Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Scikit-learn model training skill with cross-validation, hyperparameter tuning, pipeline construction, and model serialization. Enables automated ML model development using scikit-learn's comprehensive toolkit.
.claude/skills/a5c-ai-sklearn-model-trainer/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-19 | ✗→✓ | ▲ Improved | 49% | 0% |
| case-16 | ✓→✗ | ▼ Worse | 127% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 60% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 55% | 0% |
| case-04 | ✓→✓ | = Same ✓ | 47% | 0% |
Train machine learning models using scikit-learn with cross-validation, hyperparameter tuning, and pipeline construction.
This skill provides comprehensive capabilities for training machine learning models using scikit-learn. It supports the full model development workflow from data preprocessing through model training, evaluation, and serialization.
bashpip install scikit-learn>=1.0.0 joblib pandas numpy
bash# For ONNX export pip install skl2onnx onnxruntime # For additional preprocessing pip install category_encoders imbalanced-learn
pythonfrom sklearn.ensemble import RandomForestClassifier from sklearn.model_selection import train_test_split, cross_val_score from sklearn.metrics import classification_report import joblib # Split data X_train, X_test, y_train, y_test = train_test_split( X, y, test_size=0.2, random_state=42, stratify=y ) # Train model model = RandomForestClassifier( n_estimators=100, max_depth=10, random_state=42 ) model.fit(X_train, y_train) # Cross-validation cv_scores = cross_val_score(model, X_train, y_train, cv=5, scoring='accuracy') print(f"CV Accuracy: {cv_scores.mean():.3f} (+/- {cv_scores.std() * 2:.3f})") # Evaluate y_pred = model.predict(X_test) print(classification_report(y_test, y_pred)) # Save model joblib.dump(model, 'model.joblib')
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 preprocessing numeric_features = ['age', 'income', 'score'] categorical_features = ['category', 'region'] numeric_transformer = Pipeline(steps=[ ('imputer', SimpleImputer(strategy='median')), ('scaler', StandardScaler()) ]) categorical_transformer = Pipeline(steps=[ ('imputer', SimpleImputer(strategy='constant', fill_value='missing')), ('onehot', OneHotEncoder(handle_unknown='ignore')) ]) preprocessor = ColumnTransformer( transformers=[ ('num', numeric_transformer, numeric_features), ('cat', categorical_transformer, categorical_features) ] ) # Create full pipeline pipeline = Pipeline(steps=[ ('preprocessor', preprocessor), ('classifier', GradientBoostingClassifier()) ]) # Train pipeline.fit(X_train, y_train)
pythonfrom sklearn.model_selection import GridSearchCV # Define parameter grid param_grid = { 'classifier__n_estimators': [50, 100, 200], 'classifier__max_depth': [3, 5, 10, None], 'classifier__learning_rate': [0.01, 0.1, 0.2] } # Grid search grid_search = GridSearchCV( pipeline, param_grid, cv=5, scoring='f1_weighted', n_jobs=-1, verbose=2 ) grid_search.fit(X_train, y_train) print(f"Best parameters: {grid_search.best_params_}") print(f"Best score: {grid_search.best_score_:.3f}") # Get best model best_model = grid_search.best_estimator_
pythonfrom sklearn.feature_selection import SelectFromModel, RFE from sklearn.ensemble import RandomForestClassifier # Method 1: SelectFromModel selector = SelectFromModel( RandomForestClassifier(n_estimators=100, random_state=42), threshold='median' ) X_selected = selector.fit_transform(X_train, y_train) # Method 2: Recursive Feature Elimination rfe = RFE( estimator=RandomForestClassifier(n_estimators=100, random_state=42), n_features_to_select=10, step=1 ) X_rfe = rfe.fit_transform(X_train, y_train) # Get selected features selected_features = X.columns[rfe.support_].tolist()
javascriptconst sklearnTrainingTask = defineTask({ name: 'sklearn-model-training', description: 'Train a scikit-learn model with cross-validation', inputs: { modelType: { type: 'string', required: true }, trainDataPath: { type: 'string', required: true }, targetColumn: { type: 'string', required: true }, hyperparameters: { type: 'object', default: {} }, cvFolds: { type: 'number', default: 5 }, scoringMetric: { type: 'string', default: 'accuracy' } }, outputs: { modelPath: { type: 'string' }, cvScores: { type: 'array' }, bestScore: { type: 'number' }, featureImportances: { type: 'object' } }, async run(inputs, taskCtx) { return { kind: 'skill', title: `Train ${inputs.modelType} model`, skill: { name: 'sklearn-model-trainer', context: { operation: 'train_with_cv', modelType: inputs.modelType, trainDataPath: inputs.trainDataPath, targetColumn: inputs.targetColumn, hyperparameters: inputs.hyperparameters, cvFolds: inputs.cvFolds, scoringMetric: inputs.scoringMetric } }, io: { inputJsonPath: `tasks/${taskCtx.effectId}/input.json`, outputJsonPath: `tasks/${taskCtx.effectId}/result.json` } }; } });
| Model | Use Case | Pros | Cons | |-------|----------|------|------| | LogisticRegression | Binary/multiclass, interpretable | Fast, interpretable | Linear boundary | | RandomForestClassifier | General purpose | Robust, handles nonlinearity | Can overfit | | GradientBoostingClassifier | High accuracy needed | State-of-art performance | Slower training | | SVC | Small/medium datasets | Effective in high dimensions | Slow on large data | | XGBClassifier | Competition/production | Fast, accurate | Many hyperparameters |
| Model | Use Case | Pros | Cons | |-------|----------|------|------| | LinearRegression | Baseline, interpretable | Simple, fast | Assumes linearity | | Ridge/Lasso | Regularization needed | Prevents overfitting | Still linear | | RandomForestRegressor | General purpose | Handles nonlinearity | Can overfit | | GradientBoostingRegressor | High accuracy | Excellent performance | Slower | | SVR | Small datasets | Robust to outliers | Slow scaling |
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→fail | 11,576 | 5,999 | -48% | 1 | 1 | 0% | 2,685 | 3,526 | +31% | 0 | 0 | — |
case-02 | pass→pass | 12,979 | 10,385 | -20% | 1 | 1 | 0% | 2,668 | 4,278 | +60% | 0 | 0 | — |
case-03 | pass→pass | 13,579 | 7,335 | -46% | 1 | 1 | 0% | 2,254 | 3,489 | +55% | 0 | 0 | — |
case-04 | pass→pass | 13,849 | 8,807 | -36% | 1 | 1 | 0% | 2,593 | 3,822 | +47% | 0 | 0 | — |
case-05 | pass→pass | 13,137 | 8,828 | -33% | 1 | 1 | 0% | 2,790 | 3,980 | +43% | 0 | 0 | — |
case-06 | pass→pass | 7,893 | 7,313 | -7% | 1 | 1 | 0% | 1,619 | 3,766 | +133% | 0 | 0 | — |
case-07 | pass→pass | 13,285 | 11,627 | -12% | 1 | 1 | 0% | 2,281 | 4,296 | +88% | 0 | 0 | — |
case-08 | pass→pass | 12,131 | 21,732 | +79% | 1 | 1 | 0% | 2,672 | 5,540 | +107% | 0 | 0 | — |
case-09 | pass→pass | 9,252 | 9,190 | -1% | 1 | 1 | 0% | 2,106 | 4,039 | +92% | 0 | 0 | — |
case-10 | pass→pass | 12,899 | 11,828 | -8% | 1 | 1 | 0% | 2,392 | 4,409 | +84% | 0 | 0 | — |
case-11 | fail→fail | 6,656 | 7,299 | +10% | 1 | 1 | 0% | 1,242 | 3,434 | +176% | 0 | 0 | — |
case-12 | pass→pass | 10,749 | 7,919 | -26% | 1 | 1 | 0% | 2,170 | 3,782 | +74% | 0 | 0 | — |
case-13 | pass→pass | 9,103 | 5,752 | -37% | 1 | 1 | 0% | 1,879 | 3,227 | +72% | 0 | 0 | — |
case-14 | pass→pass | 9,472 | 4,854 | -49% | 1 | 1 | 0% | 1,713 | 3,159 | +84% | 0 | 0 | — |
case-15 | pass→pass | 6,759 | 8,381 | +24% | 1 | 1 | 0% | 1,236 | 3,594 | +191% | 0 | 0 | — |
case-16 | pass→fail | 10,332 | 10,647 | +3% | 1 | 1 | 0% | 1,839 | 4,174 | +127% | 0 | 0 | — |
case-17 | pass→pass | 9,430 | 5,984 | -37% | 1 | 1 | 0% | 1,424 | 3,214 | +126% | 0 | 0 | — |
case-18 | pass→pass | 3,789 | 5,845 | +54% | 1 | 1 | 0% | 720 | 3,304 | +359% | 0 | 0 | — |
case-19 | fail→pass | 13,786 | 8,827 | -36% | 1 | 1 | 0% | 2,568 | 3,823 | +49% | 0 | 0 | — |
case-20 | pass→pass | 16,568 | 19,333 | +17% | 1 | 1 | 0% | 4,002 | 6,583 | +64% | 0 | 0 | — |
case-21 | pass→pass | 18,369 | 18,585 | +1% | 1 | 1 | 0% | 3,630 | 5,919 | +63% | 0 | 0 | — |
case-22 | pass→pass | 15,805 | 19,796 | +25% | 1 | 1 | 0% | 3,432 | 5,773 | +68% | 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. 22 cases were attempted. The headline lift of 0 percentage points is the difference between those two pass rates over the 22 comparable cases. 1 case got worse with the skill loaded, and it is included in that figure.
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.