CSCC11 Lab 2: Machine Learning Workflow
This lab is to learn the end-to-end machine learning project workflow using K-Nearest
Neighbors regression API from scikit-learn.
Learning Objectives
By the end of this lab, you will be able to:
• Load and explore a real-world dataset
• Visualize data distributions and relationships
• Preprocess data using standardization
• Split data into training and testing sets
• Use cross-validation for hyperparameter tuning
• Evaluate model performance
• Identify underfitting and overfitting in KNN regression model
Prelab
• Read the 10 minutes to pandas documentation.
• Read data preprocessing scikit-learn API: StandardScaler, and train_test_split.
• Read the scikit-learn KNeighborsRegressor, KFold, and metrics.
Background: 𝑲-Nearest Neighbors (KNN) Regression
KNN is a non-parametric model that predicts the target value based on the average of the 𝐾
nearest neighbors in the feature space. The key characteristics of KNN are
• Non-parametric: No assumptions about data distribution or the underlying
regression function form.
• Instance-based: Uses training data directly for predictions
• Sensitive to scale: Distance-based, feature scaling is crucial
• Hyperparameter 𝑲: Controls model complexity
Dataset: California Housing
The California housing dataset contains information about housing districts in California
from the 1990 census.