Launch the interactive walkthrough to discover each component, including the 3D Q-Sphere Lab & Python in Colab.
Explore fundamental classification algorithms: Logistic Regression, Support Vector Machines (SVM), and Decision Trees.
| Symbol / Term | Meaning | Beginner Interpretation |
|---|---|---|
| Sigmoid activation | S-shaped probability mapping | |
| Weight vector | Feature importances | |
| Threshold shift |
Linear score z = 0.0 results in exactly 50% probability.
Result: P = 0.50 (Exact decision boundary threshold)
Compute dot product of features with learned weights: z = w1*x1 + w2*x2 + b.
Pass z through sigmoid function to obtain probability p = 1 / (1 + exp(-z)).
If p >= 0.5, predict Class 1; otherwise predict Class 0.
Problem: Classifying incoming emails as spam or inbox.
Solution: Logistic regression calculates probability based on token frequency features.
Problem: Flagging fraudulent card transactions.
Solution: SVM with RBF kernel detects non-linear fraud clusters in high-dimensional spend spaces.
Interactive activity component
Train a Logistic Regression classifier on labeled feature data and evaluate generalization accuracy on unseen test data.
For Google Colab or Jupyter notebooks, run this shell command to install the required dependencies:
!pip install scikit-learn1 from sklearn.model_selection import train_test_split 2 from sklearn.linear_model import LogisticRegression 3 from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split β Dataset split utility
from sklearn.linear_model import LogisticRegression β Logistic regression classifier
from sklearn.metrics import accuracy_score β Accuracy score metric
1 # Sample feature data and class labels 2 X = [[1], [2], [3], [4], [5], [1], [2], [3], [4], [5], [1], [2], [3], [4], [5], [1], [2], [3], [4], [5]] 3 y = [1, 2, 3, 4, 5, 1, 3, 3, 4, 5, 1, 2, 3, 4, 5, 1, 1, 3, 4, 5] # Labels 4 5 # Split data into training (80%) and testing (20%) sets 6 X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) 7 8 # Train a Logistic Regression model 9 model = LogisticRegression() 10 model.fit(X_train, y_train) 11 12 # Make predictions on unseen test data 13 y_pred = model.predict(X_test) 14 15 # Evaluate model accuracy 16 accuracy = accuracy_score(y_test, y_pred) 17 print("Accuracy:", accuracy)
# Sample feature data and class labels
Dataset definition
X = [[1], [2], [3], [4], [5], [1], [2], [3], [4], [5], [1], [2], [3], [4], [5], [1], [2], [3], [4], [5]]
Feature values
y = [1, 2, 3, 4, 5, 1, 3, 3, 4, 5, 1, 2, 3, 4, 5, 1, 1, 3, 4, 5] # Labels
Target classes
# Split data into training (80%) and testing (20%) sets
Train/test split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
Split datasets
# Train a Logistic Regression model
Model creation
model = LogisticRegression()
Instantiate classifier
model.fit(X_train, y_train)
Fit model on training set
# Make predictions on unseen test data
Inference
y_pred = model.predict(X_test)
Predict classes
# Evaluate model accuracy
Evaluation
accuracy = accuracy_score(y_test, y_pred)
Compute accuracy
print("Accuracy:", accuracy)
Display accuracy score
Click "Copy for Colab", open Google Colab, paste into a single cell, and run.
1 # ========================================================= 2 # Classification with Logistic Regression & Train-Test Split 3 # Prepared for Google Colab (Run with Shift + Enter) 4 # ========================================================= 5 6 # Step 1: Install required packages 7 !pip install scikit-learn 8 9 # Step 2: Import libraries 10 from sklearn.model_selection import train_test_split 11 from sklearn.linear_model import LogisticRegression 12 from sklearn.metrics import accuracy_score 13 14 # Step 3: Run Demonstration 15 # Sample feature data and class labels 16 X = [[1], [2], [3], [4], [5], [1], [2], [3], [4], [5], [1], [2], [3], [4], [5], [1], [2], [3], [4], [5]] 17 y = [1, 2, 3, 4, 5, 1, 3, 3, 4, 5, 1, 2, 3, 4, 5, 1, 1, 3, 4, 5] # Labels 18 19 # Split data into training (80%) and testing (20%) sets 20 X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) 21 22 # Train a Logistic Regression model 23 model = LogisticRegression() 24 model.fit(X_train, y_train) 25 26 # Make predictions on unseen test data 27 y_pred = model.predict(X_test) 28 29 # Evaluate model accuracy 30 accuracy = accuracy_score(y_test, y_pred) 31 print("Accuracy:", accuracy)
Splits 20 samples into 16 training instances and 4 held-out testing instances.
LogisticRegression optimizes class decision boundaries on X_train and y_train.
Calculates classification accuracy on X_test.
20 feature-label pairs split 80/20
Accuracy: 0.75
The model correctly generalizes to unseen test cases by discovering the relationship between numerical inputs and target class labels.
Supervised classification pipelines, train-test splits, and logistic decision boundaries.
Test your understanding with these questions. Remember, this is for learning, not examination!