Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Machine learning in Python with scikit-learn. Use when working with supervised learning (classification, regression), unsupervised learning (clustering, dimensionality reduction), model evaluation, hyperparameter tuning, preprocessing, or building ML pipelines. Provides comprehensive reference documentation for algorithms, preprocessing techniques, pipelines, and best practices.
.claude/skills/lingxling-scikit-learn/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-21 | ✗→✓ | ▲ Improved | 232% | 0% |
| case-01 | ✓→✓ | = Same ✓ | 1437% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 188% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 102% | 0% |
| case-04 | ✓→✓ | = Same ✓ | 216% | 0% |
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.
Tested against scikit-learn 1.8.0 (stable; December 2025). Requires Python 3.11–3.14 (free-threaded CPython 3.14 wheels available in 1.8+).
Install the PyPI package scikit-learn (not the deprecated sklearn package on PyPI). Import in code as sklearn.
bash# Install scikit-learn using uv uv pip install "scikit-learn>=1.7" # Optional: plotting utilities and bundled script dependencies uv pip install "scikit-learn[plots]" matplotlib seaborn # Commonly used with uv pip install pandas numpy
Check your version:
pythonimport sklearn print(sklearn.__version__)
Use the scikit-learn skill when:
pythonfrom sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler from sklearn.ensemble import RandomForestClassifier from sklearn.metrics import classification_report # Split data X_train, X_test, y_train, y_test = train_test_split( X, y, test_size=0.2, stratify=y, random_state=42 ) # Preprocess scaler = StandardScaler() X_train_scaled = scaler.fit_transform(X_train) X_test_scaled = scaler.transform(X_test) # Train model model = RandomForestClassifier(n_estimators=100, random_state=42) model.fit(X_train_scaled, y_train) # Evaluate y_pred = model.predict(X_test_scaled) print(classification_report(y_test, y_pred))
pythonfrom sklearn.pipeline import Pipeline from sklearn.compose import ColumnTransformer from sklearn.preprocessing import StandardScaler, OneHotEncoder from sklearn.impute import SimpleImputer from sklearn.ensemble import GradientBoostingClassifier # Define feature types numeric_features = ['age', 'income'] categorical_features = ['gender', 'occupation'] # Create preprocessing pipelines numeric_transformer = Pipeline([ ('imputer', SimpleImputer(strategy='median')), ('scaler', StandardScaler()) ]) categorical_transformer = Pipeline([ ('imputer', SimpleImputer(strategy='most_frequent')), ('onehot', OneHotEncoder(handle_unknown='ignore')) ]) # Combine transformers preprocessor = ColumnTransformer([ ('num', numeric_transformer, numeric_features), ('cat', categorical_transformer, categorical_features) ]) # Full pipeline model = Pipeline([ ('preprocessor', preprocessor), ('classifier', GradientBoostingClassifier(random_state=42)) ]) # Fit and predict model.fit(X_train, y_train) y_pred = model.predict(X_test)
Comprehensive algorithms for classification and regression tasks.
Key algorithms:
When to use:
See: references/supervised_learning.md for detailed algorithm documentation, parameters, and usage examples.
Discover patterns in unlabeled data through clustering and dimensionality reduction.
Clustering algorithms:
Dimensionality reduction:
umap-learn)When to use:
See: references/unsupervised_learning.md for detailed documentation.
Tools for robust model evaluation, cross-validation, and hyperparameter tuning.
Cross-validation strategies:
Hyperparameter tuning:
Metrics:
When to use:
See: references/model_evaluation.md for comprehensive metrics and tuning strategies.
Transform raw data into formats suitable for machine learning.
Scaling and normalization:
Encoding categorical variables:
Handling missing values:
Feature engineering:
When to use:
See: references/preprocessing.md for detailed preprocessing techniques.
Build reproducible, production-ready ML workflows.
Key components:
Benefits:
When to use:
See: references/pipelines_and_composition.md for comprehensive pipeline patterns.
Run a complete classification workflow with preprocessing, model comparison, hyperparameter tuning, and evaluation:
bashuv run python scripts/classification_pipeline.py
This script demonstrates:
Perform clustering analysis with algorithm comparison and visualization:
bashuv run python scripts/clustering_analysis.py
This script demonstrates:
This skill includes comprehensive reference files for deep dives into specific topics:
File: references/quick_reference.md
File: references/supervised_learning.md
File: references/unsupervised_learning.md
File: references/model_evaluation.md
File: references/preprocessing.md
File: references/pipelines_and_composition.md
python import pandas as pd df = pd.read_csv('data.csv') X = df.drop('target', axis=1) y = df['target']
python from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split( X, y, test_size=0.2, stratify=y, random_state=42 )
python from sklearn.pipeline import Pipeline from sklearn.preprocessing import StandardScaler from sklearn.compose import ColumnTransformer
# Handle numeric and categorical features separately preprocessor = ColumnTransformer( ('num', StandardScaler(), numeric_features), ('cat', OneHotEncoder(), categorical_features) ])
python model = Pipeline([ ('preprocessor', preprocessor), ('classifier', RandomForestClassifier(random_state=42)) ])
python from sklearn.model_selection import GridSearchCV
param_grid = { 'classifier__n_estimators': 100, 200], 'classifier__max_depth': 10, 20, None] }
grid_search = GridSearchCV(model, param_grid, cv=5) grid_search.fit(X_train, y_train)
python from sklearn.metrics import classification_report
best_model = grid_search.best_estimator_ y_pred = best_model.predict(X_test) print(classification_report(y_test, y_pred))
python from sklearn.preprocessing import StandardScaler
scaler = StandardScaler() X_scaled = scaler.fit_transform(X)
python from sklearn.cluster import KMeans from sklearn.metrics import silhouette_score
scores = ] for k in range(2, 11): kmeans = KMeans(n_clusters=k, random_state=42) labels = kmeans.fit_predict(X_scaled) scores.append(silhouette_score(X_scaled, labels))
optimal_k = range(2, 11)np.argmax(scores)]
python model = KMeans(n_clusters=optimal_k, random_state=42) labels = model.fit_predict(X_scaled)
python from sklearn.decomposition import PCA
pca = PCA(n_components=2) X_2d = pca.fit_transform(X_scaled)
plt.scatter(X_2d:, 0], X_2d:, 1], c=labels, cmap='viridis')
Pipelines prevent data leakage and ensure consistency:
python# Good: Preprocessing in pipeline pipeline = Pipeline([ ('scaler', StandardScaler()), ('model', LogisticRegression()) ]) # Bad: Preprocessing outside (can leak information) X_scaled = StandardScaler().fit_transform(X)
Never fit on test data:
python# Good scaler = StandardScaler() X_train_scaled = scaler.fit_transform(X_train) X_test_scaled = scaler.transform(X_test) # Only transform # Bad scaler = StandardScaler() X_all_scaled = scaler.fit_transform(np.vstack([X_train, X_test]))
Preserve class distribution:
pythonX_train, X_test, y_train, y_test = train_test_split( X, y, test_size=0.2, stratify=y, random_state=42 )
pythonmodel = RandomForestClassifier(n_estimators=100, random_state=42)
Algorithms requiring feature scaling:
Algorithms not requiring scaling:
Issue: Model didn't converge Solution: Increase max_iter or scale features
pythonmodel = LogisticRegression(max_iter=1000)
Issue: Overfitting Solution: Use regularization, cross-validation, or simpler model
python# Add regularization model = Ridge(alpha=1.0) # Use cross-validation scores = cross_val_score(model, X, y, cv=5)
Solution: Use algorithms designed for large data
python# Use SGD for large datasets from sklearn.linear_model import SGDClassifier model = SGDClassifier() # Or MiniBatchKMeans for clustering from sklearn.cluster import MiniBatchKMeans model = MiniBatchKMeans(n_clusters=8, batch_size=100)
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | pass→pass | 2,476 | 5,672 | +129% | 1 | 1 | 0% | 259 | 3,982 | +1437% | 0 | 0 | — |
case-02 | pass→pass | 12,012 | 5,561 | -54% | 1 | 1 | 0% | 1,650 | 4,756 | +188% | 0 | 0 | — |
case-03 | pass→pass | 17,213 | 12,551 | -27% | 1 | 1 | 0% | 3,120 | 6,313 | +102% | 0 | 0 | — |
case-04 | pass→pass | 8,480 | 6,979 | -18% | 1 | 1 | 0% | 1,617 | 5,104 | +216% | 0 | 0 | — |
case-05 | pass→pass | 7,235 | 6,320 | -13% | 1 | 1 | 0% | 1,505 | 4,948 | +229% | 0 | 0 | — |
case-06 | pass→pass | 7,603 | 8,048 | +6% | 1 | 1 | 0% | 1,541 | 4,950 | +221% | 0 | 0 | — |
case-07 | pass→pass | 12,824 | 12,070 | -6% | 1 | 1 | 0% | 2,392 | 5,992 | +151% | 0 | 0 | — |
case-08 | pass→pass | 10,871 | 9,448 | -13% | 1 | 1 | 0% | 1,751 | 5,359 | +206% | 0 | 0 | — |
case-09 | pass→pass | 9,463 | 10,155 | +7% | 1 | 1 | 0% | 1,728 | 5,159 | +199% | 0 | 0 | — |
case-10 | pass→pass | 13,006 | 15,511 | +19% | 1 | 1 | 0% | 2,329 | 6,271 | +169% | 0 | 0 | — |
case-11 | pass→pass | 9,527 | 8,793 | -8% | 1 | 1 | 0% | 1,812 | 5,063 | +179% | 0 | 0 | — |
case-12 | pass→pass | 14,782 | 8,865 | -40% | 1 | 1 | 0% | 2,321 | 5,694 | +145% | 0 | 0 | — |
case-13 | pass→pass | 9,025 | 8,253 | -9% | 1 | 1 | 0% | 1,536 | 5,283 | +244% | 0 | 0 | — |
case-14 | pass→pass | 13,535 | 14,363 | +6% | 1 | 1 | 0% | 2,210 | 6,078 | +175% | 0 | 0 | — |
case-15 | pass→pass | 14,720 | 15,958 | +8% | 1 | 1 | 0% | 2,166 | 6,340 | +193% | 0 | 0 | — |
case-16 | pass→pass | 12,644 | 8,095 | -36% | 1 | 1 | 0% | 1,994 | 5,255 | +164% | 0 | 0 | — |
case-17 | pass→pass | 18,885 | 14,050 | -26% | 1 | 1 | 0% | 2,704 | 6,441 | +138% | 0 | 0 | — |
case-18 | pass→pass | 13,733 | 16,787 | +22% | 1 | 1 | 0% | 2,582 | 6,600 | +156% | 0 | 0 | — |
case-19 | pass→pass | 14,984 | 14,837 | -1% | 1 | 1 | 0% | 2,457 | 6,059 | +147% | 0 | 0 | — |
case-20 | pass→pass | 15,511 | 16,204 | +4% | 1 | 1 | 0% | 3,259 | 6,247 | +92% | 0 | 0 | — |
case-21 | fail→pass | 15,591 | 26,481 | +70% | 1 | 1 | 0% | 2,418 | 8,033 | +232% | 0 | 0 | — |
case-22 | pass→pass | 18,711 | 15,911 | -15% | 1 | 1 | 0% | 2,928 | 6,888 | +135% | 0 | 0 | — |
case-23 | pass→pass | 12,255 | 12,073 | -1% | 1 | 1 | 0% | 2,389 | 6,051 | +153% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 23 cases were attempted. The headline lift of +4 percentage points is the difference between those two pass rates over the 23 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.