| name | supervised-learning |
| description | Build production-ready classification and regression models with hyperparameter tuning |
| version | 1.4.0 |
| sasmp_version | 1.4.0 |
| bonded_agent | 02-supervised-learning |
| bond_type | PRIMARY_BOND |
| parameters | {"required":[{"name":"X","type":"array","validation":"2D array, no NaN"},{"name":"y","type":"array","validation":"1D array, same length as X"}],"optional":[{"name":"task","type":"string","default":"classification","validation":"[classification|regression]"}]} |
| retry_logic | {"strategy":"exponential_backoff","max_attempts":3,"base_delay_ms":1000} |
| logging | {"level":"info","metrics":["training_time","cv_score","model_size"]} |
Supervised Learning Skill
Build, tune, and evaluate classification and regression models.
Quick Start
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import cross_val_score, 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
)
model = RandomForestClassifier(n_estimators=100, random_state=42)
model.fit(X_train, y_train)
cv_scores = cross_val_score(model, X_train, y_train, cv=5, scoring='f1_weighted')
print(f"CV F1: {cv_scores.mean():.4f} (+/- {cv_scores.std()*2:.4f})")
print(f"Test Accuracy: {model.score(X_test, y_test):.4f}")
Key Topics
1. Classification Algorithms
| Algorithm | Best For | Complexity |
|---|
| Logistic Regression | Baseline, interpretable | O(n*d) |
| Random Forest | Tabular, general | O(ndtrees) |
| XGBoost | Competitions, accuracy | O(ndtrees) |
| SVM | High-dim, small data | O(n²) |
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier
xgboost XGBClassifier
classifiers = {
: LogisticRegression(max_iter=, class_weight=),
: RandomForestClassifier(n_estimators=, class_weight=),
: XGBClassifier(n_estimators=, eval_metric=)
}