Quiz 2
Registry Synced

Learning Objectives

289 words
1 min read

Learning Objectives

  • Train multiple ML models
  • Evaluate with appropriate metrics
  • Compare model performance
python
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier
from sklearn.svm import SVC
from sklearn.metrics import (accuracy_score, precision_score, recall_score,
                             f1_score, confusion_matrix, classification_report,
                             roc_auc_score, roc_curve)
import matplotlib.pyplot as plt
# Train multiple models
models = {
    'Logistic Regression': LogisticRegression(max_iter=1000),
    'Random Forest': RandomForestClassifier(n_estimators=100),
    'Gradient Boosting': GradientBoostingClassifier(n_estimators=100),
    'SVM': SVC(probability=True)
}
results = {}
for name, model in models.items():
    model.fit(X_train, y_train)
    y_pred = model.predict(X_test)
    y_proba = model.predict_proba(X_test)[:, 1]
    results[name] = {
        'accuracy': accuracy_score(y_test, y_pred),
        'precision': precision_score(y_test, y_pred),
        'recall': recall_score(y_test, y_pred),
        'f1': f1_score(y_test, y_pred),
        'roc_auc': roc_auc_score(y_test, y_proba)
    }
# Print comparison
results_df = pd.DataFrame(results).T
print(results_df.round(3))
# Confusion matrix
cm = confusion_matrix(y_test, y_pred)
sns.heatmap(cm, annot=True, fmt='d', cmap='Blues')
Q1: How to choose evaluation metric?
Accuracy: balanced classes. Precision: minimize false positives (spam detection). Recall: minimize false negatives (disease detection). F1: balance precision and recall. AUC: ranking quality. Q2: What is overfitting and how to detect?
Model performs well on training but poorly on test. Detect: compare train/test metrics (large gap). Fix: regularization, simpler model, more data, cross-validation. Q3: What is cross-validation?
Split data into k folds, train on k-1, test on 1, repeat k times. More reliable estimate than single train/test split. k=5 or 10 is standard. Q4: How to interpret ROC-AUC?
0.5 = random guessing, 0.7-0.8 = acceptable, 0.8-0.9 = excellent, >0.9 = outstanding. Measures model's ability to distinguish positive/negative classes across thresholds. Q5: When to use which algorithm?
Linear: LR, SVM-linear (high dim, sparse). Non-linear: RF, GB, SVM-RBF (complex, non-linear). Fast training: LR, NB. High accuracy: XGBoost, LightGBM. Join Discord PreviousMilestone 3: Data Preprocessing & Feature EngineeringNextMilestone 5: Hyperparameter Tuning
Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.