Skill Tracer
Skills › Scientific Agent Skills › scikit-learn › supervised_learning.md

supervised_learning.md

387 lines · skills/scikit-learn/references/supervised_learning.md at 5f2bc03

Open on GitHub
1# Supervised Learning Reference
2
3Targets scikit-learn 1.9.1. Snippets with caller-supplied data/columns are illustrative; fit all learned preprocessing inside the training folds when estimating predictive performance.
4

Supervised Learning Reference

Targets scikit-learn 1.9.1. Snippets with caller-supplied data/columns are illustrative; fit all learned preprocessing inside the training folds when estimating predictive performance.

Raw lines 1 to 4
5## Overview
6
7Supervised learning algorithms learn from labeled training data to make predictions on new data. Scikit-learn provides comprehensive implementations for both classification and regression tasks.
8

Overview

Supervised learning algorithms learn from labeled training data to make predictions on new data. Scikit-learn provides comprehensive implementations for both classification and regression tasks.

Raw lines 5 to 8
9## Linear Models

Linear Models

Raw lines 9 to 10
11### Regression
13**Linear Regression (`sklearn.linear_model.LinearRegression`)**
14- Ordinary least squares regression
15- Ordinary least squares; choices include intercept, positivity constraints, and sparse-solver tolerance
16- Use when: Linear relationships, interpretability matters
17- Example:
18```python
19from sklearn.linear_model import LinearRegression
21model = LinearRegression()
22model.fit(X_train, y_train)
23predictions = model.predict(X_test)
24```
26**Ridge Regression (`sklearn.linear_model.Ridge`)**
27- L2 regularization to prevent overfitting
28- Key parameter: `alpha` (regularization strength, default=1.0)
29- Use when: Multicollinearity present, need regularization
30- Example:
31```python
32from sklearn.linear_model import Ridge
34model = Ridge(alpha=1.0)
35model.fit(X_train, y_train)
36```
38**Lasso (`sklearn.linear_model.Lasso`)**
39- L1 regularization with feature selection
40- Key parameter: `alpha` (regularization strength)
41- Use when: Want sparse models, feature selection
42- Can reduce some coefficients to exactly zero
43- Example:
44```python
45from sklearn.linear_model import Lasso
47model = Lasso(alpha=0.1)
48model.fit(X_train, y_train)
49# Check which features were selected
50print(f"Non-zero coefficients: {sum(model.coef_ != 0)}")
51```
53**ElasticNet (`sklearn.linear_model.ElasticNet`)**
54- Combines L1 and L2 regularization
55- Key parameters: `alpha`, `l1_ratio` (0=Ridge, 1=Lasso)
56- Use when: Need both feature selection and regularization
57- Example:
58```python
59from sklearn.linear_model import ElasticNet
61model = ElasticNet(alpha=0.1, l1_ratio=0.5)
62model.fit(X_train, y_train)
63```

Regression

**Linear Regression (sklearn.linear_model.LinearRegression)**

  • Ordinary least squares regression
  • Ordinary least squares; choices include intercept, positivity constraints, and sparse-solver tolerance
  • Use when: Linear relationships, interpretability matters
  • Example:
from sklearn.linear_model import LinearRegression

model = LinearRegression()
model.fit(X_train, y_train)
predictions = model.predict(X_test)

**Ridge Regression (sklearn.linear_model.Ridge)**

  • L2 regularization to prevent overfitting
  • Key parameter: alpha (regularization strength, default=1.0)
  • Use when: Multicollinearity present, need regularization
  • Example:
from sklearn.linear_model import Ridge

model = Ridge(alpha=1.0)
model.fit(X_train, y_train)

**Lasso (sklearn.linear_model.Lasso)**

  • L1 regularization with feature selection
  • Key parameter: alpha (regularization strength)
  • Use when: Want sparse models, feature selection
  • Can reduce some coefficients to exactly zero
  • Example:
from sklearn.linear_model import Lasso

model = Lasso(alpha=0.1)
model.fit(X_train, y_train)
# Check which features were selected
print(f"Non-zero coefficients: {sum(model.coef_ != 0)}")

**ElasticNet (sklearn.linear_model.ElasticNet)**

  • Combines L1 and L2 regularization
  • Key parameters: alpha, l1_ratio (0=Ridge, 1=Lasso)
  • Use when: Need both feature selection and regularization
  • Example:
from sklearn.linear_model import ElasticNet

