LQF Machine Learning Expert Guide

From foryourhealth111-pixel/Vibe-Skills · View interactive version

LQF Machine Learning Expert Guide is an AI agent skill from the GitHub repository foryourhealth111-pixel/Vibe-Skills. 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 tuni

How to use this skill

Skill file

LQF Machine Learning Expert Guide

When to Use This Skill

Use this skill when:

Not For / Boundaries

Out of Scope:

Required Inputs - Ask User If Missing:

  1. What is the problem type? (classification, regression, clustering, etc.)
  2. What does your data look like? (size, number of features, target variable distribution)
  3. 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

  1. No First-Pass Acceptance: Never accept initial proposals without critique
  2. Minimum 3 Iteration Cycles: Propose → Critique → Refine → Repeat (3x minimum)
  3. Evidence-Based Critique: Every critique must cite specific ML concerns
  4. Tiered Information Requirements:

Critique Intensity Levels

Level 1 - Diplomatic (for exploration/brainstorming):

Level 2 - Socratic (for investigating alternatives):

Level 3 - Direct (for critical mistakes):

Mandatory Information Checklist (HIGH-RISK Decisions)

Before proceeding with model selection or training, DEMAND answers to:

Iterative Refinement Cycle

Round 1 - Initial Proposal:

Round 2 - First Refinement:

Round 3 - Second Refinement:

Acceptance Criteria:

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:

Example:

Assumption Audit Template

List all assumptions explicitly:

  1. Data Assumptions:
  1. Problem Assumptions:
  1. Challenge Each Assumption:

Self-Critique Dialogue Example

Initial Suggestion: "Let's use a deep neural network with 5 hidden layers"

Self-Critique:

User Proposal Critique Framework

When a user proposes an approach, apply this systematic critique process:

Step 1: Identify Unstated Assumptions

Common Hidden Assumptions:

Critique Template:

"I notice you're proposing [X]. This assumes [Y] and [Z]. Can you confirm these assumptions? Specifically:

Step 2: Find Potential Failure Modes

Red Flags Checklist:

Step 3: Compare Against Simpler Alternatives

Simplicity Ladder (always start at bottom):

  1. No ML: Can this be solved with rules/heuristics?
  2. Dummy Baseline: What's the performance of predicting mean/mode?
  3. Simple Linear: Logistic regression or linear regression
  4. Simple Non-Linear: Decision tree or Random Forest
  5. Complex: Gradient boosting, neural networks

Critique Pattern:

"You're proposing [complex approach]. Have you tried:

If not, let's establish those baselines first."

Step 4: Request Missing Information

HIGH-RISK Decision Information Requirements:

For model selection, demand:

For data splitting, demand:

For feature engineering, demand:

Step 5: Challenge Complexity Without Justification

Complexity Challenge Template:

"I see you want to use [complex approach]. Let me challenge this:

Example Critique Dialogues

User: "I want to build a neural network to predict house prices"

Critique:

"Let me challenge this proposal:

  1. 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.
  2. Baseline Check: What's your dummy baseline? (predict mean price)
  3. Simpler Alternative: Have you tried linear regression? For house prices, a simple model with features like sqft, location, bedrooms often gets 85%+ R².
  4. Information Needed:
  1. 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

# Expert Problem Definition Checklist
# 1. Mathematical formulation
#    - Classification: P(y|X) where y ∈ {0,1,...,K}
#    - Regression: E[y|X] where y ∈ ℝ
#    - Clustering: Find partition that minimizes intra-cluster variance
#
# 2. Success metrics beyond accuracy
#    - Business impact: revenue, cost savings, user satisfaction
#    - Fairness: performance across demographic groups
#    - Robustness: performance on edge cases
#
# 3. Negative consequences
#    - Optimizing CTR → clickbait
#    - Optimizing engagement → filter bubbles

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

# STEP 1: Dummy Baseline (statistical guess)
# Classification: predict most frequent class
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}")

# Regression: predict mean
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}")

# STEP 2: Simple Heuristic Baseline (domain knowledge)
# Example for time series: "tomorrow = today"
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}")

# STEP 3: Calculate Lift
# Your complex model MUST beat these baselines significantly
# If lift < 10%, question whether complexity is justified

Discussion Checkpoint:

Phase 3: Data Engineering (Expert Patterns)

Data Archaeology - Understand Generation Mechanism:

# Check missing value patterns (informative vs random)
import pandas as pd

