def displaygraph(predictionsdf, uploadedfile): def getbase64(binfile): with…
- User
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
def display_graph(predictions_df, uploaded_file):
def get_base64(bin_file):
with open(bin_file, "rb") as f:
data = f.read()
return base64.b64encode(data).decode()
def set_background(png_file):
bin_str = get_base64(png_file)
page_bg_img = (
"""
<style>
.stApp {
background-image: url("data:image/png;base64,%s");
background-size: cover;
}
</style>
"""
% bin_str
)
st.markdown(page_bg_img, unsafe_allow_html=True)
set_background("Screenshot (32).png")
st.markdown('<div style="margin-top: 50px;"></div>', unsafe_allow_html=True)# ... (previous code)
st.subheader("Early warning Signal:")
df_status_1 = predictions_df[predictions_df["Predicted_Status"] == 1].head(10)
df_status_0 = predictions_df[predictions_df["Predicted_Status"] == 0].head(10)
# Combine the DataFrames
df_combined = pd.concat([df_status_0, df_status_1])
start_timestamp = datetime.datetime(2023, 1, 1)
df_combined["Synthetic_Timestamp"] = pd.date_range(
start=start_timestamp, periods=len(df_combined), freq="T"
)
# df_combined['Synthetic_Timestamp'] = pd.date_range(start='2023-01-01', periods=len(df_combined), freq='T')
instance_to_explain = predictions_df.drop(['Predicted_Status'],axis=1)
Rules=""
for i in predictions_df.iterrows:
# Exclude prediction-related columns
explainer = LimeTabularExplainer(predictions_df.iloc[:, :-1].values, feature_names=predictions_df.columns[:-1].tolist(),
class_names=['likely_to_fail', 'Normal'], verbose=True, mode='classification',
discretize_continuous=True)
exp = explainer.explain_instance(instance_to_explain, model.predict_proba)
#st.write("### Decision Rule for Instance", instance_number)
Rules=exp.as_list()
predictions_df['Rules']=Rules
fig = px.scatter(
df_combined,
x="Synthetic_Timestamp",
y="Predicted_Status",
color_discrete_map={1: "red", 0: "green"},
symbol_map={1: "circle", 0: "circle"},
hue=Predicted_Status,hover_name="Predicted_Status",hover_data=["Rules"])
fig.update_layout(xaxis_tickangle=-45)
# Get the index of the clicked point
point_index = st.plotly_chart(fig, use_container_width=True, config={"displayModeBar": True}) this is my piece of my code TypeError: 'method' object is not iterable
Traceback: File "/usr/local/lib/python3.10/dist-packages/streamlit/runtime/scriptrunner/script_runner.py", line 534, in _run_script exec(code, module.dict) File "/content/app.py", line 252, in display_graph( File "/content/app.py", line 112, in display_graph for i in predictions_df.iterrows: getting error an i'm calling the function display_graph( st.session_state.predictions_df, st.session_state.uploaded_file ) like this
The issue is that you are trying to iterate over the predictions_df.iterrows method itself, rather than calling it to get the iterator.
Here is the fixed code:
Rules=""
for i, row in predictions_df.iterrows():
# Exclude prediction-related columns
explainer = LimeTabularExplainer(predictions_df.iloc[:, :-1].values, feature_names=predictions_df.columns[:-1].tolist(),
class_names=['likely_to_fail', 'Normal'], verbose=True, mode='classification',
discretize_continuous=True)
exp = explainer.explain_instance(instance_to_explain, model.predict_proba)
#st.write("### Decision Rule for Instance", instance_number)
Rules=exp.as_list()
predictions_df['Rules']=Rules
The key change is iterating over predictions_df.iterrows() rather than just predictions_df.iterrows. This actually calls the method to get the iterator of rows.
Then on each iteration, i will be the index and row will be the actual row data. You can use these as needed in your loop body.
Let me know if this helps explain the issue!
Not yet included in a published release.