model = ElasticNet(alpha=0.1, l1_ratio=0.5)
model.fit(X_train, y_train)
Raw lines 11 to 64
65### Classification
67**Logistic Regression (`sklearn.linear_model.LogisticRegression`)**
68- Binary and multiclass classification
69- Key parameters: `C` (inverse regularization), `l1_ratio` (0=L2, 1=L1, between for elastic net)
70- Returns probability estimates
71- Use when: Need probabilistic predictions, interpretability
72- `penalty` is deprecated since 1.8; use `l1_ratio`. `lbfgs` supports only L2 (`l1_ratio=0`); use `saga` for elastic net. Use `C=np.inf` for no regularization
73- Example:
74```python
75from sklearn.linear_model import LogisticRegression
77model = LogisticRegression(C=1.0, l1_ratio=0.0, max_iter=1000)
78model.fit(X_train, y_train)
79probas = model.predict_proba(X_test)
80```
82**Stochastic Gradient Descent (SGD)**
83- `SGDClassifier`, `SGDRegressor`
84- Efficient for large-scale learning
85- Key parameters: `loss`, `penalty`, `alpha`, `learning_rate`
86- Use when: Very large datasets (>10^4 samples)
87- Example:
88```python
89from sklearn.linear_model import SGDClassifier
91model = SGDClassifier(loss='log_loss', max_iter=1000, tol=1e-3)
92model.fit(X_train, y_train)
93```

Classification

**Logistic Regression (sklearn.linear_model.LogisticRegression)**

  • Binary and multiclass classification
  • Key parameters: C (inverse regularization), l1_ratio (0=L2, 1=L1, between for elastic net)
  • Returns probability estimates
  • Use when: Need probabilistic predictions, interpretability
  • penalty is deprecated since 1.8; use l1_ratio. lbfgs supports only L2 (l1_ratio=0); use saga for elastic net. Use C=np.inf for no regularization
  • Example:
from sklearn.linear_model import LogisticRegression

model = LogisticRegression(C=1.0, l1_ratio=0.0, max_iter=1000)
model.fit(X_train, y_train)
probas = model.predict_proba(X_test)

Stochastic Gradient Descent (SGD)

  • SGDClassifier, SGDRegressor
  • Efficient for large-scale learning
  • Key parameters: loss, penalty, alpha, learning_rate
  • Use when: Very large datasets (>10^4 samples)
  • Example:
from sklearn.linear_model import SGDClassifier

model = SGDClassifier(loss='log_loss', max_iter=1000, tol=1e-3)
model.fit(X_train, y_train)
Raw lines 65 to 94
95## Support Vector Machines
97**SVC (`sklearn.svm.SVC`)**
98- Classification with kernel methods
99- Key parameters: `C`, `kernel` ('linear', 'rbf', 'poly'), `gamma`
100- Use when: Small to medium datasets, complex decision boundaries
101- Note: Does not scale well to large datasets
102- Example:
103```python
104from sklearn.svm import SVC
106# Linear kernel for linearly separable data
107model_linear = SVC(kernel='linear', C=1.0)
109# RBF kernel for non-linear data
110model_rbf = SVC(kernel='rbf', C=1.0, gamma='scale')
111model_rbf.fit(X_train, y_train)
112```
114**SVR (`sklearn.svm.SVR`)**
115- Regression with kernel methods
116- Similar parameters to SVC
117- Additional parameter: `epsilon` (tube width)
118- Example:
119```python
120from sklearn.svm import SVR
122model = SVR(kernel='rbf', C=1.0, epsilon=0.1)
123model.fit(X_train, y_train)
124```

Support Vector Machines

**SVC (sklearn.svm.SVC)**

  • Classification with kernel methods
  • Key parameters: C, kernel ('linear', 'rbf', 'poly'), gamma
  • Use when: Small to medium datasets, complex decision boundaries
  • Note: Does not scale well to large datasets
  • Example:
from sklearn.svm import SVC

# Linear kernel for linearly separable data
model_linear = SVC(kernel='linear', C=1.0)

# RBF kernel for non-linear data
model_rbf = SVC(kernel='rbf', C=1.0, gamma='scale')
model_rbf.fit(X_train, y_train)

**SVR (sklearn.svm.SVR)**

  • Regression with kernel methods
  • Similar parameters to SVC
  • Additional parameter: epsilon (tube width)
  • Example:
from sklearn.svm import SVR

