Header Ads Widget

Responsive Advertisement

Ticker

6/recent/ticker-posts

Day-5 – Machine Learning Model (Linear Regression)

Now we move from “data handling” → “AI prediction” 🚀

🎯 Goal of Day-5

You will:

✅ Understand what ML model is
✅ Build your first prediction model
✅ Predict values using data


🧠 What is Machine Learning Model?

Simple:

Model = Function that learns from data and predicts output

Example:

Input: House size

Output: Price

Model learns relation.


🧠 Linear Regression Concept

It tries to fit a straight line:

Where:

  1. y = output (price / marks)
  2. x = input (size / age)
  3. m = slope
  4. b = intercept

🚀 Part 1 – Install & Import

In Colab:

import pandas as pd
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression


🚀 Part 2 – Create Simple Dataset

data = {
"Hours": [1, 2, 3, 4, 5],
"Marks": [40, 50, 60, 70, 80]
}

df = pd.DataFrame(data)


🚀 Part 3 – Prepare Data

X = df[["Hours"]]   # input (must be 2D)

y = df["Marks"]     # output


🚀 Part 4 – Train Model

model = LinearRegression()

model.fit(X, y)

👉 Model learned pattern.


🚀 Part 5 – Predict

prediction = model.predict([[6]])

print("Predicted Marks:", prediction)

👉 If student studies 6 hours → predicted marks


🚀 Part 6 – Visualize Model

plt.scatter(df["Hours"], df["Marks"])

plt.plot(df["Hours"], model.predict(X))

plt.xlabel("Hours")

plt.ylabel("Marks")

plt.title("Study Hours vs Marks")

plt.show()

👉 Dots = actual data
👉 Line = model prediction


🎯 Mini Practice (Do This)

Task 1:

Hours = [1,2,3,4,5,6]
Marks = [35,45,55,65,75,85]

Train again.

Task 2:

Try with your CSV (if possible)

Example:

X = df[["Age"]]

y = df["Marks"]


⚠ Common Mistake

❌ This will fail:

model.predict([6])

Correct:

model.predict([[6]])

(2D input required)


🎯 End of Day-5 Goals

You should now:

✅ Understand ML basics
✅ Train model
✅ Make predictions
✅ Visualize ML output


🔥 Real AI Insight

This simple model is base of:

  • House price prediction
  • Sales forecasting
  • Stock prediction (basic level)


Github Link: https://github.com/dotnetfullstackdeveloper/ai-engineer-journey/blob/main/Week-01-AI-Foundations/Day-5:%20Machine%20Learning%20Model



Post a Comment

0 Comments