Learning Objectives
345 words
2 min read
Visual companion
Python
Type and operator map
Python Week 1: the first filter for runtime behavior
View
Revision summary
What this note is really saying
Short form
# Learning Objectives - Apply predictive models to business data - Validate model with business metrics - Create what-if scenarios > **Q1: How to evaluate a forecasting model for business?** > > MAPE (mean absolute percentage error) - interpretable (% error). Compare to naive baseline (persist last value).

Learning Objectives
- Apply predictive models to business data
- Validate model with business metrics
- Create what-if scenarios
pythonfrom sklearn.ensemble import RandomForestRegressor from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score import pandas as pd # Load processed data df = pd.read_csv('data/processed/sales_features.csv') # Prepare features feature_cols = ['price', 'discount', 'marketing_spend', 'competitor_price', 'day_of_week', 'month', 'is_holiday', 'lag_sales_7d'] X = df[feature_cols] y = df['sales'] # Train/test split (temporal) split_idx = int(len(df) * 0.8) X_train, X_test = X.iloc[:split_idx], X.iloc[split_idx:] y_train, y_test = y.iloc[:split_idx], y.iloc[split_idx:] # Model model = RandomForestRegressor(n_estimators=200, random_state=42) model.fit(X_train, y_train) # Predict y_pred = model.predict(X_test) # Business metrics mae = mean_absolute_error(y_test, y_pred) rmse = np.sqrt(mean_squared_error(y_test, y_pred)) mape = np.mean(np.abs((y_test - y_pred) / y_test)) * 100 r2 = r2_score(y_test, y_pred) print(f"MAE: ${mae:.0f}") print(f"RMSE: ${rmse:.0f}") print(f"MAPE: {mape:.1f}%") print(f"R2: {r2:.3f}")
Q1: How to evaluate a forecasting model for business?MAPE (mean absolute percentage error) - interpretable (% error). Compare to naive baseline (persist last value). RMSE penalizes large errors more. Q2: What is lag feature engineering?Use past values as features. Sales(t-1), Sales(t-7) to predict Sales(t). Captures seasonality and autocorrelation. Common for time series forecasting. Q3: What is the difference between forecasting and prediction?Forecasting: predicting FUTURE values in time series (ordered). Prediction: general term for estimating any unknown value. Forecasting requires temporal validation. Q4: How to create what-if analysis?Modify input features (what if price +10%?), run model predictions, compare to baseline. Helps business understand impact of decisions before making them. Q5: What is the business value of a predictive model?Less than 5% MAPE: excellent for operational planning. 5-10%: good for strategic decisions. >15%: useful for direction but not precision. Context matters. Q6: Create what-if scenario:python# What if we increase price by 10%? scenario = X_test.copy() scenario['price'] = scenario['price'] * 1.10 scenario_pred = model.predict(scenario) baseline_pred = model.predict(X_test) impact = scenario_pred - baseline_pred print(f"Revenue impact: ${impact.sum():.0f}")