Can somebody please help me out with the "Bob The Builder" question. Here's my code: | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can somebody please help me out with the "Bob The Builder" question. Here's my code:

import numpy as np from sklearn.linear_model import LinearRegression model=LinearRegression() n = int(input()) X = [] for i in range(n): X.append([float(x) for x in input().split()]) y = [int(x) for x in input().split()] datapoint = [float(x) for x in input().split()] y_array=np.asarray(y) datapoint_array=np.asarray(datapoint) datapoint_array.reshape(-1,1) y_array.reshape(-1,1) model.fit(datapoint_array,y_array) print(model.predict(datapoint_array))

3rd Aug 2021, 7:59 PM
Srijito Ghosh
Srijito Ghosh - avatar
8 Answers
+ 1
Well, can you please give an explanation of your own code...
4th Aug 2021, 7:10 AM
Srijito Ghosh
Srijito Ghosh - avatar
+ 1
from sklearn.linear_model import LinearRegression model=LinearRegression() n = int(input()) X = [] for i in range(n): X.append([float(x) for x in input().split()]) y = [int(x) for x in input().split()] datapoint = [float(x) for x in input().split()] model.fit(X,y) print(int(model.predict([datapoint]))) '''See I did these changes but can't understand why I can't get the test case 3 and 6 incorrect.'''
4th Aug 2021, 9:58 AM
Srijito Ghosh
Srijito Ghosh - avatar
+ 1
I mean *correct
4th Aug 2021, 9:58 AM
Srijito Ghosh
Srijito Ghosh - avatar
0
model.fit(X,y) print(model.predict(datapoint )[0])
3rd Aug 2021, 9:04 PM
▬▬▬
▬▬▬ - avatar
0
You have to output a single value not list. Otherwise sololearn will not accept. For example "[9]" will be invalid but "9" will be okey. so print only first element using [0]. using numpy is not neccessary here. so you can safely delete datapoint_array and y_array.
4th Aug 2021, 9:22 AM
▬▬▬
▬▬▬ - avatar
0
fix your last statement like this. do not use int() print(model.predict(datapoint )[0])
4th Aug 2021, 11:22 AM
▬▬▬
▬▬▬ - avatar
0
Okay, surely. Thnx very much...
4th Aug 2021, 1:33 PM
Srijito Ghosh
Srijito Ghosh - avatar
0
you can solve this using Logistic regression model, you will get pass the test case correctly
21st May 2022, 1:09 PM
Poornima