There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply () below!

Agree with a comment or answer? Like () to up-vote the contribution!

I agree that you should be getting the numbers without the long tails. I (and it seems many other users) used
i / 10 for i in range (-100,101) while the authors used:
i * 0.1 for i in range…

Yes you can/should read about floating points & why that happened, but I am wondering why the authors don’t correct this as our method finds a lower error AND the list comprehension creates the desired list (-10 to 10 in .1 increments)
Thoughts CA community?

I’m trying to run this calculate errors function over a list of data points in the Reggie’s linear regression exercise.

I seem to be able to create lists that take x and y coordinates out of the list but I can’t get the error to sum correctly.

I think it’s because the variable “line_value” is not iterating.

The expected output for the below code is 0. I get an answer of 12.

Here is my code:

`#Write your calculate_all_error function here
def calculate_all_error(m, b, points):
x_value = [x[0] for x in points]
y_value = [y[1] for y in points]
for i in x_value:
total_error = 0
line_value = m * i + b
print(line_value)
for z in y_value:
total_error += abs((line_value - z))
return total_error
#every point in this dataset lies upon y=x, so the total error should be zero:
datapoints = [(1, 1), (3, 3), (5, 5), (-1, -1)]
print(calculate_all_error(1, 0, datapoints))`

Hey there, I am trying to run this code on my own compiler (I use PyCharm) and I downloaded the necessary file, but I still cant run my code, because of the exam file, which must be imported. I downloaded the file, but it still doesnt work.

This is the code:

import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
from exam import hours_studied, passed_exam
from plotter import plot_data
# Create linear regression model
model = LinearRegression()
model.fit(hours_studied,passed_exam)
# Plug sample data into fitted model
sample_x = np.linspace(-16.65, 33.35, 300).reshape(-1,1)
probability = model.predict(sample_x).ravel()
# Function to plot exam data and linear regression curve
plot_data(model)
# Show the plot
plt.show()
# Define studios and slacker here
slacker = -0.1
studious = 1.1

This is my error:

Traceback (most recent call last):
File "D:/Python Projekte/script.py", line 5, in <module>
from exam import hours_studied, passed_exam
ImportError: cannot import name 'hours_studied' from 'exam' (D:\Python Projekte\venv\lib\site-packages\exam\__init__.py)