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, 2019 in Python by Kashish
365 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, 2019 by Harish

Related Questions In Python

0 votes
1 answer

Error saying "TypeError: range() integer end argument expected"

Try this: [x * 0.01 for x in ...READ MORE

answered May 27, 2019 in Python by Keshav
165 views
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, 2019 in Python by Noel Deepak Palle
1,214 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, 2019 in Python by Alisha
2,535 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, 2019 in Python by Mir
1,146 views
0 votes
1 answer
+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, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 756 views
0 votes
0 answers
+4 votes
6 answers
0 votes
1 answer
0 votes
2 answers

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

A TypeError can occur if the type ...READ MORE

answered Feb 5 in Python by lovelmark
• 160 points
1 flag 1,494 views