【问题标题】:python scikit - ValueErrorpython scikit - 值错误
【发布时间】:2015-02-09 13:39:40
【问题描述】:

我正在关注 stackoverflow here 中关于如何保存分类器的帖子。当我尝试按照第二篇文章中提到的方式进行时。但我不断得到

ValueError: Vocabulary 未拟合或为空!

我的训练代码如下:

train = load_files(learning_data_train)
count_vect = CountVectorizer(tokenizer=tokenize,stop_words='english')
X_train_counts = count_vect.fit_transform(train.data)
clf = SGDClassifier(loss='hinge', penalty='l1',alpha=1e-3, n_iter=5).fit(X_train_counts, train.target)
filename = "SGD.pk1"
joblib.dump(clf, filename)

而我的测试代码如下:

count_vect = CountVectorizer(tokenizer=tokenize,stop_words='english')
filename = "SGD.pk1"
clf = joblib.load(filename)
print clf 
file= "testfolder/"
docs_new = []
for i in os.listdir(file):
    docs_new.append(open(file+i,"r").read())
X_new_counts = count_vect.transform(docs_new)
predicted = clf.predict(X_new_counts)
for doc, category in zip(docs_new, predicted):
    print(' => %s' % ( train.target_names[category]))

执行时抛出错误

X_new_counts = count_vect.transform(docs_new)

我在这里做错了吗?

【问题讨论】:

    标签: python numpy scipy scikit-learn


    【解决方案1】:
    猜你喜欢
    • 2015-03-21
    • 1970-01-01
    • 1970-01-01
    • 2018-05-03
    • 1970-01-01
    • 2016-06-28
    • 2018-08-17
    • 2018-09-17
    • 2016-01-26
    相关资源
    最近更新 更多