# Are missing values informative?
df['income_missing'] = df['income'].isna().astype(int)
# If income_missing correlates with target, it's informative!

# Check for data leakage (temporal)
# WRONG: Random split when data has time component
# RIGHT: Time-based split
train_data = df[df['date'] < '2023-01-01']
test_data = df[df['date'] >= '2023-01-01']

# Feature engineering: causality over correlation
# NOVICE: Add all possible features
# EXPERT: Add features with causal relationship
df['price_per_sqft'] = df['price'] / df['sqft']  # Causal: price depends on size
# Avoid: df['random_correlation'] = df['feature1'] * df['feature2']  # No causal story

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

# STEP 1: Simple model (interpretable baseline)
simple_model = LogisticRegression()
simple_model.fit(X_train, y_train)
simple_auc = roc_auc_score(y_test, simple_model.predict_proba(X_test)[:, 1])

# STEP 2: Complex model
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])

# STEP 3: Justify complexity
improvement = (complex_auc - simple_auc) / simple_auc * 100
print(f"Improvement: {improvement:.1f}%")
# If improvement < 5%, use simple model (interpretability wins)

Ablation Study - Prove Components Are Necessary:

# Remove components one by one to prove they're needed
# Example: Testing if attention mechanism helps

# Full model
full_model_score = 0.85

# Remove attention
no_attention_score = 0.84  # Only 0.01 drop

# Conclusion: Attention adds complexity without benefit → REMOVE IT
# Only keep components where removal causes significant (>2%) drop

Discussion Checkpoint:

Phase 5: Validation (Adversarial Thinking)

Sanity Check - Overfit on Tiny Dataset:

# Take 10 samples, turn off regularization
# Model MUST achieve 100% training accuracy
# If it can't, you have a bug (not a model problem)

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:

# Don't celebrate 95% accuracy, analyze 5% errors
y_pred = model.predict(X_test)
errors = X_test[y_pred != y_test]

# Manually inspect errors
print("Error cases:")
print(errors.head(20))

# Look for patterns:
# - Mislabeled data?
# - Missing features for these cases?
# - Systematic bias?

Stress Testing:

# Test with adversarial inputs
# - Missing values
# - Extreme values
# - Out-of-distribution data

# Example: What if all features are at max?
stress_test = X_test.copy()
stress_test[:] = X_test.max()
stress_pred = model.predict(stress_test)
# Does output make sense?

Discussion Checkpoint:

Examples

Example 1: Building a Classification Model (Novice vs Expert)

Novice Approach:

# Novice: Jump straight to complex model
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)}")  # 0.87
# "Great! 87% accuracy!"

Expert Approach:

# Expert: Establish baseline first
from sklearn.dummy import DummyClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import GradientBoostingClassifier

# Step 1: Dummy baseline
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}")  # 0.82

# Step 2: Simple model
simple = LogisticRegression()
simple.fit(X_train, y_train)
simple_acc = simple.score(X_test, y_test)
print(f"Simple Model: {simple_acc:.3f}")  # 0.85

# Step 3: Complex model
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}")  # 0.87

# Analysis: 87% vs 82% dummy = only 6% lift
# 87% vs 85% simple = only 2.4% improvement
# Conclusion: Use simple logistic regression (interpretable, 85% is good enough)

Example 2: Debugging Overfitting (Expert Workflow)

Input: "My model has 99% training accuracy but 70% test accuracy"

Expert Response:

# This is classic overfitting. Let's diagnose systematically.

# Step 1: Check train-val gap
train_acc = 0.99
val_acc = 0.70
gap = train_acc - val_acc  # 0.29 - HUGE gap!

# Step 2: Regularization ladder (in order)
# Level 1: Batch Normalization (if deep learning)
# Level 2: Data Augmentation (most effective)
# Level 3: Dropout
# Level 4: L2 regularization

# For traditional ML (e.g., Random Forest):
from sklearn.ensemble import RandomForestClassifier

# Reduce complexity
model = RandomForestClassifier(
    max_depth=5,           # Limit tree depth
    min_samples_split=20,  # Require more samples to split
    min_samples_leaf=10,   # Require more samples in leaves
    max_features='sqrt'    # Limit features per tree
)
model.fit(X_train, y_train)

# Step 3: Check if gap closes
new_train_acc = model.score(X_train, y_train)  # Should drop from 99%
new_val_acc = model.score(X_val, y_val)        # Should increase from 70%

