![]() Exam Score')įrom the plot we can see that the relationship does appear to be linear. We can create a simple scatterplot to view the relationship between the two variables: import matplotlib.pyplot as plt DataFrame()īefore we fit a simple linear regression model, we should first visualize the data to gain an understanding of it.įirst, we want to make sure that the relationship between hours and score is roughly linear, since that is an underlying assumption of simple linear regression. The following code shows how to create this fake dataset in Python: import pandas as pdĭf = pd. We’ll attempt to fit a simple linear regression model using hours as the explanatory variable and exam score as the response variable. ![]() Step 1: Load the Dataįor this example, we’ll create a fake dataset that contains the following two variables for 15 students: This tutorial provides a step-by-step explanation of how to perform simple linear regression in Python. This equation can help us understand the relationship between the explanatory and response variable, and (assuming it’s statistically significant) it can be used to predict the value of a response variable given the value of the explanatory variable. b 0: The intercept of the regression line. ![]() This technique finds a line that best “fits” the data and takes on the following form: Simple linear regression is a technique that we can use to understand the relationship between a single explanatory variable and a single response variable. ![]()
0 Comments
Leave a Reply. |