Python中文
首页
教程
问答
标签
搜索
登录
注册
_pickle.UnpicklingError:NEWOBJ类参数不是类型对象
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我在cmd上运行了这段代码,我遇到了这个错误。 <code>_pickle.UnpicklingError: NEWOBJ class argument isn't a type object</code></p> <p>我的app.py如下所示:</p> <pre><code># -*- coding: utf-8 -*- """ Created on Wed Apr 21 19:18:42 2021 @author: Agni Sain """ from flask import Flask,request,render_template import pandas as pd import numpy as np import pickle app=Flask(__name__) with open('xgb.pkl','rb') as f: xgb=pickle.load(f) @app.route('/') def home(): return render_template("index.html") @app.route('/predict',methods=["POST"]) def predict_heart_disease(): age=request.form['age'] sex=request.form['sex'] cp = request.form['cp'] trestbps = request.form['trestbps'] chol = request.form['chol'] fbs = request.form['fbs'] restecg = request.form['restecg'] thalach = request.form['thalach'] exang = request.form['exang'] oldpeak = request.form['oldpeak'] slope = request.form['slope'] ca = request.form['ca'] thal = request.form['thal'] pvalues=[[age,sex,cp,trestbps,chol,fbs,restecg,thalach,exang,oldpeak,slope,ca,thal]] pvalues=np.array(pvalues).reshape((1,-1)) pred=xgb.predict(pvalues) predf=float(pred) return render_template('result.html', data=predf) @app.route('/predict_file',methods=["POST"]) def predict_heart_disease_file(): df_test=pd.read_csv(request.files.get("file")) prediction=xgb.predict(df_test) return str((list(prediction))) if (__name__=='__main__'): app.run() </code></pre> <p>我确实在这里读到了这个错误,但是没有从中找到任何这样的帮助。有人能简单地说一下为什么会出现这个错误以及如何解决它吗</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>您需要添加if语句</p> <pre><code>df_test=pd.read_csv(request.files.get("file")) if not df_test.empty: prediction=xgb.predict(df_test) return str((list(prediction))) else: return None </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
jupyter运行一个旧的pytorch版本
8 回答
Jupyter运行不同版本的卸载库?
6 回答
Jupyter运行指定的键盘快捷键
8 回答
Jupyter通过.local文件“逃逸”virtualenv。我该如何缓解这种情况?
8 回答
Jupyter重新加载自定义样式
4 回答
Jupyter错误:“没有名为Jupyter_core.paths的模块”
6 回答
jupyter错误:无法在随机林中将决策树视为png
1 回答
Jupyter错误'内核似乎已经死亡,它将自动重新启动'为一个给定的代码块
1 回答
Jupyter错误地用阿拉伯语和字母数字元素显示Python列表
8 回答
Jupyter隐藏数据帧索引,但保留原始样式
5 回答
Jupyter集线器:启动器中出现致命错误。。。系统找不到指定的文件
3 回答
Jupyther中相同值的相同哈希,但导出到Bigquery时不相同
4 回答
Jupy上Python的读/写访问问题
3 回答
jupy上没有模块cv
6 回答
Jupy上的排序错误
5 回答
Jupy中bqplot图形的紧凑布局
8 回答
Jupy中matplotlib plot的连续更新
8 回答
Jupy中Numpy函数的文档
2 回答
Jupy中Pandas的自动完成问题
9 回答
jupy中Qt后端的Matplotlib动画
4 回答