Back to AI/ML

Machine Learning Basics

Master the fundamentals of machine learning with our comprehensive tutorial. Learn supervised and unsupervised learning, data preprocessing, and model evaluation.

Video Tutorial

Introduction to Machine Learning

Machine Learning is a subset of artificial intelligence that enables systems to learn and improve from experience without being explicitly programmed. It focuses on developing computer programs that can access data and use it to learn for themselves.

Examples:

# Simple example
print("Machine Learning Types:")
print("1. Supervised Learning")
print("2. Unsupervised Learning")
print("3. Reinforcement Learning")

Three main types of machine learning approaches

Setting Up Your ML Environment

Before starting with machine learning, you need to set up your development environment with essential libraries.

Examples:

# Import commonly used ML libraries
import numpy as np
print(f"NumPy version: {np.__version__}")
print("NumPy imported successfully!")

Import commonly used ML libraries

Working with NumPy Arrays

NumPy is the foundation for numerical computing in Python and machine learning.

Examples:

import numpy as np

# Create arrays
arr = np.array([1, 2, 3, 4, 5])
matrix = np.array([[1, 2], [3, 4]])

print("Array:", arr)
print("Matrix:\n", matrix)
print("Array mean:", arr.mean())
print("Matrix shape:", matrix.shape)

Basic NumPy array operations

Simple Linear Regression Example

Linear regression is a fundamental supervised learning algorithm.

Examples:

import numpy as np

# Simple dataset
X = np.array([1, 2, 3, 4, 5])
y = np.array([2, 4, 5, 4, 5])

# Calculate slope and intercept manually
mean_x = np.mean(X)
mean_y = np.mean(Y)
slope = np.sum((X - mean_x) * (y - mean_y)) / np.sum((X - mean_x)**2)
intercept = mean_y - slope * mean_x

print(f"Slope: {slope:.2f}")
print(f"Intercept: {intercept:.2f}")
print(f"Equation: y = {slope:.2f}x + {intercept:.2f}")

Simple linear regression calculation

Data Preprocessing Example

Learn basic data preprocessing techniques.

Examples:

import numpy as np

# Sample data with missing values
data = np.array([1.0, 2.0, np.nan, 4.0, 5.0])
print("Original data:", data)

# Handle missing values (replace with mean)
mean_value = np.nanmean(data)
data_clean = np.where(np.isnan(data), mean_value, data)
print("Cleaned data:", data_clean)

# Normalize data (0-1 scale)
data_normalized = (data_clean - data_clean.min()) / (data_clean.max() - data_clean.min())
print("Normalized:", data_normalized)

Basic data cleaning and normalization

Quick Reference

Essential Libraries

  • scikit-learn - ML algorithms
  • pandas - Data manipulation
  • numpy - Numerical computing
  • matplotlib - Visualization

Best Practices

  • ✓ Always split data into train/test sets
  • ✓ Scale features before training
  • ✓ Use cross-validation for evaluation
  • ✓ Avoid overfitting with regularization