model = SVR(kernel='rbf', C=1.0, epsilon=0.1)
model.fit(X_train, y_train)
Raw lines 95 to 125
126## Decision Trees
128**DecisionTreeClassifier / DecisionTreeRegressor**
129- Non-parametric model learning decision rules
130- Key parameters:
131 - `max_depth`: Maximum tree depth (prevents overfitting)
132 - `min_samples_split`: Minimum samples to split a node
133 - `min_samples_leaf`: Minimum samples in leaf
134 - `criterion`: 'gini', 'entropy' for classification; 'squared_error', 'absolute_error' for regression
135- Use when: Need interpretable model, non-linear relationships, mixed feature types
136- Prone to overfitting - use ensembles or pruning
137- Example:
138```python
139from sklearn.tree import DecisionTreeClassifier
141model = DecisionTreeClassifier(
142 max_depth=5,
143 min_samples_split=20,
144 min_samples_leaf=10,
145 criterion='gini'
147model.fit(X_train, y_train)
149# Visualize the tree
150from sklearn.tree import plot_tree
151plot_tree(model, feature_names=feature_names, class_names=class_names)
152```

Decision Trees

DecisionTreeClassifier / DecisionTreeRegressor

  • Non-parametric model learning decision rules
  • Key parameters:
  • max_depth: Maximum tree depth (prevents overfitting)
  • min_samples_split: Minimum samples to split a node
  • min_samples_leaf: Minimum samples in leaf
  • criterion: 'gini', 'entropy' for classification; 'squared_error', 'absolute_error' for regression
  • Use when: Need interpretable model, non-linear relationships, mixed feature types
  • Prone to overfitting - use ensembles or pruning
  • Example:
from sklearn.tree import DecisionTreeClassifier

model = DecisionTreeClassifier(
    max_depth=5,
    min_samples_split=20,
    min_samples_leaf=10,
    criterion='gini'
)
model.fit(X_train, y_train)

# Visualize the tree
from sklearn.tree import plot_tree
plot_tree(model, feature_names=feature_names, class_names=class_names)
Raw lines 126 to 153
154## Ensemble Methods

Ensemble Methods

Raw lines 154 to 155
156### Random Forests
158**RandomForestClassifier / RandomForestRegressor**
159- Ensemble of decision trees with bagging
160- Key parameters:
161 - `n_estimators`: Number of trees (default=100)
162 - `max_depth`: Maximum tree depth
163 - `max_features`: Features to consider for splits ('sqrt', 'log2', or int)
164 - `min_samples_split`, `min_samples_leaf`: Control tree growth
165- Use when: High accuracy needed, can afford computation
166- Provides impurity importance, which favors high-cardinality features; use held-out permutation importance to assess predictive contribution, not causality
167- Example:
168```python
169from sklearn.ensemble import RandomForestClassifier
171model = RandomForestClassifier(
172 n_estimators=100,
173 max_depth=10,
174 max_features='sqrt',
175 n_jobs=-1 # Use all CPU cores
177model.fit(X_train, y_train)
179# Feature importance
180importances = model.feature_importances_
181```

Random Forests

RandomForestClassifier / RandomForestRegressor

  • Ensemble of decision trees with bagging
  • Key parameters:
  • n_estimators: Number of trees (default=100)
  • max_depth: Maximum tree depth
  • max_features: Features to consider for splits ('sqrt', 'log2', or int)
  • min_samples_split, min_samples_leaf: Control tree growth
  • Use when: High accuracy needed, can afford computation
  • Provides impurity importance, which favors high-cardinality features; use held-out permutation importance to assess predictive contribution, not causality
  • Example:
from sklearn.ensemble import RandomForestClassifier

model = RandomForestClassifier(
    n_estimators=100,
    max_depth=10,
    max_features='sqrt',
    n_jobs=-1  # Use all CPU cores
)
model.fit(X_train, y_train)

