Requires Higher Precision But otherwise correct Help?

I’ve written code for the sea-level predictor challenge but it keeps failing see error below

Expected different line for first line of best fit.
(shapes (170,), (171,) mismatch)
x: array([-0.542124 , -0.4790794, -0.4160349, -0.3529903, -0.2899457,
-0.2269011, -0.1638565, -0.1008119, -0.0377674, 0.0252772,
0.0883218, 0.1513664, 0.214411 , 0.2774556, 0.3405002,…
y: array([-0.542124 , -0.4790794, -0.4160349, -0.3529903, -0.2899457,
-0.2269011, -0.1638565, -0.1008119, -0.0377674, 0.0252772,
0.0883218, 0.1513664, 0.214411 , 0.2774556, 0.3405002,…

Looking at the test module and the output from my code it wants further decimal precision for example it expects -0.5421240249263661 and my code is providing it -0.54212402 does anyone know how i could increase the accuracy/decimal places of my code?

`import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import linregress

def draw_plot():
# Read data from file
df = pd.read_csv(“epa-sea-level.csv”)

# Create scatter plot
plt.scatter(df['Year'], df['CSIRO Adjusted Sea Level'])

# Create first line of best fit
First_Line = linregress(df['Year'], df['CSIRO Adjusted Sea Level'])
x_1st = np.arange(df["Year"].min(),2050,1)
y_1st = x_1st*First_Line.slope + First_Line.intercept
#print(x_1st, y_1st)
plt.plot(x_1st,y_1st)
# Create second line of best fit
Recent_df = df[df["Year"] >=2000]

Second_Line = linregress(Recent_df['Year'], Recent_df['CSIRO Adjusted Sea Level'])
x_2nd = np.arange(2000,2050,1)
y_2nd = x_2nd*Second_Line.slope +Second_Line.intercept
plt.plot(x_2nd,y_2nd)
# Add labels and title
plt.xlabel('Year')
plt.ylabel('Sea Level (inches)')
plt.title('Rise in Sea Level')

# Save plot and return data for testing (DO NOT MODIFY)
plt.savefig('sea_level_plot.png')
return plt.gca()`

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Safari/537.36

Challenge: Sea Level Predictor

Link to the challenge:

This shape mismatch seems like the first thing to worry about.

1 Like

Cheers just needed to change 2050 to 2051 :laughing:

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.