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
22 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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

Error saying "TypeError: descriptor object needs an argument"

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

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

Python error "IndentationError: expected an indented block"

Python requires its code to be indented ...READ MORE

answered Jun 17 in Python by Varun

edited Jun 17 10 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
64 views
+4 votes
6 answers
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
31 views
0 votes
1 answer

Python Error "UnicodeEncodeError: 'ascii' codec can't encode character u'\u03b1' in position 20: ordinal not in range(128)"

use the sep argument of to_csv, to delimit by a tab: df.to_csv(file_name, ...READ MORE

answered Jun 13 in Python by Rhea
18 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.