Knowledge / Artificial Intelligence and Data Science / Machine learning workflow

Machine learning workflow

Artificial Intelligence and Data Science (B.E./B.Tech) · Machine learning · free study notes for exams, placements and interviews

In short

The machine learning workflow is the end-to-end sequence that turns a business question into a deployed, monitored model: frame the problem, collect and understand data, clean and engineer features, split data, train and tune candidate models, evaluate on held-out data, deploy, then monitor and retrain. It matters because most real failures are workflow failures (leakage, a wrong split, a drifted model) rather than algorithm failures. Universities examine it as the first unit of the ML course — CRISP-DM stages, train/validation/test design, k-fold cross-validation and the preprocessing-inside-the-pipeline rule — and GATE DA tests the quantitative parts (splits, fold counts, leakage reasoning). Every Indian campus interview (TCS Digital, Infosys, Wipro, Accenture, Mu Sigma, Fractal, ZS, Flipkart, Swiggy, Jio, HDFC, Paytm) opens with "walk me through how you would build a model end to end", so this topic is effectively the frame for the whole subject.

Explained

Standard lifecycle and the reference process models

Step 1–2: Problem framing and data understanding

Step 3: Data preparation

Step 4: Splitting, training and tuning

Step 5: Evaluation and error analysis

Step 6: Deployment, monitoring and MLOps

Key points

Formulas and examples

Split sizes: n_train = ⌈(1 − p_test) × n⌉, n_test = ⌊p_test × n⌋ — n = total rows, p_test = test fraction (dimensionless)
k-fold: fold size ≈ n/k; models trained = k; rows used for training per fold = n × (k − 1)/k
Grid-search fits = (∏ of grid sizes) × k (+1 final refit on full training data)
Standardisation: z = (x − μ_train)/σ_train — μ, σ in the feature's own units; z is dimensionless
Min–max: x' = (x − x_min)/(x_max − x_min) ∈ [0, 1]
IQR outlier bounds: [Q1 − 1.5 × IQR, Q3 + 1.5 × IQR], IQR = Q3 − Q1 (feature units)
CV estimate: mean = (1/k) Σ sᵢ ; s.d. = √[Σ(sᵢ − mean)² / (k − 1)] — sᵢ = score of fold i
Population Stability Index: PSI = Σ (a_i − e_i) × ln(a_i / e_i) — a_i, e_i = actual and expected proportions in bin i
SMOTE synthetic point: x_new = x_i + λ (x_nn − x_i), λ ~ U(0, 1) — x_nn is a minority-class neighbour

Example 1 — Split and fold arithmetic. A telecom churn dataset has 50,000 rows with 8% churners. Plan: 20% test, 5-fold CV on the remainder.

Example 2 — Grid-search cost and runtime. Tuning a random forest: n_estimators ∈ {100, 300, 500}, max_depth ∈ {5, 10, 20, None}, min_samples_leaf ∈ {1, 5}, with 5-fold CV.

Example 3 — Correct vs leaky scaling. Train ages: 20, 30, 40, 50, 60 → μ = 200/5 = 40, σ (population) = √[(400+100+0+100+400)/5] = √200 ≈ 14.14.

Example 4 — CV mean, spread and model choice. Accuracy over 5 folds — Model A: 0.84, 0.86, 0.85, 0.83, 0.87; Model B: 0.90, 0.78, 0.88, 0.76, 0.93.

Example 5 — Drift check with PSI. Expected (training) vs actual (last month) distribution of a credit-score band.

BandExpected eᵢActual aᵢaᵢ − eᵢln(aᵢ/eᵢ)Contribution
Low0.200.300.100.40550.0405
Medium0.500.45−0.05−0.10540.0053
High0.300.25−0.05−0.18230.0091
StageMain riskControl
Problem framingWrong target or metricWritten target definition, cost-based metric, baseline
Data preparationLeakage, lost rowsFit transforms on train only; impute with indicators
SplittingShuffled time series, grouped rows splitTimeSeriesSplit, GroupKFold, stratification
TuningOverfitting the validation setNested CV, fewer peeks, simpler grids
EvaluationOptimistic scoreUntouched test set, fold s.d., slice analysis
DeploymentTraining–serving skewShip the pipeline object, shared feature code
Post-deploymentSilent decayDrift metrics (PSI/KS), retraining triggers
from sklearn.compose import ColumnTransformer
from sklearn.pipeline import Pipeline
from sklearn.impute import SimpleImputer
from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import StratifiedKFold, GridSearchCV, train_test_split

X_tr, X_te, y_tr, y_te = train_test_split(
    X, y, test_size=0.2, stratify=y, random_state=42)      # test set sealed here

num = Pipeline([("imp", SimpleImputer(strategy="median")),
                ("sc", StandardScaler())])
cat = Pipeline([("imp", SimpleImputer(strategy="most_frequent")),
                ("oh", OneHotEncoder(handle_unknown="ignore"))])

pipe = Pipeline([
    ("prep", ColumnTransformer([("n", num, num_cols), ("c", cat, cat_cols)])),
    ("clf", LogisticRegression(max_iter=1000, class_weight="balanced"))])

cv = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)
gs = GridSearchCV(pipe, {"clf__C": [0.01, 0.1, 1, 10]},
                  scoring="roc_auc", cv=cv, n_jobs=-1)
gs.fit(X_tr, y_tr)                 # preprocessing refits inside every fold
print(gs.best_params_, gs.best_score_)
print("test AUC:", gs.score(X_te, y_te))   # touched once

Where it is used

Interview questions

Common mistakes

Related topics

Model evaluation metrics · Overfitting, bias-variance and regularisation · Feature selection and model interpretability · Linear and logistic regression · Ensemble methods and gradient boosting · Dimensionality reduction and PCA

Open in the Knowledge reader →Find jobs →