当前位置: 首页>>代码示例>>Python>>正文


Python Counter.most_common方法代码示例

本文整理汇总了Python中collections.Counter.most_common方法的典型用法代码示例。如果您正苦于以下问题:Python Counter.most_common方法的具体用法?Python Counter.most_common怎么用?Python Counter.most_common使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在collections.Counter的用法示例。


在下文中一共展示了Counter.most_common方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: wanabeknn

# 需要导入模块: from collections import Counter [as 别名]
# 或者: from collections.Counter import most_common [as 别名]
def wanabeknn(k=15):
	from collections import Counter
	ftrd = open("minidata/trainingData.csv")
	fted = open("minidata/testData.csv")
	flab = open("minidata/trainingLabels.csv")

	lab = [[int(j) for j in i.strip().split(",")]  for i in flab.readlines()]
	trd = [[int(j) for j in i.strip().split("\t")] for i in ftrd.readlines()]
	ted = [[int(j) for j in i.strip().split("\t")] for i in fted.readlines()]

	def dist(a,b): return sum([min(a[i], b[i]) for i in xrange(len(a))])

	rez = []
	for v in ted:
		print "hurej  %4d   %3d" % ( len(rez),len(rez[-1:]))
		t = []
		for trindex, train in enumerate(trd):
			t.append((dist(train, v), trindex))
		tt = sorted(t, reverse=True)
		ll = []
		for i in range(k): ll += lab[tt[i][1]]
		n = len(ll)
		for i in range(k/3): ll += lab[tt[i][1]]
		rez.append([x[0] for x in Counter.most_common(Counter(ll),n/k)])
		print rez
	cPickle.dump(rez, file("rezPickled/wnbknn%d.pickled" % k, "w"), -1)
开发者ID:eagle12td,项目名称:dataMining,代码行数:28,代码来源:main.py

示例2: addFakeData

# 需要导入模块: from collections import Counter [as 别名]
# 或者: from collections.Counter import most_common [as 别名]
def addFakeData(oData,oLabels,count=100,low=10):
	data = oData[:]
	labels = oLabels[:]
	for iafsa in range(count):
		c = Counter(chain(*labels))
		lc = Counter.most_common(c)
	
		dlc = {}
		for l in lc: dlc[l[0]] = l[1]
	
		#teze = [sum([ dlc[y]**2 for y in x])  for x in labels]
		teze = [sum([ dlc[y] for y in x])  for x in labels]
		teze = sorted([(y,x) for x,y in enumerate(teze)])
		tt = teze[:max(low*10,200)]
		shuffle(tt)
		duplicate = [x[1] for x in tt[:low]]
		dLabels = [labels[i][:] for i in duplicate]
		dData = [data[i][:] for i in duplicate]
		for ii in range(1):
			for i in range(len(duplicate)):
				labels.append(dLabels[i])
				data.append(dData[i])
	#shuflamo vrstice da niso vec lepo, pa poskrbimo da labele ostanejo 
	#pri svojem primeru
	sd = []
	[sd.append((data[i],labels[i])) for i in xrange(len(data))]
	shuffle(sd)
	ll = []
	dd = []
	for x,y in sd:
		dd.append(x)
		ll.append(y)
	return (dd, ll)
开发者ID:zidarsk8,项目名称:dataMining,代码行数:35,代码来源:data.py

示例3: _most_preferred

# 需要导入模块: from collections import Counter [as 别名]
# 或者: from collections.Counter import most_common [as 别名]
 def _most_preferred(self, alternatives):
     """Applies funcnamei from each trait to the alternatives and return the most preferred."""
     prefs = [y for y in [getattr(x, funcnamei)(alternatives) for x in self.traits] if y is not None]
     if not prefs:
         return None
     if len(prefs) == 1:
         return prefs[0]
     return Counter.most_common(Counter(prefs), 1)[0][0]
