Scikit-learn is an open-source Python library for classical machine learning on tabular data. It combines preprocessing, model building, evaluation, and reusable workflows behind a consistent API, making it useful for building a robust baseline before moving to more specialized approaches. section 4.0 section 4.1
Its classes use a common learning interface. An estimator learns from data with .fit; transformers map data with .transform; predictors return outcomes with .predict or probabilities with .predict_proba. Learned parameters and other fitted information are exposed as object attributes. section 4.1.1 section 4.1.2
A typical tabular-data workflow is:
- Create or load features and a target, then select preprocessing and a model. section 4.1
- Chain preprocessing and modeling in a Pipeline so the same steps can be reused. section 4.1 section 4.1.1
- Use cross-validation to evaluate performance before refitting the selected pipeline on all available data. section 4.1
- Keep training data separate from validation and test data when fitting and assessing models. section 4.1.2
Classification pipeline
A synthetic balanced classification dataset is standardized with StandardScaler, passed to LogisticRegression in a Pipeline, evaluated by cross-validation accuracy, and then refit when performance is suitable. The point is the repeatable procedure rather than the particular model. section 4.1
The library covers classification, regression, clustering, dimensionality reduction, preprocessing, and model selection. It accepts NumPy arrays and sparse matrices, and later support includes pandas DataFrames with retained column information and transformations in version 1.1.3 onward. section 4.1.1
GradientBoostingClassifier and GradientBoostingRegressor provide gradient boosting for classification and regression. Their decision-tree ensembles offer detailed parameter control, but training can take considerable time because decision trees are the training bottleneck. section 5.3
Listing 4.1 Example using Scikit-learn for a classification problem
import numpy as np
from sklearn.datasets import make_classification
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import cross_validate
from sklearn.pipeline import Pipeline
X, y = make_classification(n_features=32,
n_redundant=0,
n_informative=24,
random_state=1,
n_clusters_per_class=1
) #1
model = LogisticRegression() #2
pipeline = Pipeline(
[('processing', StandardScaler()),
('modeling', model)]) #3
cv_scores = cross_validate(estimator=pipeline,
X=X,
y=y,
scoring="accuracy",
cv=5) #4
mean_cv = np.mean(cv_scores['test_score'])
std_cv = np.std(cv_scores['test_score'])
print(f"accuracy: {mean_cv:0.3f} ({std_cv:0.3f})") #5
model.fit(X, y)
Inspect a complete minimal workflow that generates data, standardizes features, fits logistic regression, and cross-validates accuracy. section 4.1




