word_appear_time.py

coding=UTF-8

import string #处理文本时,需要去除跟在单词后的标点。所以用到string模块
import os

file_name=’20171113-075144’
print(file_name + ‘\n’)

filename=open(file_name)

filelines=filename.readlines()
filename.close()

word_cnt={}

for line in filelines:
line=line.rstrip()
identity=string.maketrans(’ ‘,’ ‘)

pun_num=string.punctuation+string.digits
line=line.translate(identity,pun_num)
line=line.lower()

word_list=line.split(' ')
for word in word_list:
    if word_cnt.has_key(word):
        word_cnt[word]+=1
    else:
        word_cnt[word]=1

result=sorted(,key=lambda d:d[1],reverse=True)

match_data = {}

for (key, value) in word_cnt.items():
if key == ‘vudu’:
match_data[key] = value

for (key, value) in word_cnt.items():
if key == ‘hulu’:
match_data[key] = value

for (key, value) in word_cnt.items():
if key == ‘xumo’:
match_data[key] = value

for (key, value) in word_cnt.items():
if key == ‘crackle’:
match_data[key] = value

for (key, value) in word_cnt.items():
if key == ‘iheart’:
match_data[key] = value

for (key, value) in word_cnt.items():
if key == ‘sophie’:
match_data[key] = value

print match_data

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个错误可能是由于您的sklearn版本过低导致的。您可以尝试更新sklearn到最新版本,或者使用下面的代码来解决该问题: ```python from sklearn.metrics import confusion_matrix from sklearn.utils.multiclass import unique_labels import matplotlib.pyplot as plt def plot_confusion_matrix(y_true, y_pred, classes, normalize=False, title=None, cmap=plt.cm.Blues): """ This function prints and plots the confusion matrix. Normalization can be applied by setting `normalize=True`. """ if not title: if normalize: title = 'Normalized confusion matrix' else: title = 'Confusion matrix, without normalization' # Compute confusion matrix cm = confusion_matrix(y_true, y_pred) # Only use the labels that appear in the data classes = classes[unique_labels(y_true, y_pred)] if normalize: cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis] fig, ax = plt.subplots() im = ax.imshow(cm, interpolation='nearest', cmap=cmap) ax.figure.colorbar(im, ax=ax) # We want to show all ticks... ax.set(xticks=np.arange(cm.shape), yticks=np.arange(cm.shape), # ... and label them with the respective list entries xticklabels=classes, yticklabels=classes, title=title, ylabel='True label', xlabel='Predicted label') # Rotate the tick labels and set their alignment. plt.setp(ax.get_xticklabels(), rotation=45, ha="right", rotation_mode="anchor") # Loop over data dimensions and create text annotations. fmt = '.2f' if normalize else 'd' thresh = cm.max() / 2. for i in range(cm.shape): for j in range(cm.shape): ax.text(j, i, format(cm[i, j], fmt), ha="center", va="center", color="white" if cm[i, j] > thresh else "black") fig.tight_layout() return ax ``` 如果您有任何其他问题,请随时问我。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值