| name | scikit-learn |
| description | Machine learning library. Use when building predictive models, classification, regression, or clustering. |
Scikit-learn
Machine learning in Python.
Quick Start
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_squared_error, r2_score
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
model = RandomForestRegressor(n_estimators=100)
model.fit(X_train, y_train)
predictions = model.predict(X_test)
Key Models
# Regression
from sklearn.linear_model import Ridge, Lasso
from sklearn.ensemble import GradientBoostingRegressor
# Classification
from sklearn.ensemble import RandomForestClassifier
from sklearn.svm import SVC
# Clustering
from sklearn.cluster import KMeans
Preprocessing
from sklearn.preprocessing import StandardScaler, MinMaxScaler
from sklearn.pipeline import Pipeline
pipeline = Pipeline([
('scaler', StandardScaler()),
('model', RandomForestRegressor())
])
pipeline.fit(X_train, y_train)
Cross-validation
from sklearn.model_selection import cross_val_score
scores = cross_val_score(model, X, y, cv=5, scoring='r2')