Search⌘ K

Modeling and Analysis

Explore how to build and evaluate machine learning and deep learning models for regression tasks in data science. Understand training models like linear regression, random forest, and neural networks with TensorFlow. Learn to assess model accuracy using performance metrics such as MAE and MSE to inform data-driven predictions.

In the previous lesson, we discussed data preprocessing techniques to clean and prepare our dataset for modeling. In the end, we split our dataset into datasets for testing and training. In this lesson, we’ll build regression models to predict the tip amount based on various features. We’ll train two traditional ML models and one DL model and then evaluate their performance.

ML models

We’ll use the scikit-learn library to train two ML models. We’ll use regression models because regression always outputs a continuous value.

Linear regression

Let’s start with a simple linear regression model. Linear regression falls under the category of supervised ML algorithms and is utilized to forecast values within a continuous numerical range.

Python 3.10.4
from sklearn.linear_model import LinearRegression
lr_model = LinearRegression()
lr_model.fit(X_train, y_train)
print(lr_model.predict(X_test.head(1)))

Code explanation

  • Line 1: We import the required library.

  • Lines 2–3: The LinearRegression() model is called and then trained using the training input and the corresponding outputs.

  • Line 4: We display the ...