Skill

Build ML Models with Scikit-learn

A skill for classical ML with scikit-learn - classification, clustering, preprocessing, pipelines, and hyperparameter tuning.

Works with scikit learnpandasnumpymatplotlibseaborn

72
Spark score
out of 100
Updated last month
Version 13.4.0

Add to Favorites

Why it matters

Leverage scikit-learn, the industry-standard Python library, to build robust machine learning models for classification, regression, clustering, and more. This skill provides comprehensive guidance for data preprocessing, model evaluation, and creating production-ready ML pipelines.

Outcomes

What it gets done

01

Implement classification and regression models

02

Perform data preprocessing and feature engineering

03

Evaluate model performance and tune hyperparameters

04

Construct end-to-end ML pipelines

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/ag-scikit-learn | bash

Overview

Scikit-learn

Scikit-learn provides comprehensive guidance for classical machine learning - supervised/unsupervised algorithms, model evaluation and hyperparameter tuning, preprocessing, and production-ready Pipeline/ColumnTransformer composition - with bundled classification and clustering example scripts. Use it for classification, regression, clustering, dimensionality reduction, or preprocessing on structured/tabular data; not for large-scale GPU-accelerated deep learning, which needs a different framework.

What it does

Scikit-learn is a skill providing comprehensive guidance for classical machine learning with the industry-standard Python library - classification, regression, clustering, dimensionality reduction, preprocessing, model evaluation, and production-ready ML pipelines. Installation is via uv pip install scikit-learn, with matplotlib/seaborn for visualization and pandas/numpy commonly paired alongside it.

Supervised learning covers linear models (Logistic/Linear Regression, Ridge, Lasso, ElasticNet), tree-based methods (Decision Trees, Random Forest, Gradient Boosting), Support Vector Machines with various kernels, ensemble methods (AdaBoost, Voting, Stacking), neural networks (MLPClassifier/MLPRegressor), and Naive Bayes/KNN - for classification (discrete categories like spam or fraud detection) and regression (continuous values like price or demand). Unsupervised learning covers clustering (K-Means, MiniBatchKMeans, DBSCAN, HDBSCAN, OPTICS, AgglomerativeClustering, Gaussian Mixture, MeanShift, SpectralClustering, BIRCH) and dimensionality reduction (PCA, TruncatedSVD, NMF for linear methods; t-SNE, UMAP, Isomap, LLE for manifold learning; FastICA and LDA for feature extraction), used for customer segmentation, anomaly detection, visualization, and topic modeling.

Model evaluation and selection covers cross-validation strategies (KFold, StratifiedKFold, TimeSeriesSplit for temporal data, GroupKFold for grouped samples), hyperparameter tuning (GridSearchCV, RandomizedSearchCV, HalvingGridSearchCV), and metrics by task - classification (accuracy, precision, recall, F1, ROC AUC, confusion matrix), regression (MSE, RMSE, MAE, R², MAPE), and clustering (silhouette score, Calinski-Harabasz, Davies-Bouldin). Data preprocessing covers scaling (StandardScaler, MinMaxScaler, RobustScaler, Normalizer), categorical encoding (OneHotEncoder, OrdinalEncoder, LabelEncoder), missing value handling (SimpleImputer, KNNImputer, IterativeImputer), and feature engineering (PolynomialFeatures, KBinsDiscretizer, RFE/SelectKBest/SelectFromModel for feature selection).

Production workflow guidance centers on Pipeline/ColumnTransformer/FeatureUnion/TransformedTargetRegressor composition - chaining transformers and estimators, applying different preprocessing per column type, and combining transformers in parallel - which prevents data leakage during cross-validation, simplifies maintenance, enables joint hyperparameter tuning across preprocessing and model steps, and ensures training/prediction consistency. Two bundled example scripts run complete workflows end to end: classification_pipeline.py (mixed data type handling, cross-validated model comparison, GridSearchCV tuning, multi-metric evaluation, feature importance) and clustering_analysis.py (optimal cluster count via elbow method and silhouette analysis, comparing K-Means/DBSCAN/Agglomerative/Gaussian Mixture, PCA-projected visualization). Reference documentation is organized into quick_reference, supervised_learning, unsupervised_learning, model_evaluation, preprocessing, and pipelines_and_composition files for deep dives.

When to use - and when NOT to

Use this skill when building classification or regression models, performing clustering or dimensionality reduction, preprocessing data for ML, evaluating model performance with cross-validation, tuning hyperparameters, building production ML pipelines, comparing algorithms, or needing interpretable classical ML on structured/tabular data.

Do not use it for deep learning tasks requiring GPU-accelerated neural network training at scale - scikit-learn's MLP implementations are CPU-based and suited to smaller networks; for large-scale deep learning, a framework like PyTorch or TensorFlow is the right tool instead.

Inputs and outputs

Input: labeled or unlabeled tabular (or text) data for a classification, regression, clustering, or dimensionality-reduction task.

Output: a trained model or pipeline, for example a complete mixed-data classification pipeline:

numeric_transformer = Pipeline([
    ('imputer', SimpleImputer(strategy='median')),
    ('scaler', StandardScaler())
])

categorical_transformer = Pipeline([
    ('imputer', SimpleImputer(strategy='most_frequent')),
    ('onehot', OneHotEncoder(handle_unknown='ignore'))
])

preprocessor = ColumnTransformer([
    ('num', numeric_transformer, numeric_features),
    ('cat', categorical_transformer, categorical_features)
])

model = Pipeline([
    ('preprocessor', preprocessor),
    ('classifier', GradientBoostingClassifier(random_state=42))
])

model.fit(X_train, y_train)
y_pred = model.predict(X_test)

Along with this it produces cross-validation results, hyperparameter search results, and clustering/dimensionality-reduction analysis with visualizations.

Who it's for

Data scientists and ML engineers working with structured/tabular data who need comprehensive, production-oriented scikit-learn guidance rather than piecing together preprocessing, modeling, and evaluation code from scattered documentation.

Source README

This skill provides comprehensive guidance for machine learning tasks using scikit-learn, the industry-standard Python library for classical machine learning. Use this skill for classification, regression, clustering, dimensionality reduction, preprocessing, model evaluation, and building production-ready ML pipelines.

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.