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

Cheat Sheet Linear and Logistic Regression

This document provides a cheat sheet comparing different types of regression models including simple linear, polynomial, multiple linear, and logistic regression, detailing their purposes, pros and cons, and code syntax. It also lists associated functions commonly used in model evaluation, such as train_test_split, log_loss, mean_absolute_error, mean_squared_error, root_mean_squared_error, and r2_score. The authors of the document are Jeff Grossman and Abhishek Gagneja.
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 views2 pages

Cheat Sheet Linear and Logistic Regression

This document provides a cheat sheet comparing different types of regression models including simple linear, polynomial, multiple linear, and logistic regression, detailing their purposes, pros and cons, and code syntax. It also lists associated functions commonly used in model evaluation, such as train_test_split, log_loss, mean_absolute_error, mean_squared_error, root_mean_squared_error, and r2_score. The authors of the document are Jeff Grossman and Abhishek Gagneja.
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
You are on page 1/ 2

6/25/25, 8:48 PM about:blank

Cheat Sheet: Linear and Logistic Regression


Comparing different regression types

Model Name Description Code Syntax

from sklearn.linear_model import LinearRegression


model = LinearRegression()
model.fit(X, y)
Purpose: To predict a dependent variable based on one
independent variable.
Pros: Easy to implement, interpret, and efficient for small
Simple linear datasets.
regression Cons: Not suitable for complex relationships; prone to
underfitting.
Modeling equation: y = b0 + b1x

from sklearn.preprocessing import PolynomialFeatures


from sklearn.linear_model import LinearRegression
poly = PolynomialFeatures(degree=2)
X_poly = poly.fit_transform(X)
model = LinearRegression().fit(X_poly, y)
Purpose: To capture nonlinear relationships between variables.
Pros: Better at fitting nonlinear data compared to linear
Polynomial regression.
regression Cons: Prone to overfitting with high-degree polynomials.
Modeling equation: y = b0 + b1x + b2x2 + ...

from sklearn.linear_model import LinearRegression


model = LinearRegression()
model.fit(X, y)
Purpose: To predict a dependent variable based on multiple
independent variables.
Multiple linear Pros: Accounts for multiple factors influencing the outcome.
regression Cons: Assumes a linear relationship between predictors and
target.
Modeling equation: y = b0 + b1x1 + b2x2 + ...

from sklearn.linear_model import LogisticRegression


model = LogisticRegression()
model.fit(X, y)

Purpose: To predict probabilities of categorical outcomes.


Pros: Efficient for binary classification problems.
Logistic regression Cons: Assumes a linear relationship between independent
variables and log-odds.
Modeling equation: log(p/(1-p)) = b0 + b1x1 + ...

Associated functions commonly used

Brief
Function/Method Name Code Syntax
Description

from sklearn.model_selection import train_test_split


X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
Splits the
dataset into
training and
train_test_split testing subsets
to evaluate the
model's
performance.

StandardScaler Standardizes from sklearn.preprocessing import StandardScaler


features by scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)
removing the
mean and
scaling to unit
variance.

about:blank 1/2
6/25/25, 8:48 PM about:blank

Brief
Function/Method Name Code Syntax
Description

from sklearn.metrics import log_loss


loss = log_loss(y_true, y_pred_proba)

Calculates the
logarithmic loss,
a performance
log_loss
metric for
classification
models.

from sklearn.metrics import mean_absolute_error


mae = mean_absolute_error(y_true, y_pred)

Calculates the
mean absolute
error between
mean_absolute_error
actual and
predicted
values.

from sklearn.metrics import mean_squared_error


mse = mean_squared_error(y_true, y_pred)

Computes the
mean squared
error between
mean_squared_error
actual and
predicted
values.

from sklearn.metrics import mean_squared_error


import numpy as np
rmse = np.sqrt(mean_squared_error(y_true, y_pred))
Calculates the
root mean
squared error
root_mean_squared_error (RMSE), a
commonly used
metric for
regression tasks.

from sklearn.metrics import r2_score


r2 = r2_score(y_true, y_pred)
Computes the
R-squared
value, indicating
how well the
r2_score
model explains
the variability of
the target
variable.

Author(s)
Jeff Grossman
Abhishek Gagneja

about:blank 2/2

You might also like