SVM joblib对象返回错误的结果

时间:2016-04-20 11:00:22

标签: python scikit-learn

我已经训练了一个SVM分类器,可以预测情绪分数在1到5之间。

以下代码     https://github.com/DMKM1517/SmartCity/blob/master/DataScienceNotebooks/ScoreData.ipynb

我使用joblib来保存SVM模型。

以下代码使用joblib模型

def predict(inputFeatures):
 clf = joblib.load('/Users/krishna/MOOC/smart-city/SmartCity/DataScienceNotebooks/ModelObjects/svm.pkl') 
 vectorizer = joblib.load('/Users/krishna/MOOC/smart-city/SmartCity/DataScienceNotebooks/ModelObjects/tfidf.pkl') 

 textProcess = processTweet(inputFeatures)
 textVector = vectorizer.transform(textProcess)
 predict = clf.predict(textVector)

return predict


def processTweet(tweet):
 tweet = tweet.lower()
 tweet = re.sub('((www\.[^\s]+)|(https?://[^\s]+))','URL',tweet)
 tweet = re.sub('@[^\s]+',' ',tweet)
 tweet = re.sub('[\s]+', ' ', tweet)
 tweet = re.sub(r'#([^\s]+)', r'\1', tweet)
 tweet = tweet.strip('\'"')
return tweet

该函数在python shell中被称为下面的

import makeprediction as mp
mp.predict("I hated this movie")
array([ 3.,  3.,  3.,  3.,  3.,  3.,  3.,  3.,  3.,  3.,  3.,  3.,  3.,
    3.,  3.,  3.,  3.,  3.,  3.,  3.,  3.,  3.,  3.])

我希望数字在1到5之间,而不是分数数组。 我怎么解决这个问题?谢谢你的帮助。

0 个答案:

没有答案