Introduction
Imagine teaching a child to recognize animals by showing many pictures. The challenge is how a computer learns to recognize patterns or make decisions from examples it sees.
Think of teaching a child to recognize fruits by showing many pictures of apples and oranges with their names. The child learns patterns like color and shape. Later, when shown a new fruit, the child guesses its name based on what was learned.
┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Training │ │ Learning │ │ Model │ │ New Data │
│ Data │─────▶│ Process │─────▶│ Created │─────▶│ Input │
│ (Examples) │ │ (Training) │ │ (Rules) │ │ (Unseen) │
└─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘
│
▼
┌─────────────┐
│ Prediction │
│ or Decision │
└─────────────┘train_test_split.test_size=0.2 correctly sets 20% data for testing.from sklearn.linear_model import LinearRegression import numpy as np X = np.array([[1], [2], [3], [4]]) y = np.array([2, 4, 6, 8]) model = LinearRegression() model.fit(X, y) pred = model.predict([[5]]) print(round(pred[0], 1))
from sklearn.linear_model import LogisticRegression X_train = [[0, 1], [1, 0]] y_train = [0, 1] model = LogisticRegression() model.fit(y_train, X_train)
Pass the test and this pattern moves unknown