This is a repository for my class containing data analytics and predictive modeling projects.
A comprehensive e-commerce dataset generator that creates realistic business data for analytics practice.
What it does:
- Generates 5 interconnected datasets: customers, products, transactions, marketing campaigns, and support tickets
- Creates 5,000 customers with realistic demographics and behavior patterns
- Produces 1,000 products across 8 categories with pricing and supplier information
- Simulates 50,000 transactions with seasonal patterns and customer preferences
- Includes marketing campaigns and customer support data
- Adds customer lifecycle metrics including churn indicators
- Exports all data to CSV files in the
dataset/directory
Key Features:
- Reproducible data generation (uses fixed random seeds)
- Realistic business patterns (seasonal sales, customer segments, Pareto distribution)
- Connected data relationships across all tables
- Customer churn simulation for predictive modeling practice
A comprehensive descriptive analytics notebook that analyzes the generated e-commerce data.
What it does:
- Sales Performance Analysis: Monthly/yearly revenue trends, growth rates, and order patterns
- Customer Behavior Analysis: Segment analysis, age demographics, top customers, and spending patterns
- Product Performance Analysis: Best-selling products, category performance, and revenue distribution
- Seasonal Trends Analysis: Monthly seasonality patterns and day-of-week analysis
- Customer Lifecycle Analysis: Acquisition trends, churn analysis, and purchase recency
- Revenue Concentration Analysis: Pareto principle validation (80/20 rule)
- Business Metrics Summary: Key performance indicators and recent performance metrics
Key Insights Generated:
- Overall revenue performance: $2.27M across 50K transactions
- Customer churn rate: 29.7% with retention opportunities identified
- Seasonal patterns in sales and customer behavior
- Product category performance rankings
- Customer segment behavioral differences
Output:
- Comprehensive data analysis with visualizations
- Business metrics summary
- Actionable insights for further diagnostic analysis
- Saves summary metrics to
descriptive_summary.jsonfor downstream analysis
A comprehensive Flask web application that implements all four types of analytics in an interactive dashboard.
What it includes:
- Interactive Dashboards: Web-based interface for all analytics types
- Real-time Analysis: Dynamic data processing and visualization
- Educational Content: Built-in methodology explanations
- API Endpoints: RESTful APIs for programmatic access
- Responsive Design: Mobile-friendly interface with Bootstrap 5
Access the Application:
cd W1
python run.py
# Open http://localhost:5000 in your browserBoth scripts and the web application work together to create a complete data analytics workflow from data generation through all four types of business analytics.
Understanding the methods and techniques behind each type of analytics helps you interpret results and apply similar approaches to other business problems.
- Group-by Operations: Used
groupby()to segment customers by demographics and behavior - Value Counting: Applied
value_counts()for distribution analysis (cities, segments) - Statistical Summaries: Used
describe()for mean, standard deviation, quartiles
- Time Series Grouping:
dt.to_period('M')for monthly trends - Day-of-Week Patterns:
dt.day_name()to identify weekly cycles - Hourly Analysis:
dt.hourfor daily activity patterns
Recency (R): Days since last purchase
(current_date - last_purchase).daysFrequency (F): Number of transactions
transaction_countMonetary (M): Total spending amount
total_amount.sum()Used pd.qcut() to create value tiers (Bronze, Silver, Gold, Platinum) based on spending distribution.
- Purpose: Test relationship between categorical variables and churn
- Formula: ฯยฒ = ฮฃ[(Observed - Expected)ยฒ / Expected]
- Usage: Customer segment vs churn rate
- Code:
chi2_contingency(contingency_table)
- Purpose: Compare means between two groups
- Formula: t = (meanโ - meanโ) / SE
- Usage: Spending: Churned vs Retained customers
- Code:
stats.ttest_ind(group1, group2)
Pearson Correlation: Measures linear relationship between variables (-1 to +1)
- r > 0.7: Strong positive correlation
- 0.3 < r < 0.7: Moderate correlation
- r < 0.3: Weak correlation
dataframe.corr()- Cohort Analysis: Track customer behavior over time by segments
- Price Elasticity:
correlation(price, quantity) - Pareto Analysis: Identify top 20% customers generating 80% revenue
- Purpose: Predict customer churn probability
- How it works: Combines multiple decision trees
- Input Features: Age, spending, frequency, support tickets
- Output: Probability (0-1) of churning
- Code:
RandomForestClassifier(n_estimators=100)
- Purpose: Predict Customer Lifetime Value (CLV)
- How it works: Ensemble of regression trees
- Target: Future customer spending
- Evaluation: Rยฒ score, RMSE
- Code:
RandomForestRegressor(n_estimators=100)
- Aggregation Features: Sum, mean, std of transactions per customer
- Temporal Features: Days active, days since last purchase
- Behavioral Features: Purchase frequency, discount sensitivity
- Support Features: Ticket count, resolution time
- Encoding: Convert categorical to numerical using LabelEncoder
Sales Forecast Formula:
forecast[t+1] = current_value ร (1 + growth_rate)^t- Growth Rate: (Recent 7-day avg - Previous 7-day avg) / Previous avg
- Trend Analysis: Linear regression on historical data
- Classification Accuracy: (Correct Predictions) / (Total Predictions)
- Rยฒ Score: 1 - (SS_res / SS_tot) [Regression quality]
- RMSE: โ(ฮฃ(predicted - actual)ยฒ / n) [Prediction error]
- Method: Risk-based prioritization
- Rule: Churn probability > 70% โ Immediate intervention
- ROI Focus: High-value customers first
- Method: CLV-based segmentation
- Rule: CLV > 75th percentile โ VIP treatment
- Efficiency: Maximize ROI per dollar spent
- Method: Demand forecasting
- Rule: Stock level = Predicted demand ร Safety factor
- Goal: Minimize stockouts and overstock
| Customer Risk Level | Customer Value | Recommended Action | Method |
|---|---|---|---|
| High Risk (>70%) | High Value (Top 25%) | Personal call + Special offer | Manual intervention |
| High Risk (>70%) | Medium Value | Email campaign + Discount | Automated campaign |
| Medium Risk (30-70%) | High Value | Loyalty program invitation | Engagement strategy |
| Low Risk (<30%) | High Value | Upselling opportunities | Growth strategy |
Formula: ROI = (Benefit - Cost) / Cost ร 100%
- Retention Benefit: Customer CLV ร Retention probability improvement
- Campaign Cost: Per-customer campaign cost
- Break-even: Cost < (CLV ร Probability improvement)
- Descriptive Statistics: Mean, median, std, quartiles
- Inferential Statistics: Hypothesis testing
- Correlation Analysis: Pearson correlation
- Distribution Analysis: Histograms, quantiles
- Missing Values:
fillna()with business logic - Date Parsing:
pd.to_datetime() - Feature Engineering: Create new meaningful variables
- Encoding: Convert categories to numbers
- Supervised Learning: Classification & regression
- Ensemble Methods: Random Forest algorithms
- Model Validation: Train-test split
- Feature Importance: Identify key predictors
- KPI Calculation: Churn rate, CLV, AOV
- Segmentation: Value, behavior, risk-based
- Cohort Analysis: Track groups over time
- Portfolio Optimization: Risk-return balance
- Start with Questions: Always begin with business questions before choosing methods
- Data Quality First: Clean, validate, and understand your data
- Choose Appropriate Methods: Match statistical/ML methods to your data and goals
- Validate Results: Use proper evaluation metrics and cross-validation
- Interpret Business Impact: Translate technical results into actionable insights
- Iterate and Improve: Analytics is an ongoing process, not a one-time activity
W1/
โโโ app.py # Flask web application
โโโ run.py # Application startup script
โโโ requirements.txt # Python dependencies
โโโ analytics/ # Analytics modules
โ โโโ descriptive_analytics.py # Descriptive analysis methods
โ โโโ diagnostic_analytics.py # Diagnostic analysis methods
โ โโโ predictive_analytics.py # Predictive analysis methods
โ โโโ prescriptive_analytics.py # Prescriptive analysis methods
โโโ templates/ # HTML templates
โ โโโ base.html # Base template
โ โโโ index.html # Dashboard homepage
โ โโโ descriptive.html # Descriptive analytics page
โ โโโ diagnostic.html # Diagnostic analytics page
โ โโโ predictive.html # Predictive analytics page
โ โโโ prescriptive.html # Prescriptive analytics page
โ โโโ methodology.html # Methodology explanation page
โโโ static/ # Static assets
โ โโโ css/style.css # Custom styling
โ โโโ js/app.js # JavaScript functionality
โโโ dataset/ # Generated datasets
โโโ customers.csv # Customer data
โโโ products.csv # Product catalog
โโโ transactions.csv # Transaction records
โโโ support_tickets.csv # Customer support data
โโโ marketing_campaigns.csv # Marketing campaign data
This comprehensive methodology serves as both a learning resource and a reference guide for understanding how modern business analytics translates data into actionable insights.