# Feature importance
importances = model.feature_importances_
Raw lines 156 to 182
183### Gradient Boosting
185**GradientBoostingClassifier / GradientBoostingRegressor**
186- Sequential ensemble building trees on residuals
187- Key parameters:
188 - `n_estimators`: Number of boosting stages
189 - `learning_rate`: Shrinks contribution of each tree
190 - `max_depth`: Depth of individual trees (typically 3-5)
191 - `subsample`: Fraction of samples for training each tree
192- Use when: Need high accuracy, can afford training time
193- Compare on a held-out design; no estimator is universally best
194- Example:
195```python
196from sklearn.ensemble import GradientBoostingClassifier
198model = GradientBoostingClassifier(
199 n_estimators=100,
200 learning_rate=0.1,
201 max_depth=3,
202 subsample=0.8
204model.fit(X_train, y_train)
205```
207**HistGradientBoostingClassifier / HistGradientBoostingRegressor**
208- Faster gradient boosting with histogram-based algorithm
209- Native support for missing values and categorical features
210- Uses `max_iter` rather than `n_estimators`. `from_dtype` detects pandas categorical dtype, not arbitrary strings; each categorical feature must fit the `max_bins` cardinality limit
211- Use when: Large datasets, need faster training
212- Example:
213```python
214from sklearn.ensemble import HistGradientBoostingClassifier
216model = HistGradientBoostingClassifier(
217 max_iter=100,
218 learning_rate=0.1,
219 max_depth=None, # No limit by default
220 categorical_features='from_dtype' # Auto-detect categorical
222model.fit(X_train, y_train)
223```

Gradient Boosting

GradientBoostingClassifier / GradientBoostingRegressor

  • Sequential ensemble building trees on residuals
  • Key parameters:
  • n_estimators: Number of boosting stages
  • learning_rate: Shrinks contribution of each tree
  • max_depth: Depth of individual trees (typically 3-5)
  • subsample: Fraction of samples for training each tree
  • Use when: Need high accuracy, can afford training time
  • Compare on a held-out design; no estimator is universally best
  • Example:
from sklearn.ensemble import GradientBoostingClassifier

model = GradientBoostingClassifier(
    n_estimators=100,
    learning_rate=0.1,
    max_depth=3,
    subsample=0.8
)
model.fit(X_train, y_train)

HistGradientBoostingClassifier / HistGradientBoostingRegressor

  • Faster gradient boosting with histogram-based algorithm
  • Native support for missing values and categorical features
  • Uses max_iter rather than n_estimators. from_dtype detects pandas categorical dtype, not arbitrary strings; each categorical feature must fit the max_bins cardinality limit
  • Use when: Large datasets, need faster training
  • Example:
from sklearn.ensemble import HistGradientBoostingClassifier

model = HistGradientBoostingClassifier(
    max_iter=100,
    learning_rate=0.1,
    max_depth=None,  # No limit by default
    categorical_features='from_dtype'  # Auto-detect categorical
)
model.fit(X_train, y_train)
Raw lines 183 to 224
225### Other Ensemble Methods
227**AdaBoost**
228- Adaptive boosting focusing on misclassified samples
229- Key parameters: `n_estimators`, `learning_rate`, `estimator` (base estimator)
230- Use when: Simple boosting approach needed
231- Example:
232```python
233from sklearn.ensemble import AdaBoostClassifier
235model = AdaBoostClassifier(n_estimators=50, learning_rate=1.0)
236model.fit(X_train, y_train)
237```
239**Voting Classifier / Regressor**
240- Combines predictions from multiple models
241- Types: 'hard' (majority vote) or 'soft' (average probabilities)
242- Use when: Want to ensemble different model types
243- Example:
244```python
245from sklearn.ensemble import VotingClassifier
246from sklearn.linear_model import LogisticRegression
247from sklearn.tree import DecisionTreeClassifier
248from sklearn.svm import SVC
250model = VotingClassifier(
251 estimators=[
252 ('lr', LogisticRegression()),
253 ('dt', DecisionTreeClassifier()),
254 ('svc', SVC(probability=True))
255 ],
256 voting='soft'
258model.fit(X_train, y_train)
259```
261**Stacking Classifier / Regressor**
262- Trains a meta-model on predictions from base models
263- More sophisticated than voting
264- Key parameter: `final_estimator` (meta-learner)
265- Example:
266```python
267from sklearn.ensemble import StackingClassifier
268from sklearn.linear_model import LogisticRegression
269from sklearn.tree import DecisionTreeClassifier
270from sklearn.svm import SVC
272model = StackingClassifier(
273 estimators=[
274 ('dt', DecisionTreeClassifier()),
275 ('svc', SVC())
276 ],
277 final_estimator=LogisticRegression()
279model.fit(X_train, y_train)
280```

Other Ensemble Methods

AdaBoost

  • Adaptive boosting focusing on misclassified samples
  • Key parameters: n_estimators, learning_rate, estimator (base estimator)
  • Use when: Simple boosting approach needed
  • Example:
from sklearn.ensemble import AdaBoostClassifier

model = AdaBoostClassifier(n_estimators=50, learning_rate=1.0)
model.fit(X_train, y_train)

