【发布时间】:2017-06-25 11:21:58
【问题描述】:
我目前正在尝试使用 this SO question 查找单词列表的发音
以下代码如下:
import random
def scramble(s):
return "".join(random.sample(s, len(s)))
words = [w.strip() for w in open('/usr/share/dict/words') if w == w.lower()]
scrambled = [scramble(w) for w in words]
X = words+scrambled
y = ['word']*len(words) + ['unpronounceable']*len(scrambled)
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y)
from sklearn.pipeline import Pipeline
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
text_clf = Pipeline([
('vect', CountVectorizer(analyzer='char', ngram_range=(1, 3))),
('clf', MultinomialNB())
])
text_clf = text_clf.fit(X_train, y_train)
predicted = text_clf.predict(X_test)
from sklearn import metrics
print(metrics.classification_report(y_test, predicted))
This 输出随机单词 this
>>> text_clf.predict("scaroly".split())
['word']
我一直在检查scikit documentation,但我似乎仍然不知道如何让它打印输入单词的分数。
【问题讨论】:
-
你所说的“分数”到底是什么意思?比如分类器对给定单词的发音有多大信心?
-
@not_a_robot 没错
标签: python scikit-learn classification text-classification