Launch the interactive walkthrough to discover each component, including the 3D Q-Sphere Lab & Python in Colab.
Grasp the core engine of modern AI: learning patterns from data without being explicitly programmed.
| Symbol / Term | Meaning | Beginner Interpretation |
|---|---|---|
| Input features | Measurements fed into the system | |
| Weight vector | Importance weight assigned to each feature | |
| Bias scalar | Baseline offset when all features are zero |
Predicting car price based on mileage (in thousands): base price $25,000 with -$150 per thousand miles.
Result: Estimated value: $19,000 for a car with 40,000 miles
Raw data is cleaned, normalized, and partitioned into training, validation, and test splits.
Select an algorithm (Linear Model, Decision Tree, Support Vector Machine, Neural Network).
Model makes predictions, evaluates errors against ground truth, and updates weights via gradient descent.
Model accuracy is verified on unseen test data before real-world production deployment.
Problem: Assessing property market value across diverse neighborhoods without manual home appraisals.
Solution: Ensemble models analyze square footage, school ratings, and recent neighborhood sales to estimate valuation in real-time.
Problem: Telecom companies losing subscribers to competitors without warning.
Solution: ML classifies users showing declining usage and proactively triggers personalized retention discounts.
Interactive activity component
Train a linear regression model on house sizes and prices, predict prices for unseen square footage, and plot the regression line using matplotlib.
For Google Colab or Jupyter notebooks, run this shell command to install the required dependencies:
!pip install scikit-learn numpy matplotlib1 import numpy as np 2 import matplotlib.pyplot as plt 3 from sklearn.linear_model import LinearRegression
import numpy as np → Array manipulation and matrix reshaping
import matplotlib.pyplot as plt → Plot data points and regression line
from sklearn.linear_model import LinearRegression → Ordinary Least Squares linear regression model
1 # Data: House sizes (sq ft) and corresponding prices 2 X = np.array([500, 700, 900, 1100, 1300]).reshape(-1, 1) # Feature (sq ft) 3 y = np.array([150000, 180000, 210000, 250000, 280000]) # Target (price in $) 4 5 # Create Linear Regression model 6 model = LinearRegression() 7 8 # Train the model on the data 9 model.fit(X, y) 10 11 # Predict price for a house with 1000 sq ft 12 predicted_price = model.predict([[1000]]) 13 print(f"Predicted Price for 1000 sq ft house: ${predicted_price[0]:,.2f}") 14 15 # Plot Data and Regression Line 16 plt.scatter(X, y, color='blue', label="Actual Prices") 17 plt.plot(X, model.predict(X), color='red', label="Regression Line") 18 plt.xlabel("House Size (sq ft)") 19 plt.ylabel("House Price ($)") 20 plt.title("Linear Regression - House Price Prediction (Lesson 2)") 21 plt.legend() 22 plt.show()
# Data: House sizes (sq ft) and corresponding prices
Define training dataset
X = np.array([500, 700, 900, 1100, 1300]).reshape(-1, 1) # Feature (sq ft)
Reshape feature into 2D array
y = np.array([150000, 180000, 210000, 250000, 280000]) # Target (price in $)
Continuous target values
# Create Linear Regression model
Instantiate linear regressor
model = LinearRegression()
Initialize estimator
# Train the model on the data
Fit model parameters (slope and intercept)
model.fit(X, y)
Execute gradient/normal equation fitting
# Predict price for a house with 1000 sq ft
Run inference on unseen feature
predicted_price = model.predict([[1000]])
Evaluate model at X=1000
print(f"Predicted Price for 1000 sq ft house: ${predicted_price[0]:,.2f}")
Print estimated price
# Plot Data and Regression Line
Visualization with matplotlib
plt.scatter(X, y, color='blue', label="Actual Prices")
Scatter plot of ground-truth points
plt.plot(X, model.predict(X), color='red', label="Regression Line")
Fitted linear boundary
plt.xlabel("House Size (sq ft)")
Set X-axis label
plt.ylabel("House Price ($)")
Set Y-axis label
plt.title("Linear Regression - House Price Prediction (Lesson 2)")
Set plot title
plt.legend()
Display legend
plt.show()
Render plot figure
Click "Copy for Colab", open Google Colab, paste into a single cell, and run.
1 # ========================================================= 2 # Lesson 2: Classical Machine Learning — House Price Prediction with Linear Regression 3 # Prepared for Google Colab (Run with Shift + Enter) 4 # ========================================================= 5 6 # Step 1: Install required packages 7 !pip install scikit-learn numpy matplotlib 8 9 # Step 2: Import libraries 10 import numpy as np 11 import matplotlib.pyplot as plt 12 from sklearn.linear_model import LinearRegression 13 14 # Step 3: Run Demonstration 15 # Data: House sizes (sq ft) and corresponding prices 16 X = np.array([500, 700, 900, 1100, 1300]).reshape(-1, 1) # Feature (sq ft) 17 y = np.array([150000, 180000, 210000, 250000, 280000]) # Target (price in $) 18 19 # Create Linear Regression model 20 model = LinearRegression() 21 22 # Train the model on the data 23 model.fit(X, y) 24 25 # Predict price for a house with 1000 sq ft 26 predicted_price = model.predict([[1000]]) 27 print(f"Predicted Price for 1000 sq ft house: ${predicted_price[0]:,.2f}") 28 29 # Plot Data and Regression Line 30 plt.scatter(X, y, color='blue', label="Actual Prices") 31 plt.plot(X, model.predict(X), color='red', label="Regression Line") 32 plt.xlabel("House Size (sq ft)") 33 plt.ylabel("House Price ($)") 34 plt.title("Linear Regression - House Price Prediction (Lesson 2)") 35 plt.legend() 36 plt.show()
Input feature square footage is converted to a 2D column vector and paired with price targets.
Scikit-Learn computes the optimal slope and intercept minimizing Mean Squared Error.
Model predicts the price for a 1,000 sq ft house ($230,000.00).
Matplotlib plots the actual data points alongside the learned continuous regression line.
House Sizes: [500, 700, 900, 1100, 1300] sq ft, Target Query: 1000 sq ft
Predicted Price for 1000 sq ft house: $230,000.00
Demonstrates supervised learning regression: the model discovers the underlying linear relationship Price = m * Area + c and generalizes to unseen house sizes.
Data, prediction, and the bridge to modern AI — Presentation by Dr. Syed Muzamil Basha.
Test your understanding with these questions. Remember, this is for learning, not examination!