Q1ML Fundamentals
What is machine learning?
Machine learning learns patterns from examples to make predictions or decisions. Define the target and success metric, create a leakage-safe split, fi...
Answer
Machine learning learns patterns from examples to make predictions or decisions. Define the target and success metric, create a leakage-safe split, fit preprocessing and a model on training data, tune with validation or cross-validation, and reserve the test set for final evaluation.
Syntax
X = df[feature_columns]; y = df[target_column]
model.fit(X_train, y_train) # learn parameters
model.predict(X_new) # predict unseen rows
Example
Predict customer churn from account tenure, usage, and plan information; churn status is the target.
Code example
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42, stratify=y)
model.fit(X_train, y_train)
predictions = model.predict(X_test)
Diagram
Raw data → Define target → Split data → Train model → Validate → Test
Key Points
- Machine learning learns patterns from examples to make predictions or decisions
- Keep test data untouched until final evaluation.
Q2ML Fundamentals
What are the main types of machine learning?
Machine learning learns patterns from examples to make predictions or decisions. Define the target and success metric, create a leakage-safe split, fi...
Answer
Machine learning learns patterns from examples to make predictions or decisions. Define the target and success metric, create a leakage-safe split, fit preprocessing and a model on training data, tune with validation or cross-validation, and reserve the test set for final evaluation.
Syntax
X = df[feature_columns]; y = df[target_column]
model.fit(X_train, y_train) # learn parameters
model.predict(X_new) # predict unseen rows
Example
Predict customer churn from account tenure, usage, and plan information; churn status is the target.
Code example
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42, stratify=y)
model.fit(X_train, y_train)
predictions = model.predict(X_test)
Diagram
Raw data → Define target → Split data → Train model → Validate → Test
Key Points
- Machine learning learns patterns from examples to make predictions or decisions
- Keep test data untouched until final evaluation.
Q3ML Fundamentals
Classification vs regression
Machine learning learns patterns from examples to make predictions or decisions. Define the target and success metric, create a leakage-safe split, fi...
Answer
Machine learning learns patterns from examples to make predictions or decisions. Define the target and success metric, create a leakage-safe split, fit preprocessing and a model on training data, tune with validation or cross-validation, and reserve the test set for final evaluation.
Syntax
X = df[feature_columns]; y = df[target_column]
model.fit(X_train, y_train) # learn parameters
model.predict(X_new) # predict unseen rows
Example
Predict customer churn from account tenure, usage, and plan information; churn status is the target.
Code example
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42, stratify=y)
model.fit(X_train, y_train)
predictions = model.predict(X_test)
Diagram
Raw data → Define target → Split data → Train model → Validate → Test
Key Points
- Machine learning learns patterns from examples to make predictions or decisions
- Keep test data untouched until final evaluation.
Q4ML Fundamentals
Explain the typical ML workflow
Machine learning learns patterns from examples to make predictions or decisions. Define the target and success metric, create a leakage-safe split, fi...
Answer
Machine learning learns patterns from examples to make predictions or decisions. Define the target and success metric, create a leakage-safe split, fit preprocessing and a model on training data, tune with validation or cross-validation, and reserve the test set for final evaluation.
Syntax
X = df[feature_columns]; y = df[target_column]
model.fit(X_train, y_train) # learn parameters
model.predict(X_new) # predict unseen rows
Example
Predict customer churn from account tenure, usage, and plan information; churn status is the target.
Code example
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42, stratify=y)
model.fit(X_train, y_train)
predictions = model.predict(X_test)
Diagram
Raw data → Define target → Split data → Train model → Validate → Test
Key Points
- Machine learning learns patterns from examples to make predictions or decisions
- Keep test data untouched until final evaluation.
Q5ML Fundamentals
What are features and labels?
Machine learning learns patterns from examples to make predictions or decisions. Define the target and success metric, create a leakage-safe split, fi...
Answer
Machine learning learns patterns from examples to make predictions or decisions. Define the target and success metric, create a leakage-safe split, fit preprocessing and a model on training data, tune with validation or cross-validation, and reserve the test set for final evaluation.
Syntax
X = df[feature_columns]; y = df[target_column]
model.fit(X_train, y_train) # learn parameters
model.predict(X_new) # predict unseen rows
Example
Predict customer churn from account tenure, usage, and plan information; churn status is the target.
Code example
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42, stratify=y)
model.fit(X_train, y_train)
predictions = model.predict(X_test)
Diagram
Raw data → Define target → Split data → Train model → Validate → Test
Key Points
- Machine learning learns patterns from examples to make predictions or decisions
- Keep test data untouched until final evaluation.
Q6ML Fundamentals
What is overfitting?
Overfitting occurs when a model learns noise or quirks in training data and generalizes poorly. Look for a large training/validation gap; simplify the...
Answer
Overfitting occurs when a model learns noise or quirks in training data and generalizes poorly. Look for a large training/validation gap; simplify the model, regularize, improve data quality, or collect representative data.
Syntax
X = df[feature_columns]; y = df[target_column]
model.fit(X_train, y_train) # learn parameters
model.predict(X_new) # predict unseen rows
Example
A deep decision tree gets near-perfect training accuracy but much worse validation accuracy.
Code example
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42, stratify=y)
model.fit(X_train, y_train)
predictions = model.predict(X_test)
Diagram
Raw data → Define target → Split data → Train model → Validate → Test
Key Points
- Overfitting occurs when a model learns noise or quirks in training data and generalizes poorly
- Keep test data untouched until final evaluation.
Q7ML Fundamentals
What is underfitting?
Underfitting occurs when a model is too simple or insufficiently trained to capture useful patterns. Training and validation performance are both poor...
Answer
Underfitting occurs when a model is too simple or insufficiently trained to capture useful patterns. Training and validation performance are both poor; consider better features, a more expressive model, or improved optimization.
Syntax
X = df[feature_columns]; y = df[target_column]
model.fit(X_train, y_train) # learn parameters
model.predict(X_new) # predict unseen rows
Example
A shallow tree misses nonlinear patterns and performs poorly on training and validation sets.
Code example
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42, stratify=y)
model.fit(X_train, y_train)
predictions = model.predict(X_test)
Diagram
Raw data → Define target → Split data → Train model → Validate → Test
Key Points
- Underfitting occurs when a model is too simple or insufficiently trained to capture useful patterns
- Keep test data untouched until final evaluation.
Q8ML Fundamentals
Explain the bias-variance trade-off
High bias reflects restrictive assumptions; high variance reflects sensitivity to the training sample. Select complexity using validation performance,...
Answer
High bias reflects restrictive assumptions; high variance reflects sensitivity to the training sample. Select complexity using validation performance, balancing both while recognizing irreducible noise.
Syntax
X = df[feature_columns]; y = df[target_column]
model.fit(X_train, y_train) # learn parameters
model.predict(X_new) # predict unseen rows
Example
Predict customer churn from account tenure, usage, and plan information; churn status is the target.
Code example
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42, stratify=y)
model.fit(X_train, y_train)
predictions = model.predict(X_test)
Diagram
Raw data → Define target → Split data → Train model → Validate → Test
Key Points
- High bias reflects restrictive assumptions; high variance reflects sensitivity to the training sample
- Keep test data untouched until final evaluation.
Q9ML Fundamentals
What is a baseline model?
Machine learning learns patterns from examples to make predictions or decisions. Define the target and success metric, create a leakage-safe split, fi...
Answer
Machine learning learns patterns from examples to make predictions or decisions. Define the target and success metric, create a leakage-safe split, fit preprocessing and a model on training data, tune with validation or cross-validation, and reserve the test set for final evaluation.
Syntax
X = df[feature_columns]; y = df[target_column]
model.fit(X_train, y_train) # learn parameters
model.predict(X_new) # predict unseen rows
Example
Predict customer churn from account tenure, usage, and plan information; churn status is the target.
Code example
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42, stratify=y)
model.fit(X_train, y_train)
predictions = model.predict(X_test)
Diagram
Raw data → Define target → Split data → Train model → Validate → Test
Key Points
- Machine learning learns patterns from examples to make predictions or decisions
- Keep test data untouched until final evaluation.
Q10ML Fundamentals
Parametric vs non-parametric models
Machine learning learns patterns from examples to make predictions or decisions. Define the target and success metric, create a leakage-safe split, fi...
Answer
Machine learning learns patterns from examples to make predictions or decisions. Define the target and success metric, create a leakage-safe split, fit preprocessing and a model on training data, tune with validation or cross-validation, and reserve the test set for final evaluation.
Syntax
X = df[feature_columns]; y = df[target_column]
model.fit(X_train, y_train) # learn parameters
model.predict(X_new) # predict unseen rows
Example
Predict customer churn from account tenure, usage, and plan information; churn status is the target.
Code example
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42, stratify=y)
model.fit(X_train, y_train)
predictions = model.predict(X_test)
Diagram
Raw data → Define target → Split data → Train model → Validate → Test
Key Points
- Machine learning learns patterns from examples to make predictions or decisions
- Keep test data untouched until final evaluation.
Q11Algorithms
How does linear regression work?
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune ca...
Answer
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune candidates with cross-validation, and compare them using the same splits and metric.
Syntax
y_hat = beta_0 + beta_1*x_1 + ... + beta_p*x_p
Example
Compare logistic regression, a decision tree, and a tree ensemble for the same classification task.
Code example
from sklearn.linear_model import LinearRegression
model = LinearRegression().fit(X_train, y_train)
pred = model.predict(X_valid)
Diagram
Features → Algorithm / learned parameters → Predictions → Evaluation
Key Points
- Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs
- Keep test data untouched until final evaluation.
Q12Algorithms
Linear regression assumptions
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune ca...
Answer
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune candidates with cross-validation, and compare them using the same splits and metric.
Syntax
y_hat = beta_0 + beta_1*x_1 + ... + beta_p*x_p
Example
Compare logistic regression, a decision tree, and a tree ensemble for the same classification task.
Code example
from sklearn.linear_model import LinearRegression
model = LinearRegression().fit(X_train, y_train)
pred = model.predict(X_valid)
Diagram
Features → Algorithm / learned parameters → Predictions → Evaluation
Key Points
- Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs
- Keep test data untouched until final evaluation.
Q13Algorithms
What is logistic regression?
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune ca...
Answer
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune candidates with cross-validation, and compare them using the same splits and metric.
Syntax
P(y=1|x) = 1 / (1 + exp(-(wᵀx + b)))
Example
Compare logistic regression, a decision tree, and a tree ensemble for the same classification task.
Code example
from sklearn.linear_model import LogisticRegression
model = LogisticRegression(max_iter=1000, class_weight='balanced')
model.fit(X_train, y_train)
probability = model.predict_proba(X_valid)[:, 1]
Diagram
Features → Algorithm / learned parameters → Predictions → Evaluation
Key Points
- Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs
- Keep test data untouched until final evaluation.
Q14Algorithms
What is a decision tree?
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune ca...
Answer
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune candidates with cross-validation, and compare them using the same splits and metric.
Syntax
Classification: model.fit(X, y_class)
Regression: model.fit(X, y_numeric)
Clustering: labels = model.fit_predict(X)
Example
Compare logistic regression, a decision tree, and a tree ensemble for the same classification task.
Code example
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=200, random_state=42)
model.fit(X_train, y_train)
predictions = model.predict(X_valid)
Diagram
Features → Algorithm / learned parameters → Predictions → Evaluation
Key Points
- Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs
- Keep test data untouched until final evaluation.
Q15Algorithms
Gini impurity vs entropy
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune ca...
Answer
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune candidates with cross-validation, and compare them using the same splits and metric.
Syntax
Classification: model.fit(X, y_class)
Regression: model.fit(X, y_numeric)
Clustering: labels = model.fit_predict(X)
Example
Compare logistic regression, a decision tree, and a tree ensemble for the same classification task.
Code example
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=200, random_state=42)
model.fit(X_train, y_train)
predictions = model.predict(X_valid)
Diagram
Features → Algorithm / learned parameters → Predictions → Evaluation
Key Points
- Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs
- Keep test data untouched until final evaluation.
Q16Algorithms
What is Random Forest?
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune ca...
Answer
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune candidates with cross-validation, and compare them using the same splits and metric.
Syntax
RandomForestClassifier(n_estimators=200, max_depth=None)
Example
Compare logistic regression, a decision tree, and a tree ensemble for the same classification task.
Code example
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=200, max_features='sqrt', random_state=42, n_jobs=-1)
model.fit(X_train, y_train)
Diagram
Features → Algorithm / learned parameters → Predictions → Evaluation
Key Points
- Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs
- Keep test data untouched until final evaluation.
Q17Algorithms
What is bagging?
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune ca...
Answer
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune candidates with cross-validation, and compare them using the same splits and metric.
Syntax
Classification: model.fit(X, y_class)
Regression: model.fit(X, y_numeric)
Clustering: labels = model.fit_predict(X)
Example
Compare logistic regression, a decision tree, and a tree ensemble for the same classification task.
Code example
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=200, random_state=42)
model.fit(X_train, y_train)
predictions = model.predict(X_valid)
Diagram
Features → Algorithm / learned parameters → Predictions → Evaluation
Key Points
- Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs
- Keep test data untouched until final evaluation.
Q18Algorithms
What is boosting?
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune ca...
Answer
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune candidates with cross-validation, and compare them using the same splits and metric.
Syntax
Classification: model.fit(X, y_class)
Regression: model.fit(X, y_numeric)
Clustering: labels = model.fit_predict(X)
Example
Compare logistic regression, a decision tree, and a tree ensemble for the same classification task.
Code example
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=200, random_state=42)
model.fit(X_train, y_train)
predictions = model.predict(X_valid)
Diagram
Features → Algorithm / learned parameters → Predictions → Evaluation
Key Points
- Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs
- Keep test data untouched until final evaluation.
Q19Algorithms
AdaBoost vs gradient boosting
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune ca...
Answer
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune candidates with cross-validation, and compare them using the same splits and metric.
Syntax
Classification: model.fit(X, y_class)
Regression: model.fit(X, y_numeric)
Clustering: labels = model.fit_predict(X)
Example
Compare logistic regression, a decision tree, and a tree ensemble for the same classification task.
Code example
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=200, random_state=42)
model.fit(X_train, y_train)
predictions = model.predict(X_valid)
Diagram
Features → Algorithm / learned parameters → Predictions → Evaluation
Key Points
- Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs
- Keep test data untouched until final evaluation.
Q20Algorithms
What is XGBoost?
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune ca...
Answer
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune candidates with cross-validation, and compare them using the same splits and metric.
Syntax
Classification: model.fit(X, y_class)
Regression: model.fit(X, y_numeric)
Clustering: labels = model.fit_predict(X)
Example
Compare logistic regression, a decision tree, and a tree ensemble for the same classification task.
Code example
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=200, random_state=42)
model.fit(X_train, y_train)
predictions = model.predict(X_valid)
Diagram
Features → Algorithm / learned parameters → Predictions → Evaluation
Key Points
- Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs
- Keep test data untouched until final evaluation.
Q21Algorithms
What is an SVM?
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune ca...
Answer
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune candidates with cross-validation, and compare them using the same splits and metric.
Syntax
Classification: model.fit(X, y_class)
Regression: model.fit(X, y_numeric)
Clustering: labels = model.fit_predict(X)
Example
Compare logistic regression, a decision tree, and a tree ensemble for the same classification task.
Code example
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=200, random_state=42)
model.fit(X_train, y_train)
predictions = model.predict(X_valid)
Diagram
Features → Algorithm / learned parameters → Predictions → Evaluation
Key Points
- Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs
- Keep test data untouched until final evaluation.
Q22Algorithms
What is k-nearest neighbors?
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune ca...
Answer
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune candidates with cross-validation, and compare them using the same splits and metric.
Syntax
Classification: model.fit(X, y_class)
Regression: model.fit(X, y_numeric)
Clustering: labels = model.fit_predict(X)
Example
Compare logistic regression, a decision tree, and a tree ensemble for the same classification task.
Code example
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=200, random_state=42)
model.fit(X_train, y_train)
predictions = model.predict(X_valid)
Diagram
Features → Algorithm / learned parameters → Predictions → Evaluation
Key Points
- Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs
- Keep test data untouched until final evaluation.
Q23Algorithms
What is Naive Bayes?
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune ca...
Answer
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune candidates with cross-validation, and compare them using the same splits and metric.
Syntax
Classification: model.fit(X, y_class)
Regression: model.fit(X, y_numeric)
Clustering: labels = model.fit_predict(X)
Example
Compare logistic regression, a decision tree, and a tree ensemble for the same classification task.
Code example
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=200, random_state=42)
model.fit(X_train, y_train)
predictions = model.predict(X_valid)
Diagram
Features → Algorithm / learned parameters → Predictions → Evaluation
Key Points
- Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs
- Keep test data untouched until final evaluation.
Q24Algorithms
How does k-means clustering work?
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune ca...
Answer
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune candidates with cross-validation, and compare them using the same splits and metric.
Syntax
KMeans(n_clusters=k, n_init=10, random_state=42)
Example
Compare logistic regression, a decision tree, and a tree ensemble for the same classification task.
Code example
from sklearn.cluster import KMeans
model = KMeans(n_clusters=4, n_init=10, random_state=42)
labels = model.fit_predict(X_scaled)
Diagram
Features → Algorithm / learned parameters → Predictions → Evaluation
Key Points
- Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs
- Keep test data untouched until final evaluation.
Q25Algorithms
What is DBSCAN?
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune ca...
Answer
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune candidates with cross-validation, and compare them using the same splits and metric.
Syntax
Classification: model.fit(X, y_class)
Regression: model.fit(X, y_numeric)
Clustering: labels = model.fit_predict(X)
Example
Compare logistic regression, a decision tree, and a tree ensemble for the same classification task.
Code example
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=200, random_state=42)
model.fit(X_train, y_train)
predictions = model.predict(X_valid)
Diagram
Features → Algorithm / learned parameters → Predictions → Evaluation
Key Points
- Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs
- Keep test data untouched until final evaluation.
Q26Algorithms
What is PCA?
Principal Component Analysis projects centered data onto orthogonal directions ordered by explained variance. It can reduce correlated dimensions, but...
Answer
Principal Component Analysis projects centered data onto orthogonal directions ordered by explained variance. It can reduce correlated dimensions, but components may be harder to interpret and scaling often matters.
Syntax
PCA(n_components=0.95) # retain 95% of variance
Example
Compress correlated sensor measurements into a smaller set of principal components.
Code example
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.decomposition import PCA
pca = make_pipeline(StandardScaler(), PCA(n_components=0.95))
X_reduced = pca.fit_transform(X_train)
Diagram
Features → Algorithm / learned parameters → Predictions → Evaluation
Key Points
- Principal Component Analysis projects centered data onto orthogonal directions ordered by explained variance
- Keep test data untouched until final evaluation.
Q27Algorithms
What is an artificial neural network?
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune ca...
Answer
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune candidates with cross-validation, and compare them using the same splits and metric.
Syntax
Classification: model.fit(X, y_class)
Regression: model.fit(X, y_numeric)
Clustering: labels = model.fit_predict(X)
Example
Compare logistic regression, a decision tree, and a tree ensemble for the same classification task.
Code example
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=200, random_state=42)
model.fit(X_train, y_train)
predictions = model.predict(X_valid)
Diagram
Features → Algorithm / learned parameters → Predictions → Evaluation
Key Points
- Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs
- Keep test data untouched until final evaluation.
Q28Algorithms
What is reinforcement learning?
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune ca...
Answer
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune candidates with cross-validation, and compare them using the same splits and metric.
Syntax
Classification: model.fit(X, y_class)
Regression: model.fit(X, y_numeric)
Clustering: labels = model.fit_predict(X)
Example
Compare logistic regression, a decision tree, and a tree ensemble for the same classification task.
Code example
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=200, random_state=42)
model.fit(X_train, y_train)
predictions = model.predict(X_valid)
Diagram
Features → Algorithm / learned parameters → Predictions → Evaluation
Key Points
- Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs
- Keep test data untouched until final evaluation.
Q29Algorithms
What is regularization?
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune ca...
Answer
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune candidates with cross-validation, and compare them using the same splits and metric.
Syntax
Classification: model.fit(X, y_class)
Regression: model.fit(X, y_numeric)
Clustering: labels = model.fit_predict(X)
Example
Compare logistic regression, a decision tree, and a tree ensemble for the same classification task.
Code example
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=200, random_state=42)
model.fit(X_train, y_train)
predictions = model.predict(X_valid)
Diagram
Features → Algorithm / learned parameters → Predictions → Evaluation
Key Points
- Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs
- Keep test data untouched until final evaluation.
Q30Algorithms
L1 vs L2 regularization
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune ca...
Answer
Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs. Establish a baseline, tune candidates with cross-validation, and compare them using the same splits and metric.
Syntax
Classification: model.fit(X, y_class)
Regression: model.fit(X, y_numeric)
Clustering: labels = model.fit_predict(X)
Example
Compare logistic regression, a decision tree, and a tree ensemble for the same classification task.
Code example
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=200, random_state=42)
model.fit(X_train, y_train)
predictions = model.predict(X_valid)
Diagram
Features → Algorithm / learned parameters → Predictions → Evaluation
Key Points
- Choose an algorithm based on target type, data size, feature representation, interpretability, latency, and error costs
- Keep test data untouched until final evaluation.