Skip to main content
MahiDev — Learn. Build. Become AI-ready.

Module 27

Scikit-learn

Train, evaluate, and tune regression, classification, and clustering models with scikit-learn, from train and test splits to pipelines and saved models.

Intermediate7 hours 30 min18 lessons

01

What Is Scikit-learn

Meet scikit-learn, the Python library for machine learning: every model is an estimator you create, fit on examples, and then ask to predict.

Intermediate25 min

02

Features and Labels

Split a table into X, the two-dimensional feature table, and y, the answer column, and learn why models need numbers, double brackets, and reshape.

Intermediate25 min

03

Training and Test Sets

Hold back rows the model never sees with train_test_split, repeat the split with random_state, keep class balance with stratify, and score honestly.

Intermediate25 min

04

Linear Regression

Predict a number with LinearRegression: fit a line, read coef_ and intercept_, add more features, and check the fit with the R squared score.

Intermediate25 min

05

Measuring Regression Error

Measure how far regression predictions miss with residuals, mean absolute error, RMSE, and R squared, and compare the model against a simple baseline.

Intermediate25 min

06

Logistic Regression

Predict a yes or no answer with LogisticRegression, read probabilities with predict_proba, pick your own threshold, and check accuracy on test rows.

Intermediate25 min

07

Measuring Classification

Go beyond accuracy with the confusion matrix, precision, recall, and F1, and see why a model that never says yes can still score high accuracy.

Intermediate25 min

08

K-Nearest Neighbours

Classify a learner by the votes of the most similar learners with KNeighborsClassifier, choose n_neighbors, and see why distance needs scale.

Intermediate25 min

09

Decision Trees

Build a DecisionTreeClassifier, read its questions with export_text, control memorising with max_depth, and see which features the tree relies on.

Intermediate25 min

10

Random Forests

Combine many decision trees with RandomForestClassifier, see how their votes beat a single tree, and tune n_estimators and max_depth for new data.

Intermediate25 min

11

Feature Scaling

Put features on comparable scales with StandardScaler and MinMaxScaler, fit the scaler on training rows only, and watch nearest neighbours recover.

Intermediate25 min

12

Encoding Categories

Turn text columns into numbers with OneHotEncoder and OrdinalEncoder, handle unseen categories safely, and feed the encoded columns to a model.

Intermediate25 min

13

Missing Values

Find gaps in a table, see why models refuse NaN, and fill them with SimpleImputer using the mean, median, or most frequent value per column.

Intermediate25 min

14

Pipelines

Chain preprocessing and a model into one object with Pipeline, handle numeric and text columns together with ColumnTransformer, and predict raw rows.

Intermediate25 min

15

Cross-Validation

Score a model on several different test folds with cross_val_score, KFold, and StratifiedKFold, and report a mean and spread instead of one lucky split.

Intermediate25 min

16

Hyperparameter Tuning

Tell learned parameters from settings you choose, search settings with GridSearchCV and cross-validation, and test the winning model exactly once.

Intermediate25 min

17

K-Means Clustering

Group rows without labels using KMeans, read the cluster centres and labels, choose the number of clusters with inertia, and describe each group.

Intermediate25 min

18

Saving and Loading Models

Save a trained model or pipeline with joblib or pickle, load it back to predict later, and store the details needed to use it safely afterwards.

Intermediate25 min