Introduction
Imagine you want a computer to recognize your friends' faces in photos without telling it exactly how to do it. Teaching a computer to learn from examples instead of giving it fixed instructions solves this problem.
Think of teaching a child to recognize animals by showing many pictures and naming them. The child learns to spot patterns like shapes and colors to identify animals they haven't seen before.
┌───────────────┐ ┌───────────────┐ ┌───────────────┐ │ Training │─────▶│ Model │─────▶│ Prediction │ │ (Known Data) │ │ (Learned │ │ (New Data │ │ │ │ Rules) │ │ Output) │ └───────────────┘ └───────────────┘ └───────────────┘
from sklearn.linear_model import LinearRegression model = LinearRegression() X_train = [[1], [2], [3], [4]] y_train = [2, 4, 6, 8] model.fit(X_train, y_train) print(model.predict([[5]]))
from sklearn.tree import DecisionTreeClassifier model = DecisionTreeClassifier() X_train = [[0], [1], [2]] y_train = [0, 1, 1] model.fit(X_train) print(model.predict([[1]]))
Pass the test and this pattern moves unknown