-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsights.py
More file actions
28 lines (22 loc) · 1.18 KB
/
insights.py
File metadata and controls
28 lines (22 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def generate_insights(df):
"""Generate basic statistical insights from dataframe"""
insights = {
"total_activity": int(df["total_activity"].sum())
}
if "state" in df.columns:
insights["top_state"] = df.groupby("state")["total_activity"].sum().idxmax()
insights["state_count"] = df["state"].nunique()
return insights
def generate_prediction_insights(predictions_df):
"""Generate insights specifically from prediction results"""
insights = {}
if 'predicted_activity' in predictions_df.columns:
insights['total_predicted'] = float(predictions_df['predicted_activity'].sum())
insights['mean_predicted'] = float(predictions_df['predicted_activity'].mean())
insights['max_predicted'] = float(predictions_df['predicted_activity'].max())
insights['min_predicted'] = float(predictions_df['predicted_activity'].min())
if 'state' in predictions_df.columns:
state_pred = predictions_df.groupby('state')['predicted_activity'].sum()
insights['top_predicted_state'] = state_pred.idxmax()
insights['top_predicted_value'] = float(state_pred.max())
return insights