Visualizing Machine Learning Predictions
Break down the components of visualizing machine learning predictions.
We'll cover the following...
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 npimport plotly.express as pxfrom sklearn.linear_model import LinearRegressionimport matplotlib.pyplot as plt#Load the datadf = px.data.tips()#Reshape the x-variable to use for trainingX = df.total_bill.values.reshape(-1, 1)#Define the Linear Reg modelmodel = LinearRegression()#Train the model on the Total Bills variable to predict Tipsmodel.fit(X, df.tip)#Print the R-squared socre of the modelprint(model.score(X, df.tip))
Let's now take a look at two fundamental data visualizations that ...