Building and Evaluating Baseline Regression Models
Introduction to Baseline Models
Now that your data is clean and properly formatted, it's time to build your first machine learning models. In this lesson, we'll focus on creating baseline models—simple models that serve as a point of comparison for more complex models you might build later.
We'll implement two different types of baseline models: Linear Regression and LightGBM. By comparing these two approaches, you'll see how different algorithms handle the same data and which might be more suitable for your specific problem.
Let's begin by preparing our data for modeling!
What is a Baseline Model?
A baseline model is a simple model that helps you understand the minimum level of performance you should expect. It provides a benchmark against which to measure improvements as you try more advanced models.
Model Evaluation Metric: RMSE
To evaluate our models, we'll use the Root Mean Squared Error (RMSE), a common metric for regression problems. RMSE measures the average magnitude of the errors in our predictions, with higher weight given to larger errors. Mathematically, it's defined as:
where:
- is the number of samples,
- is the predicted value for the -th sample,
- is the actual value for the -th sample.
Lower RMSE values indicate better model performance. By comparing the RMSE of our two baseline models, we can determine which one provides a better starting point for further refinement.
Preparing Preprocessed Data for Modeling
In the previous lesson, we cleaned our data by handling missing values and encoding categorical features. Now, we need to organize this preprocessed data into the format required for training machine learning models.
For supervised learning tasks like regression, we need to separate our data into:
- Features (
X): The input variables our model will use to make predictions - Target (
y): The variable we're trying to predict
Let's start by loading our preprocessed data:
Notice that we're using the preprocess function from our scripts module, which encapsulates all the preprocessing steps we learned in the previous lesson. This is good practice, as it keeps our code organized and reusable.
Now, let's prepare our features and target variables:
In this code, we:
- Create our feature matrix
Xby dropping theidcolumn (which isn't useful for prediction) and the target columnListening_Time_minutes - Create our target variable
yby selecting just theListening_Time_minutescolumn - Similarly, prepare our test data as
X_testandy_test
It's crucial to maintain consistency between how we process our training and test data. This ensures that our model will make predictions on data that has the same structure and format as what it was trained on. The preprocess function helps us achieve this consistency.
At this point, the model inputs are:
X: all preprocessed training columns exceptidandListening_Time_minutesy: the training target columnListening_Time_minutesX_test: the test set with the same feature columns asXy_test: the true target values from the test set
This means the model sees only predictor columns in X and X_test, while the target stays separate for training and evaluation.
With our data properly prepared, we're ready to build our first baseline model: Linear Regression.
