本文整理汇总了Python中statistics.mode函数的典型用法代码示例。如果您正苦于以下问题:Python mode函数的具体用法?Python mode怎么用?Python mode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mode函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: resetPass
def resetPass(customCommand,test=False):
from random import sample as randomize
from random import random
from os.path import exists
# Opens the Adj, Adv, and Noun files as arrays
av = open(sys.path[0]+"/Adv").read().splitlines()
aj = open(sys.path[0]+"/Adj").read().splitlines()
nn = open(sys.path[0]+"/Noun").read().splitlines()
# Just for fun, some statistics!
totalCombos = len(av)*len(aj)*len(nn)
combosFormatted = "{:,}".format(totalCombos)
avLengths=[]
for item in av:
avLengths.append(len(item))
ajLengths=[]
for item in aj:
ajLengths.append(len(item))
nnLengths=[]
for item in nn:
nnLengths.append(len(item))
from statistics import mean,median,mode
print("-"*25+"\n"+
"Total adverbs: "+str(len(av))+"\n"+
"Total adjectives: "+str(len(aj))+"\n"+
"Total nouns: "+str(len(nn))+"\n"+
"Total possible combinations: "+combosFormatted+" (not factoring in numbers)\n"+
"Shortest possible passphrase length: "+str(min(avLengths)+min(ajLengths)+min(nnLengths))+"\n"+
"Longest possible passphrase length: "+str(max(avLengths)+max(ajLengths)+max(nnLengths)+5)+"\n"+
"Mean passphrase length: "+str(int(mean(avLengths)+mean(ajLengths)+mean(nnLengths)+4))+"\n"+
"Median passphrase length: "+str(int(median(avLengths)+median(ajLengths)+median(nnLengths))+4)+"\n"+
"Mode passphrase length: "+str(int(mode(avLengths)+mode(ajLengths)+mode(nnLengths))+4)+"\n"+
"-"*25)
# Randomize the order of the arrays
av = randomize(av,len(av))
aj = randomize(aj,len(aj))
nn = randomize(nn,len(nn))
# Pick a random word from each randomized array
newAdverb = av[int(random()*len(av))].capitalize()
newAdjective = aj[int(random()*len(aj))].capitalize()
newNoun = nn[int(random()*len(nn))].capitalize()
# Possibly add a random number from 1 to 10,000
if maybeNumber():
from math import ceil
number = str(ceil(random()*10000))
else:
number = ''
# Assemble the passphrase
newPassphrase = number+newAdverb+newAdjective+newNoun
#################################################################### Needs attention
print("The new passphrase will be: "+newPassphrase)
print("Total entropy: ~"+str(int(entropy(newPassphrase))))
if customCommand == ' {PASSPHRASE}':
print("Password display command not found. Aborting.")
exit()
if not test:
import RouterPasswording
RouterPasswording.newPassphrase(newPassphrase)
from os import system as execute
execute(customCommand.replace("{password}",newPassphrase).replace("{passphrase}",newPassphrase))
开发者ID:WolfgangAxel,项目名称:Random-Projects,代码行数:59,代码来源:WifiRPG.py
示例2: find_hit_regions
def find_hit_regions(primer, alignment): #this one is for all the sequences in the alignment
'''this is currently super inefficient... It basically does the work of primer_coverage() for every single possible
frame in a sliding window for every sequence... If I'm ok with this I should just have this function return the
number of mismatches for the positions which best match... If I do that then I could have the amplicon length be
something that was returned as well.....hmmm very tempting... I think I should do this. what else besides amplicon
length would this allow me to do? I could also have it output potential mispriming sites, and then the amplicon
length for the misprimed sites.... I could include a condition where it would print a warning if mispriming
is likely, output a spreadsheet that tells you what sequences are likely to misprime, how big the amplicon
for the mispriming would be... But this mispriming would only be for these particular sequences that you are
tyring to amplify, A much more liekly source of mispriming would just be other random genomic DNA. A metagenome
might be a good thing to run this, but that would really take a long time.....'''
alignment_len = len(alignment[0])
primer_length = len(primer)
number_of_frames = (alignment_len - primer_length) + 1
range_of_frames = range(0, number_of_frames)
list_of_indexes = []
first_indexes = []
last_indexes = []
frame_indexes = {}
for frame in range_of_frames:
frame_indexes[frame] = {}
frame_indexes[frame]["first"] = frame
frame_indexes[frame]["last"] = frame + primer_length
hit_regions = {}
for seq in alignment:
sequences = {}
for frame in frame_indexes:
sequence = seq[frame_indexes[frame]["first"]:frame_indexes[frame]["last"]]
#print(sequence)
sequences[frame] = sequence
number_mismatches = {}
for key in sequences:
number_mismatches[key] = 0
for count, position in enumerate(sequences[key].upper()):
#print(count, position)
if position not in ambiguous_dna_values[primer[count]]:
number_mismatches[key] += 1
indexes = frame_indexes[min(number_mismatches, key=number_mismatches.get)]
hit_regions[seq.id] = indexes
#print("number of sequences checked: {}".format(len(hit_regions)))
#print("Percent complete: {}".format(len(hit_regions)/len(alignment)))
#hit_regions = set(hit_regions)
#print(hit_regions)
starting = []
ending = []
for key in hit_regions:
#print(key)
starting.append(hit_regions[key]["first"])
ending.append(hit_regions[key]["last"])
#print(starting)
#print(ending)
starting = mode(starting)
ending = mode(ending)
return starting, ending
开发者ID:Jtrachsel,项目名称:AEM-funbuts,代码行数:58,代码来源:butcoverage.py
示例3: classify
def classify(self, text):
features = self.find_features(text)
votes = []
for c in self._classifiers:
v = c.classify(features)
votes.append(v)
choice_votes = votes.count(mode(votes))
conf = choice_votes / float(len(votes))
return (mode(votes), conf)
开发者ID:anant14014,项目名称:TwitterNERSentimentAnalysis,代码行数:9,代码来源:SentimentClassifier.py
示例4: main
def main():
print(stats.mean(range(6)))
print(stats.median(range(6)))
print(stats.median_low(range(6)))
print(stats.median_high(range(6)))
print(stats.median_grouped(range(6)))
try:
print(stats.mode(range(6)))
except Exception as e:
print(e)
print(stats.mode(list(range(6)) + [3]))
print(stats.pstdev(list(range(6)) + [3]))
print(stats.stdev(list(range(6)) + [3]))
print(stats.pvariance(list(range(6)) + [3]))
print(stats.variance(list(range(6)) + [3]))
开发者ID:L1nwatch,项目名称:Mac-Python-3.X,代码行数:15,代码来源:learn_statistics.py
示例5: classify
def classify(self,features):
votes=[]
for c in self._classifier:
v=c.classify(features)
votes.append(v)
votes.append("pos")
return mode(votes)
开发者ID:rajakamraj,项目名称:Sentiment-Analyzer,代码行数:7,代码来源:Main.py
示例6: classify
def classify(self, features):
votes = []
for c in self._classifiers:
v = c.classify(features)
votes.append(v)
print(v)
return mode(votes)
开发者ID:rajakamraj,项目名称:Sentiment-Analyzer,代码行数:7,代码来源:trainClassify.py
示例7: basic_stats
def basic_stats(total_data):
mean = statistics.mean(total_data)
median = statistics.median(total_data)
mode = statistics.mode(total_data)
standard_dev = statistics.stdev(total_data)
return [mean, median, mode, standard_dev]
开发者ID:wongstein,项目名称:thesis,代码行数:7,代码来源:statistic.py
示例8: diff1
def diff1(listy):
pie=listy
awe=[]
d=reduce(gcd,listy)
for elem in listy:
awe.append(elem/d)
listy=awe
new=[listy]
old=[pie]
for elem in listy:
new.append(diff(new[-1]))
for elem in listy:
old.append(diff(old[-1]))
new=new[0:-1]
old=old[0:-1]
loop=-1
oth=0
for elem in new:
loop=loop+1
if elem.count(elem[0])==len(elem):
me=loop
oth=1
if oth==1:
old=old[0:me]
old=list(reversed(old))
start=new[0][0]
loop=0
for elem in old:
loop=loop+elem[-1]
return(loop)
else:
return(mode(pie))
开发者ID:orcapt,项目名称:orca_python,代码行数:32,代码来源:OO+Scatter.py
示例9: classify
def classify(self, features):
votes = []
for c in self._classifiers:
v = c.classify(features)
votes.append(v)
result = mode(votes)
return result.lower()
开发者ID:0JAdams,项目名称:TwitterMovieTracker,代码行数:7,代码来源:SentimentAnalyzer.py
示例10: vote
def vote(self, training_set):
votes = []
for c in self.classifiers:
v = c.classify(training_set)
votes.append(v)
return mode(votes)
开发者ID:BHouwens,项目名称:Sentiment,代码行数:7,代码来源:election.py
示例11: mode
def mode(RGB_list, count):
''' Gets mode element of a list given'''
temp = []
for index in RGB_list:
temp.append(index[count])
return statistics.mode(temp)
开发者ID:cooperb14,项目名称:hw4,代码行数:7,代码来源:effects.py
示例12: classify
def classify(self, features):
votes = []
for c in self._classifiers: #c for classifiers
v = c.classify(features) #v for votes
votes.append(v)
#print(votes)
return mode(votes)
开发者ID:Ignis123,项目名称:Sentiment,代码行数:7,代码来源:sentiment.py
示例13: process_file
def process_file(filename):
# data = np.recfromcsv(filename, delimiter=',', filling_values=numpy.nan, case_sensitive=True, deletechars='', replace_space=' ')
with io.open(filename, "r", encoding="UTF-8") as source_file:
data_iter = csv.DictReader(source_file)
# data = [data for data in data_iter]
pricelist = []
unitlist = []
for line in data_iter:
pricelist.append(float(line["product_price"]))
unitlist.append(line["OKEI_name"])
price_med = statistics.median(pricelist)
unit_mode = statistics.mode(unitlist)
# df = pd.DataFrame(data)
med_outliers = []
mod_outliers = []
with io.open(filename, "r", encoding="UTF-8") as source_file:
data_iter = csv.DictReader(source_file)
for line in data_iter:
if line["OKEI_name"] != unit_mode:
mod_outliers.append(line)
if (float(line["product_price"]) / price_med) > 3:
med_outliers.append(line)
return price_med, unit_mode, med_outliers, mod_outliers
开发者ID:mithron,项目名称:spendhack,代码行数:26,代码来源:main.py
示例14: print_posts
def print_posts(posts, post_type, print_num):
price_list = []
for post in posts:
try:
price_list.append(float(post.price))
except ValueError:
pass
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%{}'
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'.format(post_type))
if price_list:
print('NUM of POSTS: ', len(posts))
print('MEAN: ', statistics.mean(price_list))
print('MEDIAN: ', statistics.median(price_list))
try:
print('MODE: ', statistics.mode(price_list))
print('STDEV: ', statistics.stdev(price_list))
except statistics.StatisticsError:
pass
for post in posts[:print_num]:
pprint(post.price)
pprint(post.title)
pprint(post.carrier)
pprint(post.description)
pprint('www.kijiji.ca' + post.link)
开发者ID:Arephan,项目名称:kijiji_scraper,代码行数:28,代码来源:reporter.py
示例15: validate_array
def validate_array(self, arr):
'''
given arr
if mean and stdev of *arr* is close to target_mean and target_stdev,
return true
'''
#print('there are {} elements'.format(len(arr)))
mean = statistics.mean(arr)
#median = statistics.median(arr)
stdev = statistics.stdev(arr)
mode = 0
# most time we could not get *mode* from this array, pass it
try:
mode = statistics.mode(arr)
except statistics.StatisticsError:
pass
#print('median: {:.3f}\n'.format(media))
#print('mean: {:.3f}\nstdev: {:.3f}\n'.format(mean, stdev))
if abs(self.target_mean[0] - mean) < self.target_mean[1] \
and abs(self.target_stdev[0] - stdev) < self.target_stdev[1]:
self.result_mean = mean
self.result_stdev = stdev
self.result_mode = mode
return True
return False
开发者ID:ericosur,项目名称:ericosur-snippet,代码行数:27,代码来源:validate_gaussian.py
示例16: get_3p_domain_stats
def get_3p_domain_stats(self, num_pages, tld_filter = None):
"""
determines basic stats for the number of 3p domains contacted per-page
note this is distinct domain+pubsuffix, not fqdns (e.g. 'sub.example.com'
and sub2.example.com' only count as 'example.com')
if tracker_domains have been set the stats will reflect only third-parties
which have crossed the threshold (see get_tracker_domains())
"""
# each page id corresponds to a list of domains belonging to page elements
page_id_to_domains_dict = {}
# run query to get all page id, page domain, and element domain entries
# there is no third-party filter so each page will have at least one entry for first-party domain
for row in self.sql_driver.get_page_id_3p_element_domain_pairs(tld_filter):
page_id = row[0]
element_domain = row[1]
# if the page id is not yet seen enter the current element as a fresh list
# otherwise, we add to the existing list
# in both cases, if there is a tracker_domain list we only add
# domains that are in the list
if page_id not in page_id_to_domains_dict:
if self.tracker_domains:
if element_domain in self.tracker_domains:
page_id_to_domains_dict[page_id] = [element_domain]
else:
page_id_to_domains_dict[page_id] = [element_domain]
else:
if self.tracker_domains:
if element_domain in self.tracker_domains:
page_id_to_domains_dict[page_id] = page_id_to_domains_dict[page_id] + [element_domain]
else:
page_id_to_domains_dict[page_id] = page_id_to_domains_dict[page_id] + [element_domain]
# now we determine the number of domains each page is connected to by looking at len of list of 3p domains
per_page_3p_element_counts = []
for page_id in page_id_to_domains_dict:
per_page_3p_element_counts.append(len(page_id_to_domains_dict[page_id]))
# pages that have no 3p elements are not yet in our counts
# so for all uncounted pages we add in zeros
uncounted_pages = num_pages - len(per_page_3p_element_counts)
while uncounted_pages > 0:
uncounted_pages -= 1
per_page_3p_element_counts.append(0)
# mean and median should always be ok
mean = statistics.mean(per_page_3p_element_counts)
median = statistics.median(per_page_3p_element_counts)
# but mode can throw an error, so catch here
try:
mode = statistics.mode(per_page_3p_element_counts)
except:
mode = None
return(mean, median, mode)
开发者ID:timlib,项目名称:webXray,代码行数:60,代码来源:Analyzer.py
示例17: linear
def linear(y):
x=list(range(1,len(y)+1))
xp=6
yn=diff(y)
ynn=diff(yn)
cof=np.polyfit(x,y,1)
#print(cof)
yon=np.polyval(cof,x)
newlist=0
newlist2=0
loop=-1
for elem in y:
loop=loop+1
newlist=newlist+(elem-yon[loop])**2
newlist2=newlist2+(elem-np.mean(y))**2
newlist=(1-newlist/newlist2)*100
predict=np.polyval(cof,xp)
if newlist<99:
try:
predict=mode(y)
except statistics.StatisticsError:
predict=y[-1]
yon=list(map(int,list(map(round,yon))))
#print(yn[-1])
#plt.plot(yon)
#plt.plot(y)
#print(yon,y)
return(round(float(predict)))
开发者ID:orcapt,项目名称:orca_python,代码行数:31,代码来源:Polyfit1+linear.py
示例18: print_stats
def print_stats(l): # noqa: C901
try:
print("\tMean: {}".format(mean(l)))
except StatisticsError as e:
print("\tMean: {}".format(str(e)))
try:
print("\tMedian: {}".format(median(l)))
except StatisticsError as e:
print("\tMedian: {}".format(str(e)))
try:
print("\tMode: {}".format(mode(l)))
except StatisticsError as e:
print("\tMode: {}".format(str(e)))
try:
print("\tMax: {}".format(max(l)))
except StatisticsError as e:
print("\tMax: {}".format(str(e)))
try:
print("\tMin: {}".format(min(l)))
except StatisticsError as e:
print("\tMin: {}".format(str(e)))
开发者ID:fle-internal,项目名称:content-curation,代码行数:25,代码来源:get_channel_stats.py
示例19: statistics_for_time_points
def statistics_for_time_points(time_points: list, header: str) -> str:
time_in_seconds = [t.total_seconds() for t in time_points]
mean_time = time.strftime("%H:%M", time.gmtime(st.mean(time_in_seconds)))
median_time = time.strftime("%H:%M", time.gmtime(st.median(time_in_seconds)))
std_deviation = time.strftime("%H:%M", time.gmtime(st.pstdev(time_in_seconds)))
try:
mode_time = time.strftime("%H:%M", time.gmtime(st.mode(time_in_seconds)))
except st.StatisticsError:
mode_time = "-"
min_time = time.strftime("%H:%M", time.gmtime(min(time_in_seconds)))
max_time = time.strftime("%H:%M", time.gmtime(max(time_in_seconds)))
value_width = 5
key_width = len(header) - value_width
row_format = "\n{{:<{key_width}}}{{:>{value_width}}}".format(key_width=key_width, value_width=value_width)
delimiter = "\n" + "-" * len(header)
stats_string = header
stats_string += delimiter
stats_string += row_format.format("Mean:", mean_time)
stats_string += row_format.format("Median:", median_time)
stats_string += row_format.format("Standard deviation:", std_deviation)
stats_string += row_format.format("Mode:", mode_time)
stats_string += row_format.format("Earliest:", min_time)
stats_string += row_format.format("Latest:", max_time)
stats_string += delimiter
stats_string += "\n{} values".format(len(time_in_seconds))
return stats_string
开发者ID:jonatanlindstrom,项目名称:chrono,代码行数:31,代码来源:chrono.py
示例20: run
def run(data):
f = open("analyzer.log", 'a+')
c = costs(data)
total = total_cost(data)
f.write("\n############# COST #############\n")
f.write("Total Cost : {0}\n".format(total))
f.write("Total Cost Mean: {0}\n".format(mean(c)))
f.write("Total Cost Median: {0}\n".format(median(c)))
f.write("Total Cost Mode: {0}\n".format(mode(c)))
f.write("Total Cost Variance: {0}\n".format(variance(c)))
cost_action = action(data)
f.write("Cost by Action: \n")
for k, v in cost_action.iteritems():
f.write("\t{0} -> {1} units\n".format(k, v))
f.write("Percentage Cost by Action: \n")
for k, v in cost_action.iteritems():
f.write("\t{0} -> {1} %\n".format(k, round(((v * 100.) / total), 2)))
f.write("Cost Variance by Action: \n")
for k, v in cost_action.iteritems():
c_action = costs_action(data, k)
if len(c_action) > 1:
f.write("\t{0} -> {1} units\n".format(k, round(variance(c_action), 2)))
else:
f.write("\t{0} -> {1} units\n".format(k, round(c_action[0], 2)))
key_max, max_value = max_action_value(cost_action)
f.write("More Expensive Action by value: {0} -> {1}\n".format(key_max[0], cost_action.get(key_max[0])))
key_max, max_value = max_action_percentage(cost_action, total)
f.write("More Expensive Action by percentage: {0} -> {1} %\n".format(key_max, round(max_value, 2)))
f.close()
开发者ID:I-am-Gabi,项目名称:jsontoxml,代码行数:35,代码来源:costs.py
注:本文中的statistics.mode函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论