开发者ID:Mitten-O,项目名称:freeorion,代码行数:10,代码来源:character_module.py

示例4: items

# 需要导入模块: from collections import Counter [as 别名]
# 或者: from collections.Counter import most_common [as 别名]
 def items(self, relative=False):
     """ Returns a list of (key, value)-tuples sorted by value, highest-first.
         With relative=True, the sum of values is 1.0.
     """
     a = Counter.most_common(self)
     if relative:
         n = sum(v for k, v in a) or 1.
         a = [(k, v / n) for v, k in a]
     return a
开发者ID:markus-beuckelmann,项目名称:pattern,代码行数:11,代码来源:metrics.py

示例5: most_common_viz

# 需要导入模块: from collections import Counter [as 别名]
# 或者: from collections.Counter import most_common [as 别名]
def most_common_viz(output_dir: str, ints: collections.Counter) -> None:
    df = pd.DataFrame(ints.most_common(), columns=["Integer", "Frequency"])

    with open(os.path.join(output_dir, 'index.html'), 'w') as fh:
        fh.write('<html><body>\n')
        fh.write('<h3>Most common integers:</h3>\n')
        fh.write(df.to_html(index=False))
        fh.write('</body></html>')

    with open(os.path.join(output_dir, 'index.tsv'), 'w') as fh:
        fh.write(df.to_csv(sep='\t', index=False))
开发者ID:jairideout,项目名称:qiime2,代码行数:13,代码来源:visualizer.py

示例6: removeLeastCommonData

# 需要导入模块: from collections import Counter [as 别名]
# 或者: from collections.Counter import most_common [as 别名]
def removeLeastCommonData(oData, oLabels, least=5):
	data = oData[:]
	labels = oLabels[:]
	c = Counter(chain(*labels))
	lc = Counter.most_common(c)
	bb = sorted(list(Set([j for i,j in lc])))
	a = [x[0] for x in lc if x[1] < bb[5]]
	rem = [i for i,j in enumerate(labels) if len(Set(j).intersection(Set(a))) > 0 ]
	[labels.pop(x) for x in sorted(rem, reverse=True)]
	[data.pop(x) for x in sorted(rem, reverse=True)]
	return (data, labels)
开发者ID:zidarsk8,项目名称:dataMining,代码行数:13,代码来源:data.py

示例7: removeMostCommonData

# 需要导入模块: from collections import Counter [as 别名]
# 或者: from collections.Counter import most_common [as 别名]
def removeMostCommonData(oData, oLabels, count=20):
	data = oData[:]
	labels = oLabels[:]
	for iafsa in range(count):
		c = Counter(chain(*labels))
		lc = Counter.most_common(c)
		dlc = {}
		for l in lc: dlc[l[0]] = l[1]
		teze = [max([ dlc[y] for y in x])  for x in labels]
		teze = sorted([(y,x) for x,y in enumerate(teze)])
		rem = [x[1] for x in teze[-10:]]
		[labels.pop(x) for x in sorted(rem, reverse=True)]
		[data.pop(x) for x in sorted(rem, reverse=True)]
	return (data, labels)
开发者ID:zidarsk8,项目名称:dataMining,代码行数:16,代码来源:data.py

示例8: Counter

# 需要导入模块: from collections import Counter [as 别名]
# 或者: from collections.Counter import most_common [as 别名]
# print Counter(foundEmosAndSmilies)
# print("found smilies top50")
# print Counter.most_common(Counter(foundEmosAndSmilies), 50)
# print("total number of sentences with smilies:")
# print numOfTotalSentences

"""
Classify
"""
for message in messages:
    messagecounter += 1
    # for every sentence
    score, words = emoCount.score(message)

    foundEmosAndSmilies = foundEmosAndSmilies + words
    if len(words) != 0:
        numOfTotalSentences += 1
        print(words)


