# HIDDEN
# Clear previously defined variables
%reset -f
# HIDDEN
import nbinteract as nbi
import numpy as np
Linear Regression¶
What is Regression?¶
In this tutorial, we're going to learn about regression, one of the the most important concepts in machine learning. Simply stated, regression allows us to take some data and make predictions for future data.
Let's suppose we want to figure out whether a new ice cream flavor will be popular. Here, we have some data on past ice cream flavors. Each point is a flavor. The x-axis shows how highly the ice cream texture was rated. The y-axis shows how the highly the flavor was rated overall.
We can expect that the better the texture, the higher the overall rating. We want to fit a line to the data to show that. Regression chooses the best line for us. Try dragging the points around and see how the regression line changes!
texture_rating = np.array([4.5, 5.8, 5.3, 5.5, 6.6, 6.5, 5.7, 5, 5.1])
overall_rating = np.array([5, 5.4, 6, 3.5, 6.5, 5.5, 5.9, 5.5, 5.4])
nbi.scatter_drag(texture_rating,
overall_rating,
options={'xlim': (4, 7),
'ylim': (4, 7),
'xlabel':"Texture Rating",
'ylabel':"Overall Rating",
'title': "Simple Linear Regression"})
That equation above is our regression line. We can use it to make predictions for data we haven't seen before. For example, if I gave you a ice cream that someone rated a 5.0 for texture, you could use the equation above the graph to predict the overall rating.