Voting Classifier / Regressor

  • Combines predictions from multiple models
  • Types: 'hard' (majority vote) or 'soft' (average probabilities)
  • Use when: Want to ensemble different model types
  • Example:
from sklearn.ensemble import VotingClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.svm import SVC

model = VotingClassifier(
    estimators=[
        ('lr', LogisticRegression()),
        ('dt', DecisionTreeClassifier()),
        ('svc', SVC(probability=True))
    ],
    voting='soft'
)
model.fit(X_train, y_train)

Stacking Classifier / Regressor

  • Trains a meta-model on predictions from base models
  • More sophisticated than voting
  • Key parameter: final_estimator (meta-learner)
  • Example:
from sklearn.ensemble import StackingClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.svm import SVC

model = StackingClassifier(
    estimators=[
        ('dt', DecisionTreeClassifier()),
        ('svc', SVC())
    ],
    final_estimator=LogisticRegression()
)
model.fit(X_train, y_train)
Raw lines 225 to 281
282## K-Nearest Neighbors
284**KNeighborsClassifier / KNeighborsRegressor**
285- Non-parametric method based on distance
286- Key parameters:
287 - `n_neighbors`: Number of neighbors (default=5)
288 - `weights`: 'uniform' or 'distance'
289 - `metric`: Distance metric ('euclidean', 'manhattan', etc.)
290- Use when: Small dataset, simple baseline needed
291- Slow prediction on large datasets
292- Example:
293```python
294from sklearn.neighbors import KNeighborsClassifier
296model = KNeighborsClassifier(n_neighbors=5, weights='distance')
297model.fit(X_train, y_train)
298```

K-Nearest Neighbors

KNeighborsClassifier / KNeighborsRegressor

  • Non-parametric method based on distance
  • Key parameters:
  • n_neighbors: Number of neighbors (default=5)
  • weights: 'uniform' or 'distance'
  • metric: Distance metric ('euclidean', 'manhattan', etc.)
  • Use when: Small dataset, simple baseline needed
  • Slow prediction on large datasets
  • Example:
from sklearn.neighbors import KNeighborsClassifier

model = KNeighborsClassifier(n_neighbors=5, weights='distance')
model.fit(X_train, y_train)
Raw lines 282 to 299
300## Naive Bayes
302**GaussianNB, MultinomialNB, BernoulliNB**
303- Probabilistic classifiers based on Bayes' theorem
304- Fast training and prediction
305- GaussianNB: Continuous features (assumes Gaussian distribution)
306- MultinomialNB: Count features (text classification)
307- BernoulliNB: Binary features
308- Use when: Text classification, fast baseline, probabilistic predictions
309- Example:
310```python
311from sklearn.naive_bayes import GaussianNB, MultinomialNB
313# For continuous features
314model_gaussian = GaussianNB()
316# For text/count data
317model_multinomial = MultinomialNB(alpha=1.0) # alpha is smoothing parameter
318model_multinomial.fit(X_train, y_train)
319```

Naive Bayes

GaussianNB, MultinomialNB, BernoulliNB

  • Probabilistic classifiers based on Bayes' theorem
  • Fast training and prediction
  • GaussianNB: Continuous features (assumes Gaussian distribution)
  • MultinomialNB: Count features (text classification)
  • BernoulliNB: Binary features
  • Use when: Text classification, fast baseline, probabilistic predictions
  • Example:
from sklearn.naive_bayes import GaussianNB, MultinomialNB

# For continuous features
model_gaussian = GaussianNB()

# For text/count data
model_multinomial = MultinomialNB(alpha=1.0)  # alpha is smoothing parameter
model_multinomial.fit(X_train, y_train)
Raw lines 300 to 320
321## Neural Networks
323**MLPClassifier / MLPRegressor**
324- Multi-layer perceptron (feedforward neural network)
325- Key parameters:
326 - `hidden_layer_sizes`: Tuple of hidden layer sizes, e.g., (100, 50)
327 - `activation`: 'relu', 'tanh', 'logistic'
328 - `solver`: 'adam', 'sgd', 'lbfgs'
329 - `alpha`: L2 regularization parameter
330 - `learning_rate`: 'constant', 'adaptive'
331- Use when: Complex non-linear patterns, large datasets
332- Requires feature scaling
333- Example:
334```python
335from sklearn.neural_network import MLPClassifier
336from sklearn.preprocessing import StandardScaler
338# Scale features first
339scaler = StandardScaler()
340X_train_scaled = scaler.fit_transform(X_train)
342model = MLPClassifier(
343 hidden_layer_sizes=(100, 50),
344 activation='relu',
345 solver='adam',
346 alpha=0.0001,
347 max_iter=1000
349model.fit(X_train_scaled, y_train)
350```

