+ 1
Hi, I am currently doing Bob the builder machine learning but have not come up with the correct answer. I appreciate your help.
5 Respuestas
+ 2
import numpy as np
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()]
from sklearn.linear_model import LogisticRegression
model = LogisticRegression()
model.fit(X,y)
datapoint = np.array(datapoint).reshape(1,-1)
print(model.predict(datapoint[[0]])[0])
I got answer by this, hope this helps you.
+ 2
This may be too late, but:
datapoint is a 1D array such as [1.0, 2.0].
By adding a second set of brackets, it can be converted to a 2D array of datapoints in order to work with model.predict
for example:
[[1.0, 2.0]]
or
[datapoint] where datapoint = [1.0, 2.0]
model.predict will return a 1D array with the predicted target value(s),
for example:
[1]
Finally, this assignment wants you to print the value of the prediction for the first and only datapoint (index = [0]).
The final line in your code could look like this:
print(model.predict([datapoint])[0])
0
If you would add a link to question as well that will help others look into what is the actual question asking about
0
Hi Priyanshu, I am having error with the last line. It still appears to me that I need to reshape the array. However that was done in the previous line. Do you have another way to solve it? Thanks!
0
This also works:
model =LogisticRegression()
model.fit(X,y)
print(model.predict([datapoint])[0])