Created
June 29, 2016 11:45
-
-
Save otajisan/47a306e397c8d040d769a0c3f0f4c3f5 to your computer and use it in GitHub Desktop.
scikit-learnでシリアライズしたモデルを読み込み、テキストを分類する(corpusは自前)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from sklearn.externals import joblib | |
from sklearn.metrics import classification_report | |
import corpus | |
def predict(text): | |
dictionary = corpus.get_dictionary(create_flg=False) | |
vector = [corpus.get_vector(dictionary, text)] | |
clf = joblib.load("model/model") | |
return { | |
'label' : clf.predict(vector)[0], | |
'acc' : clf.predict_proba(vector)[:,1][0] | |
} | |
if __name__ == '__main__': | |
text = '渋谷のおしゃれバーでビールをぐいぐい' | |
result = predict(text) | |
print result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment