Supervised Learning

Master classification, regression, and practical applications

Understanding Supervised Learning

Supervised learning is a machine learning approach where the model learns from labeled data. The algorithm is trained on a dataset where the correct output is known, allowing it to learn patterns and make predictions on new, unseen data.

Types of Supervised Learning

Classification

Classification Example

Predicting discrete categories or classes

Regression

Regression Example

Predicting continuous numerical values

Classification Algorithms

  • • Logistic Regression
  • • Support Vector Machines
  • • Decision Trees
  • • Random Forests
  • • K-Nearest Neighbors

Regression Algorithms

  • • Linear Regression
  • • Polynomial Regression
  • • Ridge Regression
  • • Lasso Regression
  • • Elastic Net

Performance Metrics

Classification Metrics

Confusion Matrix
  • • Accuracy
  • • Precision & Recall
  • • F1 Score
  • • ROC & AUC

Regression Metrics

Regression Metrics
  • • Mean Squared Error (MSE)
  • • Root Mean Squared Error (RMSE)
  • • Mean Absolute Error (MAE)
  • • R-squared (R²)

Implementation Example

from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score

# Prepare data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

# Create and train model
model = RandomForestClassifier(n_estimators=100)
model.fit(X_train, y_train)

# Make predictions
predictions = model.predict(X_test)

# Evaluate performance
accuracy = accuracy_score(y_test, predictions)
print(f"Model Accuracy: {accuracy:.2f}")