我的用于文本数据预测的管道模型是
pipe1=Pipeline([
('tfidf',TfidfVectorizer(analyzer=split_into_lemmas,min_df=20,max_df=3000)),
('classfier',MultinomialNB())
])
API应用为
from flask import Flask, jsonify,request
from sklearn.externals import joblib
import pandas as pd
from nltk.tokenize import word_tokenize
from nltk.corpus import stopwords
stop = set(stopwords.words('english'))
from nltk.stem.wordnet import WordNetLemmatizer
lemma = WordNetLemmatizer()
def split_into_lemmas(message):
message=message.lower()
words = word_tokenize(message)
words_sans_stop=[]
for word in words :
if word in stop:continue
words_sans_stop.append(word)
return [lemma.lemmatize(word) for word in words_sans_stop]
app = Flask(__name__)
@app.route('/',methods=['POST'])
def home():
return 'Hello Jaison'
@app.route('/predict', methods=['POST'])
def predict():
json_ = request.get_json(silent=True)
message=json_.get('message')
mydf = pd.DataFrame({'message':message})
print(mydf)
prediction = clf.predict_proba(mydf['message'])
return jsonify({'prediction': prediction.tolist()})
if __name__ == '__main__':
clf = joblib.load('/Users/JaisoN/my_model_pipeline.pkl')
app.run(port=5000)
当我点击网址时
得到正确的响应,但是当我使用文本数据作为JSON命中预测的URL时,>
curl -H "Content-Type: application/json" -X POST -d '{"message":["I‘m going to try for 2 months ha ha only joking"]}' http://127.0.0.1:5000/predict
am低于错误
File "C:/Users/JaisoN/.spyder-py3/temp.py", line 30, in predict
message=json_.get('message')
AttributeError: 'NoneType' object has no attribute 'get'
我用于文本数据预测的管道模型是pipe1 = Pipeline([('tfidf',TfidfVectorizer(analyzer = split_into_lemmas,min_df = 20,max_df = 3000)),('classfier',MultinomialNB())])API app ...
卷曲请求不正确。