Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. Master Data Science with Python

Lesson 46 of 60 · python

Introduction to Machine Learning with Scikit‑learn

Duration: 20 minutes

Machine Learning Overview

Scikit‑learn (sklearn) is the most popular library for classical machine learning in Python.

Installing scikit‑learn

pip install scikit-learn

Typical ML workflow

  1. Define problem (regression, classification, clustering).
  2. Load & preprocess data (cleaning, scaling, encoding).
  3. Split into training and test sets.
  4. Select a model (e.g., LinearRegression).
  5. Train (model.fit).
  6. Evaluate (metrics).
  7. Tune hyperparameters.
  8. Deploy.

Example: Simple Linear Regression

from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error

X = df[['feature1', 'feature2']]
y = df['target']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

model = LinearRegression()
model.fit(X_train, y_train)

preds = model.predict(X_test)
rmse = mean_squared_error(y_test, preds, squared=False)
print('RMSE:', rmse)

Key concepts

  • Estimator: any object with a fit method.
  • Transformer: implements fit and transform (e.g., StandardScaler).
  • Pipeline: chains transformers and an estimator.

Info

Scikit‑learn follows the "fit‑transform‑predict" API uniformly across models.

Previous: Encoding Categorical Variables for Machine LearningNext: Supervised Learning – Linear Regression