Neural Networks

MLPClassifier / MLPRegressor

  • Multi-layer perceptron (feedforward neural network)
  • Key parameters:
  • hidden_layer_sizes: Tuple of hidden layer sizes, e.g., (100, 50)
  • activation: 'relu', 'tanh', 'logistic'
  • solver: 'adam', 'sgd', 'lbfgs'
  • alpha: L2 regularization parameter
  • learning_rate: 'constant', 'adaptive'
  • Use when: Complex non-linear patterns, large datasets
  • Requires feature scaling
  • Example:
from sklearn.neural_network import MLPClassifier
from sklearn.preprocessing import StandardScaler

# Scale features first
scaler = StandardScaler()
X_train_scaled = scaler.fit_transform(X_train)

model = MLPClassifier(
    hidden_layer_sizes=(100, 50),
    activation='relu',
    solver='adam',
    alpha=0.0001,
    max_iter=1000
)
model.fit(X_train_scaled, y_train)
Raw lines 321 to 351
352## Algorithm Selection Guide

Algorithm Selection Guide

Raw lines 352 to 353
354### Choose based on:
356**Dataset size:**
357- Small (<1k samples): KNN, SVM, Decision Trees
358- Medium (1k-100k): Random Forest, Gradient Boosting, Linear Models
359- Large (>100k): SGD, Linear Models, HistGradientBoosting
361**Interpretability:**
362- High: Linear Models, Decision Trees
363- Medium: Random Forest (feature importance)
364- Low: SVM with RBF kernel, Neural Networks
366**Accuracy vs Speed:**
367- Fast training: Naive Bayes, Linear Models, KNN
368- High accuracy: Gradient Boosting, Random Forest, Stacking
369- Fast prediction: Linear Models, Naive Bayes
370- Slow prediction: KNN (on large datasets), SVM
372**Feature types:**
373- Continuous: Most algorithms work well
374- Categorical: Encode for ordinary trees/forests; HistGradientBoosting supports explicitly declared categoricals
375- Mixed: Use ColumnTransformer or correctly declared histogram-boosting categoricals
376- Text: Naive Bayes, Linear Models with TF-IDF
378**Common starting points:**
3791. Logistic Regression (classification) / Linear Regression (regression) - fast baseline
3802. Random Forest - good default choice
3813. Gradient Boosting - compare and tune within the same evaluation design

Choose based on:

Dataset size:

  • Small (<1k samples): KNN, SVM, Decision Trees
  • Medium (1k-100k): Random Forest, Gradient Boosting, Linear Models
  • Large (>100k): SGD, Linear Models, HistGradientBoosting

Interpretability:

  • High: Linear Models, Decision Trees
  • Medium: Random Forest (feature importance)
  • Low: SVM with RBF kernel, Neural Networks

Accuracy vs Speed:

  • Fast training: Naive Bayes, Linear Models, KNN
  • High accuracy: Gradient Boosting, Random Forest, Stacking
  • Fast prediction: Linear Models, Naive Bayes
  • Slow prediction: KNN (on large datasets), SVM

Feature types:

  • Continuous: Most algorithms work well
  • Categorical: Encode for ordinary trees/forests; HistGradientBoosting supports explicitly declared categoricals
  • Mixed: Use ColumnTransformer or correctly declared histogram-boosting categoricals
  • Text: Naive Bayes, Linear Models with TF-IDF

Common starting points:

  1. Logistic Regression (classification) / Linear Regression (regression) - fast baseline
  2. Random Forest - good default choice
  3. Gradient Boosting - compare and tune within the same evaluation design
Raw lines 354 to 382
383## Upstream references
385- https://scikit-learn.org/stable/modules/linear_model.html
386- https://scikit-learn.org/stable/modules/ensemble.html
387- https://scikit-learn.org/stable/auto_examples/inspection/plot_permutation_importance.html

Upstream references

  • https://scikit-learn.org/stable/modules/linear_model.html
  • https://scikit-learn.org/stable/modules/ensemble.html
  • https://scikit-learn.org/stable/auto_examples/inspection/plot_permutation_importance.html
Raw lines 383 to 387