scikit learn

**Scikit-Learn (sklearn)** is the **most widely used Python library for classical machine learning** — providing a consistent, elegant API (fit/predict/transform) across every major algorithm (classification, regression, clustering, dimensionality reduction), comprehensive preprocessing tools (scaling, encoding, imputation), model selection utilities (cross-validation, grid search, train/test split), and pipeline infrastructure that chains preprocessing and modeling into reproducible workflows, serving as the essential foundation that every ML practitioner learns first. **What Is Scikit-Learn?** - **Definition**: An open-source Python library (pip install scikit-learn) built on NumPy, SciPy, and Matplotlib that provides simple and efficient tools for predictive data analysis — covering every classical ML algorithm with a unified, consistent API. - **The Design Philosophy**: Every estimator (model) has the same interface: `fit(X, y)` to train, `predict(X)` to predict, `score(X, y)` to evaluate, and `transform(X)` for preprocessing. This consistency means learning one algorithm teaches you the API for all algorithms. - **Why It Dominates**: Released in 2007, sklearn has the best documentation in the Python ecosystem, the most consistent API, and covers the full ML workflow from preprocessing to evaluation. It's the library every data scientist learns first. **Core Modules** | Module | Purpose | Key Classes | |--------|---------|-------------| | **Classification** | Predict discrete labels | LogisticRegression, RandomForestClassifier, SVC, GradientBoostingClassifier | | **Regression** | Predict continuous values | LinearRegression, Ridge, Lasso, SVR, RandomForestRegressor | | **Clustering** | Group unlabeled data | KMeans, DBSCAN, AgglomerativeClustering | | **Dimensionality Reduction** | Reduce feature space | PCA, TSNE, UMAP (via umap-learn) | | **Preprocessing** | Transform features | StandardScaler, MinMaxScaler, OneHotEncoder, LabelEncoder | | **Model Selection** | Evaluate and tune models | cross_val_score, GridSearchCV, RandomizedSearchCV, train_test_split | | **Metrics** | Score predictions | accuracy_score, f1_score, roc_auc_score, mean_squared_error | | **Pipeline** | Chain steps into workflows | Pipeline, ColumnTransformer, make_pipeline | | **Feature Selection** | Select informative features | SelectKBest, RFE, mutual_info_classif | | **Imputation** | Handle missing values | SimpleImputer, KNNImputer, IterativeImputer | **The Consistent API** ```python from sklearn.ensemble import RandomForestClassifier from sklearn.linear_model import LogisticRegression from sklearn.svm import SVC # Every model works identically: for Model in [RandomForestClassifier, LogisticRegression, SVC]: model = Model() model.fit(X_train, y_train) # Train predictions = model.predict(X_test) # Predict score = model.score(X_test, y_test) # Evaluate ``` **The Pipeline** ```python from sklearn.pipeline import Pipeline from sklearn.preprocessing import StandardScaler pipe = Pipeline([ ('scaler', StandardScaler()), ('model', RandomForestClassifier(n_estimators=100)) ]) pipe.fit(X_train, y_train) # Scaler fits + model trains pipe.predict(X_test) # Scaler transforms + model predicts ``` **Scikit-Learn is the foundation of practical machine learning in Python** — providing the consistent fit/predict/transform API, comprehensive algorithm coverage, and pipeline infrastructure that every ML practitioner depends on, with documentation so clear and an interface so elegant that it has become the standard that other ML libraries model their APIs after.

Go deeper with CFSGPT

Get AI-powered deep-dives, save terms, and run advanced simulations — free account.

Create Free Account