print(f"New train: {new_train_acc:.3f}, New val: {new_val_acc:.3f}")
# Goal: Gap < 0.05 (5%)

Example 3: Feature Engineering (Causal vs Correlational)

Novice Approach:

# Novice: Create all possible feature combinations
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)
# Result: 10,000 features, most are noise

Expert Approach:

# Expert: Create features with causal story
import pandas as pd

# Domain: House price prediction
# Causal reasoning: Price depends on size AND location

# Good: Price per square foot (causal relationship)
df['price_per_sqft'] = df['price'] / df['sqft']

# Good: Age of house (older = more depreciation)
df['house_age'] = 2024 - df['year_built']

# Good: Interaction with causal meaning
df['luxury_indicator'] = (df['price_per_sqft'] > df['price_per_sqft'].quantile(0.9)).astype(int)

# Bad: Random multiplication (no causal story)
# df['random_feature'] = df['bedrooms'] * df['bathrooms']  # Why multiply these?

# Validate: Check feature importance
from sklearn.ensemble import RandomForestRegressor
model = RandomForestRegressor()
model.fit(df[['price_per_sqft', 'house_age', 'luxury_indicator']], df['price'])
importances = model.feature_importances_
# If importance < 0.01, remove feature

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:

  1. Data Size Check: How many customers do you have in your dataset? Deep learning typically needs 10,000+ samples to avoid overfitting.
  1. Baseline Check: What's your dummy baseline? If 80% of customers don't churn, predicting "no churn" for everyone gives 80% accuracy.
  1. Simpler Alternative: Have you tried logistic regression or Random Forest? For tabular data (customer features), these often outperform neural networks.
  1. Information Needed:

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:

Recommendation: Start with simpler models first:

  1. Logistic Regression (interpretable, good for small data)
  2. Random Forest (handles non-linearity, less prone to overfitting than DL)
  3. 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:

Questions:

  1. Is 3.5% lift significant for your business? (e.g., if you have 1M customers, this saves 35,000 false predictions)
  2. Have you tried Random Forest or Gradient Boosting? These might get you to 90% without deep learning complexity.
  3. What's the cost of false positives vs false negatives? (Maybe accuracy isn't the right metric)

Recommendation: Before trying deep learning:

  1. Try Random Forest and XGBoost
  2. Optimize the metric (maybe use F1-score or precision-recall if classes are imbalanced)
  3. 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:

  1. What is the problem type? (classification, regression, etc.)
  2. What is the dummy baseline performance?
  3. What is the target variable distribution?
  4. What model are you using?
  5. What is the train/test split?
  6. 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:

Root Cause Analysis:

  1. Dummy baseline: Predicting majority class gives 60% accuracy
  2. Your model: 70% test accuracy
  3. Lift: Only 16.7% over dummy baseline - very small!

Critical Questions:

  1. How many samples do you have? (If n < 1000, Random Forest will overfit)
  2. How many features? (If n_features > n_samples/10, you have too many features)
  3. Did you tune hyperparameters on the test set? (This causes data leakage)

Hypothesis: Your model is overfitting due to:

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:

Issue 2 - Curse of Dimensionality:

You have 500 samples and 100 features. Rule of thumb: need n_samples > 10 * n_features.

Solutions (in order of priority):

  1. Feature Selection: Reduce to 20-30 most important features
  2. Regularization: Use max_depth=3, min_samples_split=20 in Random Forest
  3. Simpler Model: Try Logistic Regression with L2 regularization
  4. 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:

  1. What's your current model performance?
  2. What's the baseline performance?
  3. How many features do you currently have?
  4. 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:

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:

Concerns:

Recommendation: Let's try a controlled experiment:

  1. Baseline: Current linear model (R² = 0.65)
  2. Alternative 1: Polynomial features with regularization (Ridge regression)
  3. Alternative 2: Random Forest (captures non-linearity without explicit polynomials)

Hypothesis: Random Forest will outperform polynomial features because:

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:

Analysis:

Critical Question: Is the Random Forest overfitting?

Next Steps:

  1. Check Random Forest train/test gap
  2. If gap > 0.1, add regularization (max_depth, min_samples_split)
  3. Do error analysis - which samples have high residuals?
  4. 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:

Last Updated: 2026-01-24

Version: 2.0.0 - Enhanced with Critical Discussion Mode

Known Limits:

Non-Goals:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.