Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么我在尝试将模型装入烧瓶时会遇到取消勾选错误?_Python_Machine Learning_Scikit Learn_Pickle - Fatal编程技术网

Python 为什么我在尝试将模型装入烧瓶时会遇到取消勾选错误?

Python 为什么我在尝试将模型装入烧瓶时会遇到取消勾选错误?,python,machine-learning,scikit-learn,pickle,Python,Machine Learning,Scikit Learn,Pickle,我曾在jupyter实验室尝试过酸洗和解酸洗,它似乎能正常工作,但当我运行app.py时,它会给我以下错误 C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Python 3.7\fakenews\venv\lib\site-packages\sklearn\utils\deprecation.py:144: FutureWarning: The sklearn.linear_model.passive_aggressive module

我曾在jupyter实验室尝试过酸洗和解酸洗,它似乎能正常工作,但当我运行app.py时,它会给我以下错误

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Python 3.7\fakenews\venv\lib\site-packages\sklearn\utils\deprecation.py:144: FutureWarning: The sklearn.linear_model.passive_aggressive module is  deprecated in version 0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.linear_model. Anything that cannot be imported from sklearn.linear_model is now part of the private API.
  warnings.warn(message, FutureWarning)
Traceback (most recent call last):
  File "app.py", line 9, in <module>
    model = pickle.load(open('model.pkl', 'rb'))
_pickle.UnpicklingError: invalid load key, '\x17'.
App.py



import numpy as np
from flask import Flask, request, jsonify, render_template
import pickle
import pandas as pd
app = Flask(__name__)
model = pickle.load(open('model.pkl', 'rb'))
session.clear()
@app.route('/')
def home():
    return render_template('index.html')

@app.route('/predict',methods=['POST'])
def predict():

    news = request.form["newsT"]
    test1 = pd.Series(news, index=[11000])
    prediction = model.predict(test1)
    return render_template('index.html', prediction_text='Sales should be $ {}'.format(prediction))



if __name__ == "__main__":
    app.run(debug=True)
我用这个代码来泡菜---------------

这在实验室中运行良好,但在加载app.py时似乎会出现取消勾选错误。
我对这个领域相当陌生,即使在网上进行了大量搜索,也无法找出问题所在。

这似乎是一个编码问题。这可能是因为您正在保存pickle模型并尝试加载同一模型vai
pickle
库。尝试使用
joblib

model = joblib.load('model.pkl')
我希望有帮助


# Save the model as a pickle in a file 
joblib.dump(pac, 'model.pkl') 

# Load the model from the file 
pac_from_joblib = joblib.load('model.pkl')  

# Use the loaded model to make predictions 
pac_from_joblib.predict(tfidf_test) 
model = joblib.load('model.pkl')