Hey Guys,
So i’ve been checking out the Pandas Profiling app made by @Marc, in that he uses html.escape(html_report) #where html_report -> is nothing but the dashboard output of pandas profiling library
, I am trying to output a dashboard of similar kind for Interpretability of ML model purpose, and the object file when I am giving to the html.escape(html_report)
, it says AttributeError: ErrorAnalysisDashboard has no attribute 'replace' #this is when i try to showcase the output of the dashboard
Following is the code :
pn.extension(loading_spinner='dots', loading_color='#00aa41', sizing_mode="stretch_width")
EMPTY_HTML_REPORT = "<p>Query the data and select pickle file to generate Interpretability report</p>"
HTML_CREATING_REPORT = "<p>Creating Report ...</p>"
HTML_TEXT_MISSING = "<p>Please Enter the SQL Query ...</p>"
HTML_PICKLE_FILE = "<p>Please select a Pickle File ...</p>"
def queryFunc(query : str) -> pd.DataFrame():
client = bigquery.Client(project="project_name")
bqs_client = bigquery_storage.BigQueryReadClient()
df = (client.query(query).result().to_dataframe(bqstorage_client=bqs_client))
return df
def AIDashCreation(df, pickleFile):
df = df[['dayofyear',
'book_hr',
'book_wd',
'distance_02',
'ifcs_pred','zip_0',
'dlvr_typ',
'fill_meth',
'state_2','dlvr_days']]
df['fill_meth'] = df['fill_meth'].map(fill_meth_map)
df['state_2'] = df['state_2'].map(state_mapper)
model = pickle.loads(pickleFile)
X = df.drop(columns='dlvr_days')
y = df['dlvr_days'].values
feature_names = list(X.columns)
X = X.values
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)
# Train the LightGBM surrogate model using MimicExplaner
model_task = ModelTask.Regression
explainer = MimicExplainer(model, X_train, LGBMExplainableModel,
augment_data=True, max_num_of_augmentations=10,
features=feature_names, model_task=model_task)
global_explanation = explainer.explain_global(X_test)
return global_explanation, X_test, y_test
html_report_pane = pn.pane.HTML(EMPTY_HTML_REPORT, height=900, sizing_mode="stretch_both")
sqlWidget = pn.widgets.TextInput(name='Enter the SQL Query',
value='', placeholder = 'Enter the SQL Query')
queryButtonErr = pn.widgets.Button(name="Query the results for Error Analysis Dashboard",
margin=(0, 32, 0, 57), button_type="primary")
queryButtonExp = pn.widgets.Button(name="Query the results for Explanability Dashboard",
margin=(0, 32, 0, 57), button_type="primary")
pickleFile = pn.widgets.FileInput(accept=".pkl")
layout = pn.Column(sqlWidget, pickleFile, pn.Row(queryButtonErr, queryButtonExp), html_report_pane)
def errorDashFunc(event):
if sqlWidget.value and pickleFile.value:
df = queryFunc(sqlWidget.value)
html_report_pane.object = HTML_CREATING_REPORT
start_loading_spinner(html_report_pane)
globalExp, Xtest, ytest = AIDashCreation(df, pickleFile.value)
model = pickle.loads(pickleFile.value)
dashError = ErrorAnalysisDashboard(globalExp, model, dataset=Xtest, true_y=ytest,
model_task='regression')
stop_loading_spinner(html_report_pane)
dashHTML = pn.pane.HTML((f"""<iframe srcdoc="{dashError}" frameborder="0" allowfullscreen></iframe>"""),
height=900, sizing_mode="stretch_both")
layout[3] = dashHTML
elif sqlWidget.value:
html_report_pane.object = HTML_PICKLE_FILE
elif pickleFile.value:
html_report_pane.object = HTML_TEXT_MISSING
else:
html_report_pane.object = EMPTY_HTML_REPORT
queryButtonErr.on_click(errorDashFunc)
pn.template.FastListTemplate(
site="Panel",
title="Explanability Page",
main=[
"Demo for Querying your data and getting a dashboard for your model to better understand it",
layout
]
).servable();
Can someone tell me how to showcase the dashboard properly without any error please.