Skip to content
Home Tutorials Roadmaps Courses
Log in Join free
Tutorials AI How Machine Learning Works
AI Intermediate FREE

How Machine Learning Works

Lesson 1 of 17 Intermediate Interactive

Machine Learning works by finding patterns in data and using them to make predictions.

ML Workflow

  1. Collect data
  2. Clean and prepare data
  3. Choose a model
  4. Train the model
  5. Evaluate performance
  6. Make predictions

Syntax

AI
# Simple ML example
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score

# Split data
X_train, X_test, y_train, y_test = train_test_split(X, y)

# Train model
model = RandomForestClassifier()
model.fit(X_train, y_train)

# Predict
predictions = model.predict(X_test)
accuracy = accuracy_score(y_test, predictions)
print(f"Accuracy: {accuracy}")
Simple Linear Regression
PYTHON
# Simple ML concept
def predict(weight, bias, x):
    return weight * x + bias

# Training data: hours studied vs score
hours = [1, 2, 3, 4, 5]
scores = [2, 4, 5, 8, 9]

# Simple training
weight = 1.8
bias = 0.2

for h, s in zip(hours, scores):
    predicted = predict(weight, bias, h)
    print(f"Hours: {h}, Actual: {s}, Predicted: {predicted:.1f}")

Practice

1
Exercise

What are the 6 steps of the ML workflow?

Answer
Collect data → Clean data → Choose model → Train → Evaluate → Predict

Quick Quiz

1

What does a machine learning model do?

ML models learn patterns from data to make predictions or decisions.

Interview Questions

Training a model on labeled data where the correct answers are known. The model learns to map inputs to outputs.