# in the end
print("Messages total:")
print messagecounter
print("found smilies total:")
print sum(Counter(foundEmosAndSmilies).values())
print("found smilies examples ordered:")
print Counter(foundEmosAndSmilies)
print("found smilies top50")
print Counter.most_common(Counter(foundEmosAndSmilies), 50)
print("total number of sentences with smilies:")
print numOfTotalSentences
开发者ID:lolgans,项目名称:twitchSentiment,代码行数:33,代码来源:EmoCount.py

示例9: most_common

# 需要导入模块: from collections import Counter [as 别名]
# 或者: from collections.Counter import most_common [as 别名]
 def most_common(self, n, conts):
     """Returns most frequent word"""
     return Counter.most_common(conts)
开发者ID:lesley2958,项目名称:teachers_contracts,代码行数:5,代码来源:NGrammer.py

示例10: Counter

# 需要导入模块: from collections import Counter [as 别名]
# 或者: from collections.Counter import most_common [as 别名]
from collections import Counter

text = "In February 2014, I made a recommendation to my co - founders at" \
    "Ballistiq that I wanted to cancel development of ArtStation." \
    "The project was in development hell. It wasn’t going anywhere." \
    "I was unhappy with it and just couldn’t see a path for it to be a"\
    "successful product. Two months later we managed to launch it," \
    "and two years later it is the leading network for professional games."

words = text.split()

Counter = Counter(words)

top_three = Counter.most_common(3)

print(top_three)
开发者ID:aruntakkar,项目名称:PyCode,代码行数:18,代码来源:counter.py

示例11: open

# 需要导入模块: from collections import Counter [as 别名]
# 或者: from collections.Counter import most_common [as 别名]
from collections import Counter

hairy = open("RFand1R-2-2")
majcn = open("resultRF-0.72388.csv")
smotko = open("smotkoTopScore.csv")
zidar = open("result-0.36027.csv")
aaa = open("resultRF-0.85714.csv")

a = []
a.append([[int(j) for j in i.strip().split(" ")] for i in majcn.readlines()])
a.append([[int(j) for j in i.strip().split(" ")] for i in zidar.readlines()])
a.append([[int(j) for j in i.strip().split(" ")] for i in smotko.readlines()])
a.append([[int(j) for j in i.strip().split(" ")] for i in hairy.readlines()])
a.append([[int(j) for j in i.strip().split(" ")] for i in aaa.readlines()])
b = []
for i in xrange(len(a[0])):
	c = Counter(a[0][i]+a[1][i]+a[2][i]+a[3][i]+a[4][i])
	b.append([x[0] for x in Counter.most_common(c) if x[1]>1])
	if len(x)==0 :
		x = [40, 44, 18, 62, 41]
		print "aa"
for i in b:
	if len(i) == 1:
		print "aaa"
print "bb"
f = file("RFand1R-2-2","w")
f.write("\n".join(   [" ".join([str(x) for x in i]) for i in b ]    ))
f.flush()
f.close()
开发者ID:Smotko,项目名称:data-mining,代码行数:31,代码来源:skp.py

示例12: open

# 需要导入模块: from collections import Counter [as 别名]
# 或者: from collections.Counter import most_common [as 别名]
from collections import Counter

files = [open("knn.txt"), open("knnm.txt"), open("RF200por.txt"), open("test.txt")]

a = []
for f in files:
	a.append([[int(j) for j in i.strip().split(" ")] for i in f.readlines()])

b = []
for i in xrange(len(a[0])):
	c = Counter(a[0][i]+a[1][i]+a[2][i])
	x = [x[0] for x in Counter.most_common(c) if x[1]>2]
	if len(x)==0 :
		x = [40]
	b.append(x)

print "done"
f = file("skupniNoTest.csv","w")
f.write("\n".join(   [" ".join([str(x) for x in i]) for i in b ]    ))
f.close()
开发者ID:eagle12td,项目名称:dataMining,代码行数:22,代码来源:skp.py


注:本文中的collections.Counter.most_common方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。