Fundamentals of Machine Learning
Types of Machine Learning Machine learning (ML) is a subset of artificial intelligence that enables systems to learn patterns from data and make predictions. It is generally categorized into the following types: Supervised Learning The model is trained on labeled data (i.e., data with known outputs). The goal is to learn the mapping from inputs to correct outputs. Common applications: Spam detection, Image classification, Stock price prediction Example: from sklearn.linear_model import LinearRegression import numpy as np x_train = np.array([1, 2, 3, 4, 5]).reshape(-1, 1) y_train = np.array([30, 35, 40, 50, 60]) model = LinearRegression() model.fit(x_train, y_train) print("Predicted salary for 6 years of experience:", model.predict([[6]])[0]) Unsupervised Learning The model is trained on unlabeled data (i.e., no predefined outputs). The goal is to find hidden structures or patterns in data. Common applications: Customer segmentation, Anomaly detection, Market basket analysis Example: from sklearn.cluster import KMeans import numpy as np data = np.array([[2, 3], [10, 15], [5, 8], [12, 14], [6, 9]]) kmeans = KMeans(n_clusters=2, random_state=42) kmeans.fit(data) print("Cluster assignments:", kmeans.labels_) Reinforcement Learning (RL) The model learns through trial and error and receives rewards or penalties based on actions. Used in game AI, robotics, and autonomous systems. Includes Proximal Policy Optimization (PPO), Generalized Proximal Policy Optimization (GRPO). Example: Self-learning game AI like AlphaGo. Value-Based vs. Rule-Based Learning Value-Based Learning: The AI assigns numerical values to different outcomes and chooses actions maximizing future rewards (e.g., Q-learning in RL). Rule-Based Learning: The AI follows predefined rules (e.g., Decision Trees, Expert Systems). Regression & Classification Basics Machine learning models are not only categorized into regression and classification but also include reinforcement learning and generative models. However, regression and classification are the most fundamental predictive learning approaches. ...