gpt4 book ai didi

python - 属性错误 : 'super' object has no attribute 'get_params' while deploying

转载 作者:行者123 更新时间:2023-12-05 09:04:34 27 4
gpt4 key购买 nike

我的模型已保存,我正在尝试部署模型,但收到错误消息 AttributeError:“super”对象没有属性“get_params”。我无法在我的代码中找到任何错误。任何人都可以帮助解决这个问题。在此先感谢您的帮助。我的完整代码如下所示。

from flask import Flask, render_template, request
from datetime import date
import numpy as np
import pandas as pd
from dateutil.relativedelta import relativedelta
import pickle
app=Flask(__name__)
model=pickle.load(open('XGBoost.pkl','rb'))
@app.route('/',methods=['GET'])

def home():
return render_template('index.html')

@app.route('/predict',methods=['POST'])
def predict():
if request.method=='POST':
loan_amt=float(request.form['loan_amt'])
term=int(request.form['term'])
issue_d=str(request.form['issue_d'])
tol_paymnt=float(request.form['tol_paymnt'])
int_recvd=float(request.form['int_recvd'])
late_recv_fee=float(request.form['total_rec_late_fee'])
rcvry=float(request.form['rcvry'])
lst_pymnt_d=str(request.form['lst_pymnt_d'])
last_pymnt_amnt=float(request.form['last_pymnt_amnt'])
last_credit_pull_d=str(request.form['last_credit_pull_d'])
nxt_pymnt_d=str(request.form['nxt_pymnt_d'])

df=pd.DataFrame([[loan_amt,term,issue_d,tol_paymnt,int_recvd,late_recv_fee,rcvry,lst_pymnt_d,last_pymnt_amnt,last_credit_pull_d,nxt_pymnt_d]],
columns=('loan_amnt','term','issue_d','total_pymnt','total_rec_int','late_recv_fee','recoveries','last_pymnt_d','last_pymnt_amnt','last_credit_pull_d','nxt_pymnt_d'))

df['issue_d']=pd.to_datetime(df['issue_d']).dt.date
df['last_pymnt_d']=pd.to_datetime(df['last_pymnt_d']).dt.date
df['last_credit_pull_d']=pd.to_datetime(df['last_credit_pull_d']).dt.date
df['nxt_pymnt_d']=pd.to_datetime(df['nxt_pymnt_d']).dt.date

df['issue_d']=round((date.today()-df['issue_d'])/np.timedelta64(1,'M'))
df['last_pymnt_d']=round((date.today()-df['last_pymnt_d'])/np.timedelta64(1,'M'))
df['last_credit_pull_d']=round((date.today()-df['last_credit_pull_d'])/np.timedelta64(1,'M'))
df['nxt_pymnt_d']=round((date.today()-df['nxt_pymnt_d'])/np.timedelta64(1,'M'))

df['lst_nxt_pymnt_diff']=df['last_pymnt_d']-df['nxt_pymnt_d']
df['issue_lst_pymnt_diff']=df['issue_d']-df['nxt_pymnt_d']

df.drop(['nxt_pymnt_d'],axis=1,inplace=True)

input=np.asarray([[df['loan_amnt'],df['term'],df['issue_d'],df['total_pymnt'],df['total_rec_int'],df['late_recv_fee'],df['recoveries'],df['last_pymnt_d'],df['last_pymnt_amnt'],
df['last_credit_pull_d'],df['lst_nxt_pymnt_diff'],df['issue_lst_pymnt_diff']]])

prediction=model.predict(input)
if prediction==0:
return render_template('index.html',prediction_texts='Borrower will repay the loan amount.')
else:
return render_template('index.html',prediction_texts='Borrower will fail to repay the loan amount.')
else:
return render_template('index.html')

if __name__=='main':
app.run(debug=True)

错误的完整回溯如下所示。

    Traceback (most recent call last):
File "C:\Users\Vikes\anaconda3\envs\loan_default\Lib\site-packages\werkzeug\serving.py", line 319, in run_wsgi xecute(self.server.app)
File "C:\Users\Vikes\anaconda3\envs\loan_default\Lib\site-packages\werkzeug\serving.py", line 308, in execute application_iter = app(environ, start_response)
File "C:\Users\Vikes\anaconda3\envs\loan_default\Lib\site-packages\flask\app.py", line 2088, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\Vikes\anaconda3\envs\loan_default\Lib\site-packages\flask\app.py", line 2073, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\Vikes\anaconda3\envs\loan_default\Lib\site-packages\flask\app.py", line 2070, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\Vikes\anaconda3\envs\loan_default\Lib\site-packages\flask\app.py", line 1515, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\Vikes\anaconda3\envs\loan_default\Lib\site-packages\flask\app.py", line 1513, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\Vikes\anaconda3\envs\loan_default\Lib\site-packages\flask\app.py", line 1499, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "D:\Study material\Datasets\Python Project - Bank Lending\app.py", line 50, in predict
prediction=model.predict(input)
File "C:\Users\Vikes\anaconda3\envs\loan_default\Lib\site-packages\xgboost\sklearn.py", line 1209, in predict
class_probs = super().predict(
File "C:\Users\Vikes\anaconda3\envs\loan_default\Lib\site-packages\xgboost\sklearn.py", line 818, in predict
if self._can_use_inplace_predict():
File "C:\Users\Vikes\anaconda3\envs\loan_default\Lib\site-packages\xgboost\sklearn.py", line 758, in _can_use_inplace_predict
params = self.get_params()
File "C:\Users\Vikes\anaconda3\envs\loan_default\Lib\site-packages\xgboost\sklearn.py", line 438, in get_params
params = super().get_params(deep)
AttributeError: 'super' object has no attribute 'get_params'

您可以找到完整的代码 https://github.com/Vikeshkr-DSP/Loan_Default_Prediction

最佳答案

尝试将 scikit-learn 添加到您的 requirements.txt

关于python - 属性错误 : 'super' object has no attribute 'get_params' while deploying,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68433215/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com