13 Fitting a Model
13.1 Fitting a model
13.2 Type of (supervised) models
13.2.1 Baseline
null_model() |> set_mode("classification")
null_model() |> set_mode("regression")
from sklearn.dummy import DummyClassifier, DummyRegressor
="most_common")
DummyClassifier(strategy="mean") DummyRegressor(strategy
13.2.2 Linear Regression
Regression
linear_reg()
Classification
logistic_reg()
Regression
from sklearn.linear_model import LinearRegression
LinearRegression()
Classification
from sklearn.linear_model import LogisticRegression
="none") LogisticRegression(penalty
13.2.3 Regularized Regression
Regression
linear_reg(penalty = 0.1, mixture = 0) |> set_mode("regression")
linear_reg(penalty = 0.1, mixture = 1) |> set_mode("regression")
linear_reg(penalty = 0.1, mixture = 0.5) |> set_mode("regression")
Classification
linear_reg(penalty = 0.1, mixture = 0) |> set_mode("classification")
linear_reg(penalty = 0.1, mixture = 1) |> set_mode("classification")
linear_reg(penalty = 0.1, mixture = 0.5) |> set_mode("classification")
Parameters alpha
(regularization strength) and C
are linked by the following relationship: \(\alpha = \frac{1}{2C}\).
Regression
from sklearn.linear_model import Ridge, Lasso, ElasticNet
=0.1) # ElasticNet(alpha=0.1, l1_ratio=0)
Ridge(alpha=0.1) # ElasticNet(alpha=0.1, l1_ratio=1)
Lasso(alpha=0.1, l1_ratio=0.5) ElasticNet(alpha
Classification
from sklearn.linear_model import RidgeClassifier, LogisticRegression
=0.1) # LogisticRegression(penalty="l2", C=5)
RidgeClassifier(alpha="l1", C=5)
LogisticRegression(penalty="elasticnet", C=5, l1_ratio=0.5) LogisticRegression(penalty
13.2.4 K-Nearest Neighbors
nearest_neighbor(neighbors = 5, dist_power = 2) |> set_mode("regression")
nearest_neighbor(neighbors = 5, dist_power = 2) |> set_mode("classification")
from sklearn.neighbors import KNeighborsRegressor, KNeighborsClassifier
=5, p=2)
KNeighborsRegressor(n_neighbors=5, p=2) KNeighborsClassifier(n_neighbors
13.2.5 Support Vector Machine
Regression
svm_linear(cost = 5, margin = 0.01) |> set_mode("regression")
svm_poly(cost = 5, degree = 3, margin = 0.01) |> set_mode("regression")
svm_rbf(cost = 5, rbf_sigma = 20, margin = 0.01) |> set_mode("regression")
Classification
svm_linear(cost = 5) |> set_mode("classification")
svm_poly(cost = 5, degree = 3) |> set_mode("classification")
svm_rbf(cost = 5, rbf_sigma = 20) |> set_mode("classification")
Regression
from sklearn.svm import LinearSVR, SVR
=5, epsilon=0.01)
LinearSVR(C="poly", C=5, degree=3, epsilon=0.01)
SVR(kernel="rbf", C=5, gamma=0.2, epsilon=0.01) SVR(kernel
Classification
from sklearn.svm import LinearSVC, SVC
=5)
LinearSVC(C="poly", C=5, degree=3)
SVC(kernel="rbf", C=5, gamma=0.2) SVC(kernel
13.2.6 Classification and Regression Trees
decision_tree() |> set_mode("regression")
decision_tree() |> set_mode("classification")
from sklearn.tree import DecisionTreeRegressor, DecisionTreeClassifier
DecisionTreeRegressor() DecisionTreeClassifier()
13.2.7 Random Forest
rand_forest() |> set_mode("regression")
rand_forest() |> set_mode("classification")
from sklearn.ensemble import RandomForestRegressor, RandomForestClassifier
RandomForestRegressor() RandomForestClassifier()
13.2.8 Bagging Trees
bag_tree() |> set_mode("regression")
bag_tree() |> set_mode("classification")
from sklearn.ensemble import BaggingRegressor, BaggingClassifier
from sklearn.tree import DecisionTreeRegressor, DecisionTreeClassifier
=DecisionTreeRegressor())
BaggingRegressor(base_estimator=DecisionTreeClassifier()) BaggingClassifier(base_estimator
13.2.9 Gradient Boosting Machine
boost_tree() |> set_mode("regression")
boost_tree() |> set_mode("classification")
from sklearn.ensemble import GradientBoostingRegressor, GradientBoostingClassifier
GradientBoostingRegressor() GradientBoostingClassifier()