'AttributeError: 'super' object has no attribute 'get_params' while deploying

My model has been saved and I'm trying to deploy the model but I'm getting the error message AttributeError: 'super' object has no attribute 'get_params'. I am not able to find any error in my code. Can anyone help to solve this problem. Thanks in advance for your help. My complete code can be seen below.

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)

Complete traceback of error can be seen below.

    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'

You can find the complete, code https://github.com/Vikeshkr-DSP/Loan_Default_Prediction



Solution 1:[1]

Try adding scikit-learn to your requirements.txt

Solution 2:[2]

I faced similar issue in my Flask application while using the xgboost predict function.

After installing the scikit-learn package the issue got resolved

pip install scikit-learn

Solution 3:[3]

I faced similar issue in my Fastapi application while using the xgboost predict function.

Try to install scikit-learn

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Paul M
Solution 2 Akhilesh
Solution 3 Karan wadhawan 25