Log In

Don't have an account? Sign up now

Lost Password?

Sign Up

Prev Next

MODULE 16: Python for AI & Machine Learning

Python is the most popular language for AI & Machine Learning due to its simplicity, strong libraries, and large community support.

1. What is AI & ML?

Artificial Intelligence (AI)

AI refers to systems that can simulate human intelligence, such as:

  • Learning from data
  • Making decisions
  • Recognizing patterns
  • Understanding language

Examples

  • Chatbots
  • Face recognition
  • Recommendation systems

Machine Learning (ML)

ML is a subset of AI where systems learn from data without being explicitly programmed.

Real-World Examples

  • Spam email detection
  • Job recommendation engines
  • Salary prediction
  • Resume screening (ATS)

AI vs ML vs DL

ConceptMeaning
AIBroad concept of intelligent machines
MLLearning from data
DLNeural networks with multiple layers

2. Scikit-Learn Basics

Brief

Scikit-learn is the most widely used ML library in Python.


Key Features

  • Simple and consistent API
  • Built-in datasets
  • Multiple ML algorithms
  • Model evaluation tools

Install Scikit-Learn

pip install scikit-learn

Basic Imports

import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split

3. Supervised Learning

Brief

Supervised learning uses labeled data (input + output).


Types

  • Regression → Predict continuous values
  • Classification → Predict categories

Example Use Cases

  • Salary prediction
  • Email spam detection
  • Resume shortlisted or not

Simple Example (Classification)

from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier

data = load_iris()
X = data.data
y = data.target

model = DecisionTreeClassifier()
model.fit(X, y)

print(model.predict([[5.1, 3.5, 1.4, 0.2]]))

4. Unsupervised Learning

Brief

Unsupervised learning uses unlabeled data.


Common Algorithms

  • K-Means Clustering
  • Hierarchical Clustering
  • DBSCAN
  • PCA (Dimensionality Reduction)

Example: K-Means Clustering

from sklearn.cluster import KMeans

X = [[1, 2], [1, 4], [1, 0],
     [10, 2], [10, 4], [10, 0]]

model = KMeans(n_clusters=2)
model.fit(X)

print(model.labels_)

Real-World Use

  • Customer segmentation
  • Resume grouping
  • Market analysis

5. Model Training

Brief

Model training means teaching the model patterns from data.


Training Workflow

  1. Collect data
  2. Clean & preprocess
  3. Split data
  4. Train model
  5. Tune parameters

Train-Test Split

X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, random_state=42
)

Fit Model

model.fit(X_train, y_train)


6. Model Evaluation

Brief

Evaluating a model checks how well it performs on unseen data.


Common Metrics

  • Accuracy
  • Precision
  • Recall
  • F1-score
  • Confusion Matrix

Accuracy Example

from sklearn.metrics import accuracy_score

y_pred = model.predict(X_test)
print("Accuracy:", accuracy_score(y_test, y_pred))

Classification Report

from sklearn.metrics import classification_report

print(classification_report(y_test, y_pred))

Why Evaluation Matters

  • Prevents overfitting
  • Ensures real-world performance

7. Simple ML Projects

Project 1: Iris Flower Classification

  • Dataset: Iris
  • Algorithm: Decision Tree / KNN
  • Output: Flower type

Project 2: House Price Prediction

  • Algorithm: Linear Regression
  • Input: Area, rooms, location
  • Output: Price

Project 3: Student Performance Prediction

  • Input: Study hours
  • Output: Pass / Fail

Project 4: Resume Shortlisting (Basic)

  • Input: Skills count
  • Output: Shortlisted or not

Mini Project Code (Linear Regression)

from sklearn.linear_model import LinearRegression
import numpy as np

X = np.array([[1], [2], [3], [4]])
y = np.array([30000, 35000, 40000, 45000])

model = LinearRegression()
model.fit(X, y)

print(model.predict([[5]]))

Leave a Comment

    🚀 Join Common Jobs Pro — Referrals & Profile Visibility Join Now ×
    🔥