Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Sklearn Introduction

Sklearn Introduction

Sklearn, fully named Sklearn, is an open-source machine learning library based on Python.

Sklearn is a powerful and easy-to-use machine learning library that provides a complete set of tools from data preprocessing to model evaluation.

Sklearn is built on top of NumPy and SciPy, so it can efficiently handle numerical computation and array operations.

Sklearn is suitable for various machine learning tasks, such as classification, regression, clustering, and dimensionality reduction.

With its concise and consistent API, Sklearn has become an essential tool for machine learning enthusiasts and experts.


How Sklearn Works

In Sklearn, the machine learning workflow follows a certain pattern: data loading, data preprocessing, model training, model evaluation, and model tuning.

The specific workflow is as follows:


Characteristics of Sklearn

- **Classification algorithms**: such as logistic regression, support vector machine (SVM), K-nearest neighbors (KNN), random forest, etc. - **Regression algorithms**: such as linear regression, ridge regression, Lasso regression, etc. - **Clustering algorithms**: such as K-means, hierarchical clustering, DBSCAN, etc. - **Dimensionality reduction algorithms**: such as Principal Component Analysis (PCA), t-SNE, etc. - **Model selection and evaluation**: cross-validation, grid search, model evaluation metrics, etc.

Machine Learning Tasks Supported by Sklearn

Sklearn provides rich tools and supports the following categories of machine learning tasks:

- **Classification problems**: predict the category of data (e.g., email spam classification, image classification, disease prediction, etc.). - **Regression problems**: predict continuous values (e.g., house price prediction, stock price prediction, etc.). - **Clustering problems**: group data into different clusters (e.g., customer segmentation, document clustering, etc.). - **Dimensionality reduction problems**: project high-dimensional data onto a low-dimensional space to facilitate visualization or reduce computational complexity (e.g., PCA, t-SNE).


Common Modules and Classes in Sklearn

- `sklearn.linear_model.LogisticRegression`: logistic regression - `sklearn.svm.SVC`: support vector machine classification - `sklearn.neighbors.KNeighborsClassifier`: K-nearest neighbors classification - `sklearn.ensemble.RandomForestClassifier`: random forest classification - `sklearn.linear_model.LinearRegression`: linear regression - `sklearn.linear_model.Ridge`: ridge regression - `sklearn.ensemble.RandomForestRegressor`: random forest regression - `sklearn.cluster.KMeans`: K-means clustering - `sklearn.cluster.DBSCAN`: density-based spatial clustering - `sklearn.decomposition.PCA`: Principal Component Analysis (PCA) - `sklearn.decomposition.NMF`: Non-negative Matrix Factorization - `sklearn.model_selection.train_test_split`: split the dataset into training and test sets - `sklearn.model_selection.GridSearchCV`: grid search to find the best hyperparameters - `sklearn.preprocessing.StandardScaler`: standardization - `sklearn.preprocessing.MinMaxScaler`: min-max standardization - `sklearn.preprocessing.OneHotEncoder`: one-hot encoding

Explanation of Common Terms


Relationship Between Sklearn and Other Libraries