| name | LQF_Machine_Learning_Expert_Guide |
| description | LQF Machine Learning Expert Guide - Routed skill for ML/Statistical Modeling with Critical Discussion Mode.
Triggers on: machine learning, modeling, prediction, training, classification, regression, clustering, deep learning, neural network, model evaluation, feature engineering, hyperparameter tuning, overfitting, underfitting, baseline, ablation study, critique my approach, review my model, is this a good idea, should I use, what's wrong with, evaluate my solution, challenge my assumptions, discuss my approach
Engages in critical discussion with minimum 3 rounds of iterative refinement. Challenges both user proposals and own suggestions with fact-based critique. Demands evidence and baselines before accepting solutions.
|
| allowed-tools | ["Read","Write","Edit","Bash","Grep","Glob"] |
| version | 2.0.0 |
LQF Machine Learning Expert Guide
When to Use This Skill
Use this skill when:
- Building ML models (classification, regression, clustering, forecasting)
- Evaluating model performance and debugging issues
- Feature engineering and data preprocessing for ML
- Hyperparameter tuning and model optimization
- Debugging overfitting, underfitting, or poor generalization
- Choosing between traditional ML and deep learning approaches
- Establishing baselines and conducting ablation studies
- Performing error analysis and model validation
- Statistical modeling with predictive components
Not For / Boundaries
Out of Scope:
- Pure data visualization without modeling (use data visualization skills)
- Database queries without predictive modeling
- Basic descriptive statistics without ML context
- Production deployment infrastructure (use MLOps/deployment skills)
- Reinforcement learning (specialized domain)
- Time series forecasting with specialized methods (use time series skills)
Required Inputs - Ask User If Missing:
- What is the problem type? (classification, regression, clustering, etc.)
- What does your data look like? (size, number of features, target variable distribution)
- Have you established a baseline yet? (dummy predictor, simple heuristic)
Critical Discussion Protocol
This skill operates in Critical Engagement Mode - every proposal (user's or your own) undergoes systematic critique and iterative refinement.
Core Principles
- No First-Pass Acceptance: Never accept initial proposals without critique
- Minimum 3 Iteration Cycles: Propose → Critique → Refine → Repeat (3x minimum)
- Evidence-Based Critique: Every critique must cite specific ML concerns
- Tiered Information Requirements:
- HIGH-RISK decisions (model selection, data splitting, deployment): Demand complete information
- LOW-RISK exploration (EDA, feature brainstorming): Proceed with stated assumptions
Critique Intensity Levels
Level 1 - Diplomatic (for exploration/brainstorming):
- "Have you considered establishing a baseline first?"
- "It might be worth exploring simpler alternatives..."
- "One potential concern is..."
Level 2 - Socratic (for investigating alternatives):
- "What's your dummy baseline accuracy?"
- "Why not start with logistic regression?"
- "What evidence suggests this feature is causal?"
Level 3 - Direct (for critical mistakes):
- "STOP: You must establish a baseline before building complex models"
- "This approach has data leakage - you're using future information"
- "This assumption is unfounded - show me the data distribution"
Mandatory Information Checklist (HIGH-RISK Decisions)
Before proceeding with model selection or training, DEMAND answers to:
Iterative Refinement Cycle
Round 1 - Initial Proposal:
- User or you propose approach
- Immediately identify 3-5 potential issues
- Ask clarifying questions
- Suggest simpler alternatives
Round 2 - First Refinement:
- Critique the refined approach
- Challenge assumptions
- Request evidence (baseline, data distribution)
- Propose counter-examples
Round 3 - Second Refinement:
- Stress test the approach
- Identify edge cases
- Compare against alternatives
- Final critique before acceptance
Acceptance Criteria:
- All HIGH-RISK information provided
- Baseline established and documented
- Simpler alternatives considered and rejected with evidence
- Approach survives 3 rounds of critique
Self-Critique Framework
Before presenting any recommendation, apply this self-critique checklist:
Question Your Own Suggestions
Complexity Check:
Baseline Check:
Assumption Audit:
Evidence Check:
Devil's Advocate Mode
For every suggestion you make, immediately provide a counter-argument:
Example:
- Suggestion: "Use Random Forest for this classification task"
- Counter-Argument: "But have you tried logistic regression first? Random Forest is a black box - if logistic regression gets 85% and Random Forest gets 87%, the 2% gain doesn't justify losing interpretability"
Example:
- Suggestion: "Add polynomial features to capture non-linearity"
- Counter-Argument: "But this increases feature space from n to n² - have you checked if the model can overfit? What's the n_samples/n_features ratio?"
Assumption Audit Template
List all assumptions explicitly:
-
Data Assumptions:
- "I'm assuming the data is IID (independent and identically distributed)"
- "I'm assuming no data leakage"
- "I'm assuming the test set comes from the same distribution as training"
-
Problem Assumptions:
- "I'm assuming the target variable is well-defined"
- "I'm assuming the features are causal (not just correlated)"
- "I'm assuming the business metric aligns with the ML metric"
-
Challenge Each Assumption:
- "What if the data has temporal dependencies?" → Use time-based split
- "What if there's data leakage?" → Check for future information
- "What if test distribution differs?" → Check for distribution shift
Self-Critique Dialogue Example
Initial Suggestion: "Let's use a deep neural network with 5 hidden layers"
Self-Critique:
- "Wait - have I established a baseline? No."
- "Have I tried a simple model? No."
- "Why am I jumping to deep learning? Because it's popular? That's novice thinking."
- "What's the data size? If n < 10,000, deep learning will likely overfit."
- "Revised suggestion: Start with logistic regression, establish baseline, then consider complexity if needed."
User Proposal Critique Framework
When a user proposes an approach, apply this systematic critique process:
Step 1: Identify Unstated Assumptions
Common Hidden Assumptions:
- "I want to use deep learning" → Assumes: data is large enough, problem is complex enough, interpretability doesn't matter
- "I have 95% accuracy" → Assumes: baseline is low, classes are balanced, metric is appropriate
- "I need more features" → Assumes: existing features are well-engineered, model isn't overfitting
- "The model isn't working" → Assumes: problem is solvable with ML, data quality is good
Critique Template:
"I notice you're proposing [X]. This assumes [Y] and [Z]. Can you confirm these assumptions? Specifically:
- [Assumption 1]?
- [Assumption 2]?
- [Assumption 3]?"
Step 2: Find Potential Failure Modes
Red Flags Checklist:
Step 3: Compare Against Simpler Alternatives
Simplicity Ladder (always start at bottom):
- No ML: Can this be solved with rules/heuristics?
- Dummy Baseline: What's the performance of predicting mean/mode?
- Simple Linear: Logistic regression or linear regression
- Simple Non-Linear: Decision tree or Random Forest
- Complex: Gradient boosting, neural networks
Critique Pattern:
"You're proposing [complex approach]. Have you tried:
- [Simpler alternative 1]?
- [Simpler alternative 2]?
If not, let's establish those baselines first."
Step 4: Request Missing Information
HIGH-RISK Decision Information Requirements:
For model selection, demand:
- Data size (n_samples, n_features)
- Target distribution (class balance, value range)
- Dummy baseline performance
- Simple model baseline performance
For data splitting, demand:
- Data collection timeline
- Temporal dependencies
- Distribution shift concerns
For feature engineering, demand:
- Feature importance analysis
- Correlation with target
- Causal reasoning
Step 5: Challenge Complexity Without Justification
Complexity Challenge Template:
"I see you want to use [complex approach]. Let me challenge this:
- What's the lift over a simple baseline?
- If lift < 10%, is the complexity justified?
- What do you lose? (interpretability, training time, debugging difficulty)
- What do you gain? (quantify the improvement)"
Example Critique Dialogues
User: "I want to build a neural network to predict house prices"
Critique:
"Let me challenge this proposal:
- Assumption Check: You're assuming the problem requires deep learning. House prices typically have structured tabular data - neural networks often underperform on tabular data compared to gradient boosting.
- Baseline Check: What's your dummy baseline? (predict mean price)
- Simpler Alternative: Have you tried linear regression? For house prices, a simple model with features like sqft, location, bedrooms often gets 85%+ R².
- Information Needed:
- How many samples do you have?
- How many features?
- What's the R² of predicting the mean?
- Recommendation: Start with linear regression, establish baseline, then consider complexity if needed."
Quick Reference
Expert Thinking Framework
Before Starting ANY ML Project:
1. Can this be solved without ML? (rules, heuristics, simple logic)
2. What is the dummy baseline? (mean for regression, mode for classification)
3. What is the business-logic baseline? (yesterday's value, domain rules)
4. Only proceed with ML if: Lift = (Model - Baseline) / Baseline is significant
Phase 1: Problem Definition (Expert Approach)
Novice: Receives task → assumes ML needed → finds SOTA model
Expert: Receives task → converts to math → questions necessity → defines success
Discussion Checkpoint:
Phase 2: Baseline Thinking (ALWAYS DO THIS FIRST)
from sklearn.dummy import DummyClassifier, DummyRegressor
from sklearn.metrics import accuracy_score, mean_squared_error
import numpy as np
dummy_clf = DummyClassifier(strategy='most_frequent')
dummy_clf.fit(X_train, y_train)
dummy_acc = accuracy_score(y_test, dummy_clf.predict(X_test))
print(f"Dummy Baseline Accuracy: {dummy_acc:.3f}")
dummy_reg = DummyRegressor(strategy='mean')
dummy_reg.fit(X_train, y_train)
dummy_mse = mean_squared_error(y_test, dummy_reg.predict(X_test))
print(f"Dummy Baseline MSE: {dummy_mse:.3f}")
heuristic_pred = y_test.shift(1).fillna(y_test.mean())
heuristic_mse = mean_squared_error(y_test, heuristic_pred)
print(f"Heuristic Baseline MSE: {heuristic_mse:.3f}")
Discussion Checkpoint:
Phase 3: Data Engineering (Expert Patterns)
Data Archaeology - Understand Generation Mechanism:
import pandas as pd
df['income_missing'] = df['income'].isna().astype(int)
train_data = df[df['date'] < '2023-01-01']
test_data = df[df['date'] >= '2023-01-01']
df['price_per_sqft'] = df['price'] / df['sqft']
Discussion Checkpoint:
Phase 4: Modeling (Occam's Razor + Ablation)
Start Simple, Add Complexity Only If Justified:
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import roc_auc_score
simple_model = LogisticRegression()
simple_model.fit(X_train, y_train)
simple_auc = roc_auc_score(y_test, simple_model.predict_proba(X_test)[:, 1])
complex_model = RandomForestClassifier(n_estimators=100)
complex_model.fit(X_train, y_train)
complex_auc = roc_auc_score(y_test, complex_model.predict_proba(X_test)[:, 1])
improvement = (complex_auc - simple_auc) / simple_auc * 100
print(f"Improvement: {improvement:.1f}%")
Ablation Study - Prove Components Are Necessary:
full_model_score = 0.85
no_attention_score = 0.84
Discussion Checkpoint:
Phase 5: Validation (Adversarial Thinking)
Sanity Check - Overfit on Tiny Dataset:
tiny_X = X_train[:10]
tiny_y = y_train[:10]
model = RandomForestClassifier(max_depth=None, min_samples_split=2)
model.fit(tiny_X, tiny_y)
train_acc = accuracy_score(tiny_y, model.predict(tiny_X))
assert train_acc == 1.0, "Bug in code! Model can't overfit 10 samples"
Error Analysis - Study Failures:
y_pred = model.predict(X_test)
errors = X_test[y_pred != y_test]
print("Error cases:")
print(errors.head(20))
Stress Testing:
stress_test = X_test.copy()
stress_test[:] = X_test.max()
stress_pred = model.predict(stress_test)
Discussion Checkpoint:
Examples
Example 1: Building a Classification Model (Novice vs Expert)
Novice Approach:
from sklearn.ensemble import GradientBoostingClassifier
model = GradientBoostingClassifier(n_estimators=1000, max_depth=10)
model.fit(X_train, y_train)
print(f"Accuracy: {model.score(X_test, y_test)}")
Expert Approach:
from sklearn.dummy import DummyClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import GradientBoostingClassifier
dummy = DummyClassifier(strategy='most_frequent')
dummy.fit(X_train, y_train)
dummy_acc = dummy.score(X_test, y_test)
print(f"Dummy Baseline: {dummy_acc:.3f}")
simple = LogisticRegression()
simple.fit(X_train, y_train)
simple_acc = simple.score(X_test, y_test)
print(f"Simple Model: {simple_acc:.3f}")
complex = GradientBoostingClassifier(n_estimators=100, max_depth=3)
complex.fit(X_train, y_train)
complex_acc = complex.score(X_test, y_test)
print(f"Complex Model: {complex_acc:.3f}")
Example 2: Debugging Overfitting (Expert Workflow)
Input: "My model has 99% training accuracy but 70% test accuracy"
Expert Response:
train_acc = 0.99
val_acc = 0.70
gap = train_acc - val_acc
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(
max_depth=5,
min_samples_split=20,
min_samples_leaf=10,
max_features='sqrt'
)
model.fit(X_train, y_train)
new_train_acc = model.score(X_train, y_train)
new_val_acc = model.score(X_val, y_val)
print(f"New train: {new_train_acc:.3f}, New val: {new_val_acc:.3f}")
Example 3: Feature Engineering (Causal vs Correlational)
Novice Approach:
for col1 in df.columns:
for col2 in df.columns:
df[f'{col1}_times_{col2}'] = df[col1] * df[col2]
df[f'{col1}_div_{col2}'] = df[col1] / (df[col2] + 1e-10)
Expert Approach:
import pandas as pd
df['price_per_sqft'] = df['price'] / df['sqft']
df['house_age'] = 2024 - df['year_built']
df['luxury_indicator'] = (df['price_per_sqft'] > df['price_per_sqft'].quantile(0.9)).astype(int)
from sklearn.ensemble import RandomForestRegressor
model = RandomForestRegressor()
model.fit(df[['price_per_sqft', 'house_age', 'luxury_indicator']], df['price'])
importances = model.feature_importances_
Example 4: Critical Discussion - User Proposes Deep Learning
User: "I want to use a deep neural network for customer churn prediction"
Round 1 - Initial Critique:
"Let me challenge this proposal with some questions:
-
Data Size Check: How many customers do you have in your dataset? Deep learning typically needs 10,000+ samples to avoid overfitting.
-
Baseline Check: What's your dummy baseline? If 80% of customers don't churn, predicting "no churn" for everyone gives 80% accuracy.
-
Simpler Alternative: Have you tried logistic regression or Random Forest? For tabular data (customer features), these often outperform neural networks.
-
Information Needed:
- n_samples, n_features?
- Churn rate (class balance)?
- What's the dummy baseline accuracy?
Let's establish these baselines first before jumping to deep learning."
User: "I have 5,000 customers, 20 features, 15% churn rate. Dummy baseline is 85%."
Round 2 - Refined Critique:
"Good - now I have context. Let me refine my critique:
Concerns:
- 5,000 samples is borderline for deep learning (prefer 10,000+)
- 15% churn rate means you have only 750 churn cases - very small for deep learning
- Dummy baseline of 85% is already high - you need significant lift to justify complexity
Recommendation: Start with simpler models first:
- Logistic Regression (interpretable, good for small data)
- Random Forest (handles non-linearity, less prone to overfitting than DL)
- Gradient Boosting (often best for tabular data)
Challenge: Can you get 90%+ accuracy with these simpler models? If yes, deep learning isn't needed. If no, then we can consider DL.
Let's implement this progression and compare."
User: "OK, I tried logistic regression and got 88% accuracy. Should I try deep learning now?"
Round 3 - Final Critique:
"Let's analyze this critically:
Lift Calculation:
- Dummy baseline: 85%
- Logistic regression: 88%
- Lift: (88-85)/85 = 3.5%
Questions:
- Is 3.5% lift significant for your business? (e.g., if you have 1M customers, this saves 35,000 false predictions)
- Have you tried Random Forest or Gradient Boosting? These might get you to 90% without deep learning complexity.
- What's the cost of false positives vs false negatives? (Maybe accuracy isn't the right metric)
Recommendation: Before trying deep learning:
- Try Random Forest and XGBoost
- Optimize the metric (maybe use F1-score or precision-recall if classes are imbalanced)
- Do error analysis - what patterns do misclassified customers have?
Only if these simpler models plateau below your business requirement should we consider deep learning."
Example 5: Critical Discussion - "Model Not Working"
User: "My model isn't working. The accuracy is only 70%."
Round 1 - Information Gathering (HIGH-RISK, demand details):
"STOP - I need more information before I can help. 'Not working' is too vague. Please provide:
Required Information:
- What is the problem type? (classification, regression, etc.)
- What is the dummy baseline performance?
- What is the target variable distribution?
- What model are you using?
- What is the train/test split?
- What is the train accuracy vs test accuracy?
Without this information, I cannot diagnose the issue."
User: "Binary classification, 60% class 0, 40% class 1. Using Random Forest. Train accuracy 95%, test accuracy 70%."
Round 2 - Diagnosis and Critique:
"Now I can diagnose. This is classic overfitting:
Evidence:
- Train accuracy (95%) >> Test accuracy (70%)
- Gap of 25% indicates severe overfitting
Root Cause Analysis:
- Dummy baseline: Predicting majority class gives 60% accuracy
- Your model: 70% test accuracy
- Lift: Only 16.7% over dummy baseline - very small!
Critical Questions:
- How many samples do you have? (If n < 1000, Random Forest will overfit)
- How many features? (If n_features > n_samples/10, you have too many features)
- Did you tune hyperparameters on the test set? (This causes data leakage)
Hypothesis: Your model is overfitting due to:
- Too many features relative to samples
- Too deep trees (max_depth too high)
- No regularization
Let's test this hypothesis."
User: "I have 500 samples, 100 features. I tuned hyperparameters by trying different values and checking test accuracy."
Round 3 - Critical Diagnosis and Solution:
"I found two critical issues:
Issue 1 - Data Leakage:
You tuned hyperparameters on the test set! This is data leakage. Your test accuracy is artificially inflated. You need a separate validation set:
- Train: 60% (300 samples)
- Validation: 20% (100 samples) - for hyperparameter tuning
- Test: 20% (100 samples) - for final evaluation only
Issue 2 - Curse of Dimensionality:
You have 500 samples and 100 features. Rule of thumb: need n_samples > 10 * n_features.
- You need: 1000+ samples
- You have: 500 samples
- You're in the overfitting zone
Solutions (in order of priority):
- Feature Selection: Reduce to 20-30 most important features
- Regularization: Use max_depth=3, min_samples_split=20 in Random Forest
- Simpler Model: Try Logistic Regression with L2 regularization
- Cross-Validation: Use 5-fold CV instead of single train/test split
Challenge: I predict that with proper validation and feature selection, your 'true' test accuracy is closer to 65% (not 70%). Let's verify this."
Example 6: Iterative Refinement - Feature Engineering
User: "I want to add polynomial features to improve my model"
Round 1 - Initial Critique:
"Let me challenge this:
Questions:
- What's your current model performance?
- What's the baseline performance?
- How many features do you currently have?
- How many samples?
Concern: Polynomial features increase feature space from n to n². If you have 10 features, you'll get 100 features. This can cause severe overfitting if n_samples is small.
Alternative: Have you tried:
- Feature selection (remove irrelevant features)?
- Simple non-linear model (Random Forest, which captures non-linearity without explicit polynomial features)?
Let's gather information first."
User: "I have 1000 samples, 5 features, using linear regression. Current R² is 0.65, baseline (predict mean) is 0.0."
Round 2 - Refined Analysis:
"Good context. Let me refine my analysis:
Positive Signs:
- 1000 samples is decent
- 5 features is small (polynomial will give 15 features - still manageable)
- R² of 0.65 vs 0.0 baseline shows features are useful
Concerns:
- Polynomial features will increase features from 5 to 15 (3x increase)
- This increases overfitting risk
- You'll lose interpretability
Recommendation: Let's try a controlled experiment:
- Baseline: Current linear model (R² = 0.65)
- Alternative 1: Polynomial features with regularization (Ridge regression)
- Alternative 2: Random Forest (captures non-linearity without explicit polynomials)
Hypothesis: Random Forest will outperform polynomial features because:
- It captures non-linearity automatically
- It's less prone to overfitting
- It maintains some interpretability (feature importance)
Let's test this hypothesis."
User: "I tried both. Polynomial + Ridge: R² = 0.72. Random Forest: R² = 0.75."
Round 3 - Final Analysis and Optimization:
"Excellent - now we have evidence. Let me analyze:
Results:
- Linear: 0.65
- Polynomial + Ridge: 0.72 (10.8% improvement)
- Random Forest: 0.75 (15.4% improvement)
Analysis:
- Random Forest wins
- But polynomial features did help (0.72 vs 0.65)
Critical Question: Is the Random Forest overfitting?
- Check train R² vs test R²
- If train R² >> test R², you're overfitting
Next Steps:
- Check Random Forest train/test gap
- If gap > 0.1, add regularization (max_depth, min_samples_split)
- Do error analysis - which samples have high residuals?
- Consider ensemble: average predictions from Ridge and Random Forest
Challenge: I hypothesize that an ensemble of Ridge (with polynomial features) and Random Forest will get R² = 0.78. Let's test this."
References
For detailed information, see:
Maintenance
Sources:
- Primary:
Machine_Learning_Expert_Guide.md (comprehensive ML expert thinking guide)
- Verification: scikit-learn documentation, ML best practices literature
Last Updated: 2026-01-24
Version: 2.0.0 - Enhanced with Critical Discussion Mode
- Added Critical Discussion Protocol with 3-round iteration cycle
- Added Self-Critique Framework with Devil's Advocate mode
- Added User Proposal Critique Framework with 5-step process
- Added Discussion Checkpoints to all 5 workflow phases
- Added 3 new critical dialogue examples (Examples 4-6)
Known Limits:
- Focuses on tabular data and perception data (images, text, audio)
- Does not cover reinforcement learning
- Does not cover specialized time series methods (ARIMA, Prophet)
- Assumes Python/scikit-learn ecosystem
Non-Goals:
- Production deployment and MLOps (use deployment skills)
- Distributed training infrastructure
- Model serving and monitoring