小编N.P*_*N.P的帖子

使用保存的分类器/模型时出现“idf 向量未拟合”错误

如果我使用了错误的术语,请原谅我,但我想要的是训练一组数据(使用来自 Scikit Learn 的 GaussianNB 朴素贝叶斯),保存模型/分类器,然后在需要时加载它并预测类别。

from sklearn.externals import joblib
from sklearn.naive_bayes import GaussianNB
from sklearn.feature_extraction.text import TfidfVectorizer

self.vectorizer = TfidfVectorizer(decode_error='ignore')
self.X_train_tfidf = self.vectorizer.fit_transform(train_data)

# Fit the model to my training data
self.clf = self.gnb.fit(self.X_train_tfidf.toarray(), category)

# Save the classifier to file
joblib.dump(self.clf, 'trained/NB_Model.pkl')

# Save the vocabulary to file
joblib.dump(self.vectorizer.vocabulary_, 'trained/vectorizer_vocab.pkl')


#Next time, I read the saved classifier
self.clf = joblib.load('trained/NB_Model.pkl')

# Read the saved vocabulary
self.vocab =joblib.load('trained/vectorizer_vocab.pkl')

# Initializer the vectorizer
self.vectorizer = TfidfVectorizer(vocabulary=self.vocab, decode_error='ignore')

# Try to …
Run Code Online (Sandbox Code Playgroud)

python-2.7 scikit-learn naivebayes

2
推荐指数
1
解决办法
867
查看次数

如何在memcache中设置一个值以在特定时间到期?

我有一个谷歌应用程序引擎应用程序(使用python创建).我想为memcache添加一个值,但希望每个午夜(PST)的值到期如何执行此操作?

google-app-engine python-memcached

1
推荐指数
1
解决办法
1460
查看次数