...

/

Visualizing Machine Learning Predictions

Visualizing Machine Learning Predictions

Break down the components of visualizing machine learning predictions.

As part of business intelligence efforts, machine learning (ML) models are often used for forecasting and better identifying the factors behind certain relationships.

Let's take a look at a brief example of how to visualize machine learning predictions using the Tips dataset from the Plotly package. Here, we're training a simple linear regression model on the Tips dataset to predict the tips of a restaurant from the total bill that groups paid. We print the R-squared score, also known as the coefficient of determination, to identify the performance of the model on the dataset.

Press + to interact
import numpy as np
import plotly.express as px
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt
#Load the data
df = px.data.tips()
#Reshape the x-variable to use for training
X = df.total_bill.values.reshape(-1, 1)
#Define the Linear Reg model
model = LinearRegression()
#Train the model on the Total Bills variable to predict Tips
model.fit(X, df.tip)
#Print the R-squared socre of the model
print(model.score(X, df.tip))

Let's now take a look at two fundamental data visualizations that ...