Python error "TypeError: range() integer end argument expected, got numpy.float64."

0 votes

I'm trying to run the following section of python code

for i in range(0, int(m)):
    y_pred = c + m * X[i]
    ss_t += (Y[i] - mean_y) ** 2
    ss_r += (Y[i] - y_pred) ** 2
    r2 = 1 - (ss_r/ss_t)
    print(r2)

I get the following error

TypeError: range() integer end argument expected, got numpy.float64.
May 27 in Python by Kashish
76 views

1 answer to this question.

0 votes

Hi @Kashish, try something like this:

for i in range(0, int(m)):
    y_pred = c + m * X[i]
    ss_t += (Y[i] - mean_y) ** 2
    ss_r += (Y[i] - y_pred) ** 2
    r2 = 1 - (ss_r/ss_t)
    print(r2)
answered May 27 by Harish

Related Questions In Python

0 votes
1 answer
0 votes
1 answer

i am normalizing the data set iris in python and get the error ::TypeError: 'numpy.float64' object is not callable

TRY THIS   #Nomalisation for i in names:     print(i)   ...READ MORE

answered Aug 19 in Python by Noel Deepak Palle
134 views
0 votes
1 answer

Error saying "TypeError: descriptor object needs an argument"

The error is pretty straight forward, toy ...READ MORE

answered May 28 in Python by Alisha
359 views
0 votes
1 answer

Python error "TypeError: Cannot compare types 'ndarray(dtype=int64)' and 'str'"

Hey @Ashish, change the emotion_map to the ...READ MORE

answered May 30 in Python by Mir
257 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 232 views
+4 votes
6 answers
0 votes
1 answer
0 votes
1 answer

Python error "TypeError: Can't convert 'int' object to str implicitly"

Hey Yamini, you cannot concatenate a string ...READ MORE

answered May 31 in Python by Gargi
241 views