Introduction to Supervised Learning
Supervised learning is a type of machine learning in which the algorithm is trained on labeled data.
This means that for each input, the corresponding output (or label) is provided, and the algorithm
learns to map the inputs to the correct outputs.
Examples of supervised learning tasks include:
- Predicting house prices based on features such as size, location, and condition.
- Classifying emails as spam or not spam.
- Recognizing handwritten digits from images.
Supervised learning can be further divided into:
1. Regression: Predicting continuous outputs (e.g., predicting temperature).
2. Classification: Predicting discrete labels (e.g., identifying if an email is spam).
Python Coding Example
# Example: Classification using scikit-learn
from [Link] import load_iris
from sklearn.model_selection import train_test_split
from [Link] import RandomForestClassifier
from [Link] import accuracy_score
# Load dataset
data = load_iris()
X, y = [Link], [Link]
# Split into training and testing data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Train the model
clf = RandomForestClassifier()
[Link](X_train, y_train)
# Make predictions
predictions = [Link](X_test)
# Evaluate the model
print("Accuracy:", accuracy_score(y_test, predictions))
Exercises
1. Load the Boston housing dataset and train a regression model to predict
house prices.
2. Use the MNIST dataset to classify handwritten digits using a neural network.
3. Experiment with different classifiers (e.g., SVM, Decision Tree) on the Iris
dataset.
4. Implement cross-validation and check how it affects model performance.