Chapter 4: Supervised Learning

 

Chapter 4: Supervised Learning

🎯 Supervised Learning is a type of machine learning where the model learns from labeled data (i.e., input with known output).


What is Supervised Learning?

  • The algorithm is "supervised" because it learns from training data that includes both the input and the correct output (label).

  • The goal is to predict output for new, unseen inputs.


🔁 Supervised Learning Workflow:

markdown
1. Collect labeled data ➝ 2. Split into train & test ➝ 3. Choose a model ➝ 4. Train model ➝ 5. Evaluate on test data ➝ 6. Predict new data

🔹 Types of Supervised Learning

TypeOutputExamples
RegressionContinuous valuePredict price, temperature, salary
ClassificationCategorical classSpam vs. Ham, Yes/No, Cat/Dog

🔢 1. Regression Algorithms

a. Linear Regression

  • Predicts a continuous output using a straight line:

y=mx+cy = mx + c

📌 Example: Predict house price based on area.

python
from sklearn.linear_model import LinearRegression model = LinearRegression() model.fit(X_train, y_train)

b. Polynomial Regression

  • Fits a curve (non-linear data).

  • Useful when data is not linearly separable.


🧭 2. Classification Algorithms

a. Logistic Regression

  • For binary classification (yes/no)

  • Outputs probabilities between 0 and 1

python
from sklearn.linear_model import LogisticRegression model = LogisticRegression() model.fit(X_train, y_train)

b. Decision Trees

  • Tree-like model for decisions.

  • Easy to visualize.

c. K-Nearest Neighbors (KNN)

  • Classifies a point based on its K nearest neighbors.

d. Support Vector Machines (SVM)

  • Finds the best boundary (hyperplane) that separates classes.


📏 Model Evaluation Metrics

MetricUsed ForDescription
AccuracyClassification% of correct predictions
PrecisionClassificationTrue Positives / (TP + FP)
RecallClassificationTrue Positives / (TP + FN)
F1 ScoreClassificationHarmonic mean of precision and recall
MSE / RMSERegressionMeasures prediction error

💻 Hands-On Project Ideas

✅ Predict House Prices (Regression)

  • Input: Area, Bedrooms, Location

  • Output: Price

✅ Email Spam Classifier (Classification)

  • Input: Text of email

  • Output: Spam or Not Spam


Example Code (Classification):

python
from sklearn.model_selection import train_test_split from sklearn.linear_model import LogisticRegression from sklearn.metrics import accuracy_score # Split data X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2) # Train model model = LogisticRegression() model.fit(X_train, y_train) # Predict y_pred = model.predict(X_test) # Evaluate print("Accuracy:", accuracy_score(y_test, y_pred))

📚 Summary of Chapter 4

ConceptSummary
Supervised LearningLearn from labeled data
RegressionPredict continuous values
ClassificationPredict categories or classes
Common AlgorithmsLinear, Logistic, KNN, SVM, Decision Trees
Evaluation MetricsAccuracy, Precision, Recall, RMSE, F1 Score
Hands-onPredict house price, classify spam

✅ Mini Assignment:

  1. Build a Linear Regression model to predict house price using area.

  2. Build a Spam Classifier using Logistic Regression and check accuracy.

  3. Try tuning the value of K in KNN and observe results.

homeacademy

Home academy is JK's First e-learning platform started by Er. Afzal Malik For Competitive examination and Academics K12. We have true desire to serve to society by way of making educational content easy . We are expertise in STEM We conduct workshops in schools Deals with Science Engineering Projects . We also Write Thesis for your Research Work in Physics Chemistry Biology Mechanical engineering Robotics Nanotechnology Material Science Industrial Engineering Spectroscopy Automotive technology ,We write Content For Coaching Centers also infohomeacademy786@gmail.com

Post a Comment (0)
Previous Post Next Post