返回目錄
A
Data Science for Strategic Decision-Making: A Practical Guide - 第 4 章
Chapter 4: Statistical Inference & Predictive Modeling
發布於 2026-03-03 18:54
# Chapter 4: Statistical Inference & Predictive Modeling
Statistical inference transforms raw observations into knowledge, while predictive modeling turns that knowledge into actionable foresight. In this chapter we blend rigorous theory with hands‑on examples that illustrate how these techniques underpin strategic decisions in modern enterprises.
---
## 4.1 From Questions to Quantitative Insight
| **Step** | **Description** | **Typical Business Question** |
|----------|-----------------|-------------------------------|
| 1️⃣ Define the problem | Clarify objectives, outcomes, and constraints | *“Does a new marketing channel increase average order value?”* |
| 2️⃣ Select the data | Identify relevant variables, time horizons, and sub‑populations | *Regional sales records filtered by `region`* |
| 3️⃣ Choose the method | Decide between hypothesis testing, regression, or classification | *Linear regression for sales forecasting, logistic regression for churn* |
| 4️⃣ Validate the model | Use cross‑validation, hold‑out data, or bootstrapping | *10‑fold CV for a sales model* |
| 5️⃣ Communicate results | Translate statistics into strategic recommendations | *“Allocate 15% more budget to Channel B based on a 2% uplift.”* |
---
## 4.2 Hypothesis Testing in Business
### 4.2.1 Conceptual Foundations
- **Null hypothesis (H₀)**: No effect or difference.
- **Alternative hypothesis (H₁)**: An effect or difference exists.
- **p‑value**: Probability of observing data at least as extreme as current data under H₀.
- **Significance level (α)**: Threshold for rejecting H₀ (commonly 0.05).
### 4.2.2 Practical Example – A/B Test on Landing Page
```python
import pandas as pd
import scipy.stats as stats
# Simulated conversion data
df = pd.DataFrame({
'variant': ['A']*500 + ['B']*500,
'converted': [1]*250 + [0]*250 + [1]*275 + [0]*225
})
# Build contingency table
contingency = pd.crosstab(df['variant'], df['converted'])
print(contingency)
# Chi‑square test of independence
chi2, p, dof, ex = stats.chi2_contingency(contingency)
print(f"p‑value: {p:.4f}")
```
- **Result interpretation**: If `p < α`, we reject H₀ and conclude the new landing page has a statistically significant effect on conversions.
### 4.2.3 Common Pitfalls
| Issue | Mitigation |
|-------|------------|
| Multiple comparisons | Apply Bonferroni or False Discovery Rate corrections |
| Small sample size | Use exact tests (Fisher’s) or increase N |
| Ignoring business relevance | Combine p‑values with effect size (e.g., Cohen’s d) |
---
## 4.3 Confidence Intervals & Estimation
- **Point estimate**: Best single estimate of a parameter (e.g., mean, regression coefficient).
- **Confidence interval (CI)**: Range within which the true parameter lies with a specified probability (e.g., 95%).
```python
import numpy as np
from scipy import stats
# Estimate average sales lift
sales_lift = np.array([200, 180, 210, 195, 205])
mean_lift = sales_lift.mean()
se = stats.sem(sales_lift)
ci = stats.t.interval(0.95, len(sales_lift)-1, loc=mean_lift, scale=se)
print(f"Mean lift: {mean_lift:.2f} USD, 95% CI: {ci}")
```
- **Why CIs matter**: They convey precision and uncertainty, informing risk‑adjusted decisions.
---
## 4.4 Regression Analysis
Regression models link a response variable to one or more predictors. The most common forms in business are:
- **Linear regression** (continuous outcome)
- **Logistic regression** (binary outcome)
- **Poisson/Negative‑Binomial** (count data)
### 4.4.1 Linear Regression Workflow
```python
import statsmodels.api as sm
# Assume df contains 'sales', 'price', 'promotion', 'region'
X = df[['price', 'promotion', 'region']]
X = sm.add_constant(X) # Adds intercept term
y = df['sales']
model = sm.OLS(y, X).fit()
print(model.summary())
```
**Key diagnostics**
| Diagnostic | What to check | Action |
|------------|--------------|--------|
| Residual plots | Linearity, homoscedasticity | Transform variables or add interactions |
| VIF | Multicollinearity | Remove or combine correlated predictors |
| QQ‑plot | Normality of residuals | Apply Box‑Cox or robust regression |
### 4.4.2 Logistic Regression for Churn Prediction
```python
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import roc_auc_score
X = df[['tenure', 'avg_monthly_usage', 'support_calls']]
y = df['churn']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=42)
logreg = LogisticRegression(max_iter=200)
logreg.fit(X_train, y_train)
prob = logreg.predict_proba(X_test)[:, 1]
print(f"AUC: {roc_auc_score(y_test, prob):.4f}")
```
- **Interpretation**: Coefficients are log‑odds; exponentiated to odds ratios.
---
## 4.5 Model Diagnostics & Validation
| Technique | Purpose | Typical Use Case |
|-----------|---------|-----------------|
| Cross‑validation | Assess generalisation | Time‑series CV for sales forecasts |
| Bootstrapping | Estimate variability | Confidence bands for predicted sales |
| Residual analysis | Detect model misspecification | Checking for heteroskedasticity |
| Sensitivity analysis | Evaluate robustness | Scenario planning in pricing strategy |
**Practical tip**: Store each model version with a unique identifier in a model registry; log inputs, outputs, and performance metrics for reproducibility.
---
## 4.6 Beyond Linear Models: Decision Trees & Ensemble Methods
While classical inference provides interpretability, tree‑based ensembles capture non‑linearities and interactions naturally.
```python
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_squared_error
rf = RandomForestRegressor(n_estimators=500, random_state=42)
rf.fit(X_train, y_train)
pred = rf.predict(X_test)
print(f"RMSE: {mean_squared_error(y_test, pred, squared=False):.2f}")
```
- **Feature importance**: Offers a pseudo‑interpretation, but beware of bias toward high‑cardinality features.
- **Partial dependence plots**: Visualise marginal effects of predictors.
---
## 4.7 Evaluation Metrics – From Accuracy to Business Value
| Metric | When to Use | What It Tells You |
|--------|-------------|------------------|
| R² / Adjusted R² | Regression | Proportion of variance explained |
| RMSE / MAE | Regression | Scale‑dependent error magnitude |
| AUC‑ROC | Binary classification | Trade‑off between true & false positives |
| F1‑Score | Imbalanced classes | Harmonic mean of precision & recall |
| Cost‑Loss Curve | Decision‑threshold tuning | Direct mapping to monetary loss |
**Example**: For a sales uplift study, compute the incremental revenue per dollar spent and compare against a cost‑benefit threshold.
---
## 4.8 Business Use Cases – Turning Numbers into Strategy
| Domain | Problem | Statistical Tool | Decision Impact |
|--------|---------|------------------|----------------|
| Retail | Forecasting seasonal demand | Time‑series ARIMA + exogenous regressors | Optimize inventory, reduce stockouts |
| Marketing | Measuring campaign effectiveness | Interrupted time‑series + difference‑in‑differences | Allocate budget to high‑ROI channels |
| Finance | Credit risk scoring | Logistic regression, ROC analysis | Set interest rates, limit exposure |
| Operations | Predictive maintenance | Survival analysis | Schedule downtime, extend asset life |
Each case begins with a hypothesis, followed by data‑driven validation, and culminates in a recommendation that aligns with organizational KPIs.
---
## 4.9 Practical Workflow – From Notebook to Production
1. **Data exploration** – Use `pandas`, `seaborn`, and `plotly` to understand distributions.
2. **Statistical modeling** – `statsmodels` for inference, `scikit‑learn` for predictive pipelines.
3. **Validation** – `sklearn.model_selection` for CV, `mlflow` for tracking.
4. **Deployment** – Wrap the model in a FastAPI or Flask service; containerise with Docker.
5. **Monitoring** – Track metrics (e.g., mean absolute error) in real time; set alerts.
6. **Feedback loop** – Retrain on new data quarterly; document drift detection.
---
## 4.10 Summary
- **Statistical inference** gives us confidence about relationships and the significance of effects.
- **Predictive modeling** translates those relationships into forecasts and decision‑support tools.
- **Diagnostics and validation** are essential to ensure robustness and avoid misleading conclusions.
- **Business context** guides the choice of methods, metrics, and ultimately the strategic decisions that follow.
In the next chapter, we’ll extend these foundations to large‑scale machine‑learning pipelines, exploring hyper‑parameter optimisation, model monitoring, and production‑ready deployment strategies.