Python error: Typeerror: 'numpy.float64' Object is not iterable

Asked

Viewed 70 times

0

I am having the following problem when compiling this program in google collab: Typeerror: 'numpy.float64' Object is not iterable He points out the error in the line plt.plot([min(X),max(X)],[min(Y_pred), max(Y_pred)], color ='red')

The graph with the dots is printed, but the line is not. What should I do?

The csv file is available at: https://drive.google.com/file/d/1PykpOOdPRm-N1k-hmpKylqSPqqDtsJ0E/view?usp=sharing

import numpy as np
import matplotlib.pyplot as plt


data = pd.read_csv('/content/drive/My Drive/data.csv')
X = data.iloc[:, 0]
Y = data.iloc[:, 1]
print(data)
plt.scatter(X,Y)

X_mean = np.mean(X)
Y_mean = np.mean(Y)

num = 0
den = 0 


for i in range(len(X)):
  num += (X[i]-X_mean)*(Y[i]-Y_mean)
  den += (X[i]-X_mean)**2
  
m = num/den
c = Y_mean - m*X_mean

Y_pred = m*X_mean + c 

plt.scatter(X,Y)
plt.plot([min(X),max(X)],[min(Y_pred), max(Y_pred)], color ='red')
plt.show()
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.