[go: up one dir, main page]

0% found this document useful (0 votes)
10 views11 pages

Sklearn Quick Reference

This document serves as a quick reference for key modules and APIs in the sklearn library, outlining various functionalities such as feature selection, model training, and evaluation metrics. It includes lists of important modules, commonly used machine learning models, metrics, and data preprocessing techniques. The document emphasizes that it is not a substitute for the official sklearn documentation and provides guidance on accessing module information in Google Colab.

Uploaded by

om.narayan.ug21
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)
10 views11 pages

Sklearn Quick Reference

This document serves as a quick reference for key modules and APIs in the sklearn library, outlining various functionalities such as feature selection, model training, and evaluation metrics. It includes lists of important modules, commonly used machine learning models, metrics, and data preprocessing techniques. The document emphasizes that it is not a substitute for the official sklearn documentation and provides guidance on accessing module information in Google Colab.

Uploaded by

om.narayan.ug21
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/ 11

Note:

1. This document is to help you as a quick reference for sklearn modules and APIs.

2. In no way it attempts to replace/substitute sklearn documentation.

3. It is not a complete or exhaustive list of sklearn modules and APIs.

List of some important sklearn modules


Module Name Brief Description

This module implements feature selection algorithms. It


sklearn.feature_extraction currently includes univariate filter selection methods and the
recursive feature elimination algorithm.

This module implements feature selection algorithms. It


sklearn.feature_selection currently includes univariate filter selection methods and the
recursive feature elimination algorithm.

sklearn.impute Transformers for missing value imputation

sklearn.linear_model This module implements a variety of linear models.

This module includes score functions, performance metrics and


sklearn.metrics
pairwise metrics and distance computations.

This module implements various cross validation and HPT


sklearn.model_selection
techniques.

sklearn.naive_bayes This module implements Naive Bayes algorithms

sklearn.neighbors This module implements the k-nearest neighbors algorithm.

sklearn.neural_network This module includes models based on neural networks.

This module implements utilities to build a composite


sklearn.pipeline
estimator, as a chain of transforms and estimators.

This module includes scaling, centering, normalization,


sklearn.preprocessing
binarization methods.

sklearn.svm This module includes Support Vector Machine algorithms.

This module includes decision tree-based models for


sklearn.tree
classification and regression.

This module includes ensemble-based methods for


sklearn.ensemble
classification, regression and anomaly detection.

Models
Following is the list of most commonly used ML models:
Category Library module API

DummyRegressor
Baseline model sklearn.dummy
DummyClassifier

Linear Regression sklearn.linear_model LinearRegression

Generic Regression/classification SGDRegressor


sklearn.linear_model
model SGDClassifier

Ridge
Ridge regression/Classification sklearn.linear_model
Ridge Classifier

Lasso regression sklearn.linear_model Lasso

RidgeCV sklearn.linear_model RidgeCV

LassoCV sklearn.linear_model LassoCV

Perceptron classifier sklearn.linear_model Perceptron

Logistic Regression sklearn.linear_model LogisticRegression

Logistic Regression CV sklearn.linear_model LogisticRegressionCV

BernoulliNB
Naïve Bayes sklearn.naïve_bayes MultinomialNB
Categorical NB

Naïve Bayes sklearn.naïve_bayes GaussianNB

KneighborsClassifier
Nearest Neighbours sklearn.neighbors
KneighborsRegressor

RadiusNeighborsClassifier
Nearest Neighbours sklearn.neighbors
RadiusNeighborsRegressor

LinearSVC
Support Vector Machines sklearn.svm
LinearSVR

SVC
Support Vector Machines sklearn.svm
SVR

NuSVC
Support Vector Machines sklearn.svm
NuSVR
DecisionTreeRegressor
Decision Trees sklearn.tree
DecisionTreeClassifier

Decision Trees sklearn.tree plot_tree

VotingRegressor
Voting models sklearn.ensemble
VotingClassifier

BaggingRegressor
Bagging models sklearn.ensemble
BaggingClassifier

RandomForestRegressor
Random Forest sklearn.ensemble
RandomForestClassifier

AdaBoostRegressor
Adaptive Boosting sklearn.ensemble
AdaBoostClassifier

GradientBoostingRegressor
Gradient Boosting sklearn.ensemble
GradientBoostingClassifier

Clustering sklearn.cluster KMeans

Clustering sklearn.cluster Agglomerative Clustering

MLPRegressor
Artificial Neural Networks sklearn.neural_network
MLPClassifier

Hyper-parameter tuning sklearn.model_selection GridSearchCV

Hyper-parameter tuning sklearn.model_selection RandomizedSearchCV

Meta estimators sklearn.multiclass OneVsRestClassifier

Meta estimators sklearn.multiclass OneVsOneClassifier

Meta estimators sklearn.multiclass OutputCodeClassifier

MultiOutputClassifier
Meta estimators sklearn.multioutput
MultiOutputRegressor

ClassifierChain
Meta estimators sklearn.multioutput
RegressorChain

Metrics
Following is the list of most commonly used ML metrics APIs:

Broad category API


from sklearn.metrics import accuracy_score
Classification sklearn.metrics.accuracy_score

Classification sklearn.metrics.precision_score

Classification sklearn.metrics.recall_score

