0

''' features = [gender, SeniorCitizen, Partner, Dependents, Tenure, PhoneService, MultipleLines, OnlineSecurity, OnlineBackup, DeviceProtection, TechSupport, StreamingTV, StreamingMovies, PaperlessBilling, MonthlyCharges, TotalCharges, InternetService_Fiberoptic, InternetService_No, Contract_Oneyear,Contract_Twoyear, PaymentMethod_CreditCard, PaymentMethod_ElectronicCheck, PaymentMethod_MailedCheck] final_features = [np.array(features)]

prediction = model.predict_proba(final_features)

output = prediction[0,1]

# Shap Values
explainer = joblib.load(filename="explainer.bz2")
shap_values = explainer.shap_values(np.array(final_features))
shap_img = io.BytesIO()
shap.force_plot(explainer.expected_value[1], shap_values[1], columns, matplotlib = True, show = False).savefig(shap_img, bbox_inches="tight", format = 'png')
shap_img.seek(0)
shap_url = base64.b64encode(shap_img.getvalue()).decode()

当我们尝试运行 python 文件时,错误是关于树集合的。错误说:'TreeEnsemble' 对象没有属性'model_output'。请帮助纠正此错误,回溯是:文件“C:\Users\utrej\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py”,第 1836 行,调用中 返回 self.wsgi_app(environ, start_response) 文件“C:\Users\utrej\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py”,第 1820 行,在 wsgi_app response = self. make_response(self.handle_exception(e)) 文件“C:\Users\utrej\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py”,第 1403 行,在 handle_exception reraise(exc_type, exc_value, tb) 文件“C:\Users\utrej\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask_compat.py”,第 33 行,在 reraise raise value 文件“C:\Users\utrej\ AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py”,第 1817 行,在 wsgi_app 响应 = self.full_dispatch_request() 文件“C:\Users\utrej\AppData\Local\Programs\ Python\Python38\Lib\site-packages\flask\app.py",第 1477 行,在 full_dispatch_request rv = self.handle_user_exception(e) 文件“C:\Users\utrej\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\app.py”,第 1381 行,在 handle_user_exception reraise(exc_type, exc_value, tb) 文件中“C:\Users\utrej\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask_compat.py”,第 33 行,在 reraise raise 值文件“C:\Users\utrej\AppData\Local\Programs \Python\Python38\Lib\site-packages\flask\app.py”,第 1475 行,在 full_dispatch_request rv = self.dispatch_request() 文件“C:\Users\utrej\AppData\Local\Programs\Python\Python38\Lib \site-packages\flask\app.py",第 1461 行,在 dispatch_request 中返回 self.view_functionsrule.endpoint 文件 "C:\Users\utrej\Desktop####\product dev lab\Customer-Survival-Analysis-and- Churn-Prediction-master\app.py",第 118 行,在 predict shap_values = explainer.shap_values(np.数组(final_features))文件“C:\Users\utrej\AppData\Local\Programs\Python\Python38\Lib\site-packages\shap\explainers\tree.py”,第 298 行,在 shap_values 中,如果 self.model.model_output == “log_loss”:

4

0 回答 0