Master the fundamentals of machine learning with our comprehensive tutorial. Learn supervised and unsupervised learning, data preprocessing, and model evaluation.
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.
# 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
Before starting with machine learning, you need to set up your development environment with essential libraries.
# Import commonly used ML libraries
import numpy as np
print(f"NumPy version: {np.__version__}")
print("NumPy imported successfully!")Import commonly used ML libraries
NumPy is the foundation for numerical computing in Python and machine learning.
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
Linear regression is a fundamental supervised learning algorithm.
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
Learn basic data preprocessing techniques.
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
scikit-learn - ML algorithmspandas - Data manipulationnumpy - Numerical computingmatplotlib - Visualization