Classification sklearn.metrics.f1_score

Classification sklearn.metrics.classification_report

Classification sklearn.metrics.confusion_matrix

Classification sklearn.metrics.precision_recall_curve

Classification sklearn.metrics.roc_curve

Classification sklearn.metrics.ConfusionMatrixDisplay

Classification sklearn.metrics.PrecisionRecallDisplay

Classification sklearn.metrics.RocCurveDisplay

Regression sklearn.metrics.explained_variance

Regression sklearn.metrics.r2_score

Regression sklearn.metrics.mean_absolute_error

Regression sklearn.metrics.mean_squared_error

Regression sklearn.metrics.mean_squared_log_error

Regression sklearn.metrics.mean_absolute_percentage_error

Classification sklearn.metrics.hinge_loss

Classification sklearn.metrics.log_loss

Classification sklearn.metrics.balanced_accuracy_score

Classification sklearn.metrics.roc_auc_score

Classification sklearn.metrics.top_k_accuracy_score
Data Preprocessing, feature selection and
model selection
Following is the list of most commonly used data preprocessing, feature selectiona nd model
selection APIs:
Broad
Sub category Library module API
category

Data pre- Training and


sklearn.model_selection train_test_split
processing test

Data pre- Feature


sklearn.feature_extraction DictVectorizer
processing extraction

Data pre- Handling


sklearn.impute SimpleImputer
processing missing values

Data pre- Handling


sklearn.impute KNNImputer
processing missing values

Data pre- Feature


sklearn.impute MissingIndicator
processing extraction

Data pre- Feature


sklearn.preprocessing StandardScaler
processing scaling

Data pre- Feature


sklearn.preprocessing MinMaxScaler
processing scaling

Data pre- Feature


sklearn.preprocessing MaxAbsScaler
processing scaling

Data pre- Feature


sklearn.preprocessing OneHotEncoder
processing encoding

Data pre- Feature


sklearn.preprocessing LabelEncoder
processing encoding

Data pre- Feature


sklearn.preprocessing OrdinalEncoder
processing encoding

Data pre- Feature


sklearn.preprocessing LabelBinarizer
processing encoding

Data pre- Feature


sklearn.preprocessing MultiLabelBinarizer
processing encoding

Data pre-
Preprocessing sklearn.preprocessing add_dummy_feature
processing
Broad
Sub category Library module API
category

Feature Filter feature


sklearn.feature_selection VarianceThreshold
Selection selection

Feature Filter feature


sklearn.feature_selection SelectKBest
Selection selection

Feature Filter feature


sklearn.feature_selection SelectPercentile
Selection selection

Feature Filter feature


sklearn.feature_selection GenericUnivariateSelect
Selection selection

Wrapper
Feature
feature sklearn.feature_selection RFE
Selection
selection

Wrapper
Feature
feature sklearn.feature_selection RFECV
Selection
selection

Wrapper
Feature
feature sklearn.feature_selection SelectFromModel
Selection
selection

Wrapper
Feature
feature sklearn.feature_selection SequentialFeatureSelector
Selection
selection

Data pre- Dimensionality


sklearn.decomposition PCA
processing reduction

Data pre- Feature


sklearn.preprocessing FunctionTransformer
processing transformation

Data pre- Feature


sklearn.preprocessing PolynomialFeatures
processing transformation

Data pre- Feature


sklearn.preprocessing KBinsDiscretizer
processing transformation

Data pre- Feature


sklearn.compose ColumnTransformer
processing transformation
Broad
Sub category Library module API
category

Data pre- Feature


sklearn.compose TransformedTargetRegressor
processing transformation

Data pre- Chaining


sklearn.pipeline Pipeline
processing transformers

Data pre- Chaining


sklearn.pipeline FeatureUnion
processing transformers

Model Cross
sklearn.model_selection KFold
Selection validation

Model Cross
sklearn.model_selection LeaveOneOut
Selection validation

Model Cross
sklearn.model_selection ShuffleSplit
Selection validation

Model Cross
sklearn.model_selection cross_val_score
Selection validation

Model Cross
sklearn.model_selection cross_validate
Selection validation

Model Cross
sklearn.model_selection learning_curve
Selection validation

Model Cross
sklearn.model_selection validation_curve
Selection validation

Target Target
sklearn.utils.multiclass type_of_target
identification identification

Accessing sklearn modules and APIs


documentation in Google Colab
1. In a Google colab document, import the module of interest. e.g. sklearn , as following:

2. import sklearn
3. Type sklearn. (notice the dot . after module name) and press Ctrl + Space Bar
together. A pop up will show up as in the following image:

as you can see in the above image, a scrollable list of all sub modules is presented.

4. Let's say you want to see APIs in the impute module. Then follow the same procedure as
above, you will see a pop up like following:

5. Now, say you want to know more about SimpleImputer and want to see what it does, its
signature, info on its parameters and possibly some examples, then use ? operator as
following

from sklearn.impute import SimpleImputer


?SimpleImputer
6. A scrollable panel will open like following:

7. Instead of ? operator you can use help() like following:

from sklearn.impute import SimpleImputer


help(SimpleImputer)

8. Instead of showing same documentation of SimpleImputer API in a separate panel, it


will be shown as output of the code cell, as shown below:

You might also like