Posts

Machine Learning Lab PCCSL508 Semester 5 KTU CS 2024 Scheme - Dr Binu V P

About Me - Dr Binu V P Syllabus Learn Python well before You start(focus on numpy,pandas,matplotlib )- refer blog Build a strong understanding of the theory before moving on to programming Recommended Tools and Setup for Lab Experiments Regression  Explore Californoa Housing Dataset(learn pandas,scikit-learn and matplotlib) Simple Linear Regression using Sample Data ( Single variable, Toy Example) Simple Linear Regression using Gradient Descent ( Single variable, Toy Example). Simple Linear regression using California Housing Dataset(CSV input). Simple Linear Regression Using California Housing Dataset (using scikit-learn). Simple Linear regression using Gradient Descent on California Housing Dataset. Multiple Linear Regression using using Matrix Form ( Toy Dataset). Multivariate Linear Regression using Gradient Descent (Toy Dataset) Implement linear regression using scikit-learn on  California Housing dataset( Single Variable). Implement linear regression using scikit-learn o...

Explore Californoa Housing Dataset

  California Housing Dataset 🔹 Dataset Characteristics Feature Description Number of Instances                20,640 Number of Attributes                8 numerical predictive attributes + 1 target + 1 categorical Target Variable                Median House Value 🔹 Context This dataset is used in the book “Hands-On Machine Learning with Scikit-Learn and TensorFlow” by Aurélien Géron . It is widely used as an introductory dataset for machine learning because: Requires basic preprocessing Has clear and interpretable features Is moderate in size (not too small, not too large) 🔹 Dataset Description The dataset contains information about housing in California districts based on the 1990 U.S. Census . Each row represents a census block group , which is: The smallest geographical unit used by the census Typically contains ...

Recommended Tools and Setup for Lab

  Recommended Tools  Core Stack  Tool Purpose Python           Main language Jupyter Notebook           Interactive lab work NumPy           Numerical computation Pandas           Data handling Matplotlib / Seaborn           Visualization Scikit-learn           ML algorithms Advanced Tools  Tool Use Google Colab      No-install lab  Kaggle Notebooks      datasets + practice TensorFlow / PyTorch           neural networks Streamlit      mini project deployment  Best Offline Setup (Recommended)  Use Anaconda (Easiest) This is the best choice for students . 🔹 Steps: Download Anaconda from  https://www.anaconda.com/download Install it It includes: Python Jupyter Notebook NumPy, ...

Implementation of Multivariate Linear Regression using Gradient Descent (Toy Dataset)

Image
  Experiment  Implementation of Multivariate Linear Regression using Gradient Descent (Toy Dataset) 🎯 Aim To implement multivariate linear regression using gradient descent and evaluate its performance. 🎯 Objectives Understand multivariate regression Implement gradient descent manually Train model on sample dataset Compute MSE and R² Visualize cost convergence 📖 Theory 🔹 Multivariate Linear Regression Model y ^ = θ 0 + θ 1 x 1 + θ 2 x 2 + ⋯ + θ n x n \hat{y} = \theta_0 + \theta_1 x_1 + \theta_2 x_2 + \dots + \theta_n x_n ​ Matrix form: y ^ = X θ \hat{y} = X\theta 🔹 Cost Function (MSE) J ( θ ) = 1 n ∑ ( y − y ^ ) 2 J(\theta) = \frac{1}{n} \sum (y - \hat{y})^2 🔹 Gradient Descent Update Rule θ = θ − α ⋅ 2 n X T ( X θ − y ) \theta = \theta - \alpha \cdot \frac{2}{n} X^T (X\theta - y) 🔹 Evaluation Metrics Mean Squared Error (MSE): M S E = 1 n ∑ ( y − y ^ ) 2 MSE = \frac{1}{n} \sum (y - \hat{y})^2 R-squared (R²): R 2 = 1 − S S r e s S S t o ...

Simple Linear Regression using Gradient Descent

   Experiment  Simple Linear Regression using Gradient Descent Aim To implement Simple Linear Regression using Gradient Descent on sample data and evaluate the model using MSE and R² . Objectives Understand Gradient Descent optimization Iteratively compute regression coefficients Compare with analytical solution Compute MSE and R² manually Visualize regression line 🛠️ Tools Required Python NumPy Matplotlib 📖 Theory 🔹 Linear Regression Model y = θ 0 + θ 1 x y = \theta_0 + \theta_1 x 🔹 Cost Function (MSE) J ( θ ) = 1 n ∑ ( y i − y ^ i ) 2 J(\theta) = \frac{1}{n} \sum (y_i - \hat{y}_i)^2 🔹 Gradient Descent Gradient Descent minimizes the cost function iteratively: θ 0 : = θ 0 − α ⋅ ∂ J ∂ θ 0 \theta_0 := \theta_0 - \alpha \cdot \frac{\partial J}{\partial \theta_0} ​ θ 1 : = θ 1 − α ⋅ ∂ J ∂ θ 1 \theta_1 := \theta_1 - \alpha \cdot \frac{\partial J}{\partial \theta_1} ∂ J ∂ θ 0 = − 2 n ∑ ( y i − y ^ i ) \boxed{ \frac{\partial J...

Simple Linear Regression using Sample Data ( Single variable , Toy Example)

Image
  Experiment Simple Linear Regression using Sample Data Aim To implement Simple Linear Regression on sample data and manually compute: Regression coefficients Mean Squared Error (MSE) R-squared (R²)  Objectives Build a regression model from scratch Compute slope and intercept manually Evaluate model using MSE and R² (without sklearn) Visualize regression line 🛠️ Tools Required Python NumPy Matplotlib 📖 Theory 🔹 Linear Regression Model y = b 0 + b 1 x y = b_0 + b_1 x 🔹 Regression Coefficients b 1 = ∑ ( x − x ˉ ) ( y − y ˉ ) ∑ ( x − x ˉ ) 2 b_1 = \frac{\sum (x - \bar{x})(y - \bar{y})}{\sum (x - \bar{x})^2} ​ b 0 = y ˉ − b 1 x ˉ b_0 = \bar{y} - b_1 \bar{x} 🔹 Mean Squared Error (MSE) M S E = 1 n ∑ ( y i − y ^ i ) 2 MSE = \frac{1}{n} \sum (y_i - \hat{y}_i)^2 Measures average squared error Lower value → better model 🔹 R-squared (R² Score) R 2 = 1 − S S r e s S S t o t R^2 = 1 - \frac{SS_{res}}{SS_{tot}} ​ ​ Where: ...