+ 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))
8 Antworten
+ 1
Well, can you please give an explanation of your own code...
+ 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.'''
+ 1
I mean *correct
0
model.fit(X,y)
print(model.predict(datapoint )[0])
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.
0
fix your last statement like this. do not use int()
print(model.predict(datapoint )[0])
0
Okay, surely. Thnx very much...
0
you can solve this using Logistic regression model, you will get pass the test case correctly