0% found this document useful (0 votes)
2 views4 pages

Building Supervised Learning Models

This document provides a cheat sheet for building supervised learning models, detailing common models such as One vs One, One vs All, Decision Trees, Linear SVM, K-nearest neighbors, Random Forest, and XGBoost, along with their code syntax, pros, cons, and applications. It also includes associated functions for data preprocessing and evaluation, such as OneHotEncoder, accuracy_score, and roc_auc_score. The authors of the document are Jeff Grossman and Abhishek Gagneja.

Uploaded by

rahatdu23
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Building Supervised Learning Models

This document provides a cheat sheet for building supervised learning models, detailing common models such as One vs One, One vs All, Decision Trees, Linear SVM, K-nearest neighbors, Random Forest, and XGBoost, along with their code syntax, pros, cons, and applications. It also includes associated functions for data preprocessing and evaluation, such as OneHotEncoder, accuracy_score, and roc_auc_score. The authors of the document are Jeff Grossman and Abhishek Gagneja.

Uploaded by

rahatdu23
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

9/6/25, 7:53 PM about:blank

Cheat Sheet: Building Supervised Learning Models


Common supervised learning models

Process Name Brief Description Code Syntax

from [Link] import OneVsOneClassifier


Process: This method trains one classifier for from sklearn.linear_model import LogisticRegression
each pair of classes. model = OneVsOneClassifier(LogisticRegression())
Key hyperparameters:
- `estimator`: Base classifier (e.g., logistic
One vs One classifier regression)
(using logistic Pros: Can work well for small datasets.
regression) Cons: Computationally expensive for large
datasets.
Common applications: Multiclass classification
problems where the number of classes is
relatively small.

from [Link] import OneVsRestClassifier


from sklearn.linear_model import LogisticRegression
model = OneVsRestClassifier(LogisticRegression())

Process: Trains one classifier per class, where


each classifier distinguishes between one class
and the rest.
Key hyperparameters:
- `estimator`: Base classifier (e.g., Logistic
Regression)
One vs All classifier - `multi_class`: Strategy to handle multiclass
(using logistic classification (`ovr`) or
regression) Pros: Simpler and more scalable than One vs
One. from sklearn.linear_model import LogisticRegression
Cons: Less accurate for highly imbalanced model_ova = LogisticRegression(multi_class='ovr')
classes.
Common applications: Common in multiclass
classification problems such as image
classification.

from [Link] import DecisionTreeClassifier


model = DecisionTreeClassifier(max_depth=5)
Process: A tree-based classifier that splits data
into smaller subsets based on feature values.
Key hyperparameters:
- `max_depth`: Maximum depth of the tree
Decision tree classifier
Pros: Easy to interpret and visualize.
Cons: Prone to overfitting if not pruned properly.
Common applications: Classification tasks,
such as credit risk assessment.

from [Link] import DecisionTreeRegressor


Process: Similar to the decision tree classifier, model = DecisionTreeRegressor(max_depth=5)
but used for regression tasks to predict
continuous values.
Key hyperparameters:
- `max_depth`: Maximum depth of the tree
Decision tree regressor
Pros: Easy to interpret, handles nonlinear data.
Cons: Can overfit and perform poorly on noisy
data.
Common applications: Regression tasks, such
as predicting housing prices.

Linear SVM classifier Process: A linear classifier that finds the optimal from [Link] import SVC
hyperplane separating classes with a maximum model = SVC(kernel='linear', C=1.0)
margin.
Key hyperparameters:
- `C`: Regularization parameter
- `kernel`: Type of kernel function (`linear`,
`poly`, `rbf`, etc.)
- `gamma`: Kernel coefficient (only for `rbf`,
`poly`, etc.)
Pros: Effective for high-dimensional spaces.
Cons: Not ideal for nonlinear problems without

about:blank 1/4
9/6/25, 7:53 PM about:blank

Process Name Brief Description Code Syntax


kernel tricks.
Common applications: Text classification and
image recognition.

Process: Classifies data based on the majority


class of its nearest neighbors.
from [Link] import KNeighborsClassifier
Key hyperparameters: model = KNeighborsClassifier(n_neighbors=5, weights='uniform')
- `n_neighbors`: Number of neighbors to use
- `weights`: Weight function used in prediction
(`uniform` or `distance`)
K-nearest neighbors - `algorithm`: Algorithm used to compute the
classifier nearest neighbors (`auto`, `ball_tree`, `kd_tree`,
`brute`)
Pros: Simple and effective for small datasets.
Cons: Computationally expensive as the dataset
grows.
Common applications: Recommendation
systems, image recognition.

Process: An ensemble method using multiple


from [Link] import RandomForestRegressor
decision trees to improve accuracy and reduce model = RandomForestRegressor(n_estimators=100, max_depth=5)
overfitting.
Key hyperparameters:
- `n_estimators`: Number of trees in the forest
Random Forest - `max_depth`: Maximum depth of each tree
regressor Pros: Less prone to overfitting than individual
decision trees.
Cons: Model complexity increases with the
number of trees.
Common applications: Regression tasks such as
predicting sales or stock prices.

Process: A gradient boosting method that builds


trees sequentially to correct errors from previous import xgboost as xgb
trees. model = [Link](n_estimators=100, learning_rate=0.1, max_depth=5)
Key hyperparameters:
- `n_estimators`: Number of boosting rounds
- `learning_rate`: Step size to improve accuracy
XGBoost regressor - `max_depth`: Maximum depth of each tree
Pros: High accuracy and works well with large
datasets.
Cons: Computationally intensive, complex to
tune.
Common applications: Predictive modeling,
especially in Kaggle competitions.

Associated functions used

Method Name Brief Description Code Syntax

from [Link] import OneHotEncoder


encoder = OneHotEncoder(sparse=False)
encoded_data = encoder.fit_transform(categorical_data)

OneHotEncoder Transforms categorical features into a one-hot encoded matrix.

from [Link] import accuracy_score


accuracy = accuracy_score(y_true, y_pred)

Computes the accuracy of a classifier by comparing predicted


accuracy_score
and true labels.

LabelEncoder Encodes labels (target variable) into numeric format. from [Link] import LabelEncoder
encoder = LabelEncoder()
encoded_labels = encoder.fit_transform(labels)

about:blank 2/4
9/6/25, 7:53 PM about:blank

Method Name Brief Description Code Syntax

from [Link] import plot_tree


plot_tree(model, max_depth=3, filled=True)

plot_tree Plots a decision tree model for visualization.

from [Link] import normalize


normalized_data = normalize(data, norm='l2')

Scales each feature to have zero mean and unit variance


normalize
(standardization).

from [Link].class_weight import compute_sample_weight


weights = compute_sample_weight(class_weight='balanced', y=y)

compute_sample_weight Computes sample weights for imbalanced datasets.

from [Link] import roc_auc_score


auc = roc_auc_score(y_true, y_score)

Computes the Area Under the Receiver Operating


roc_auc_score Characteristic Curve (AUC-ROC) for binary classification
models.

Author
Jeff Grossman
Abhishek Gagneja

about:blank 3/4
9/6/25, 7:53 PM about:blank

about:blank 4/4

You might also like