Hi, I am currently doing Bob the builder machine learning but have not come up with the correct answer. I appreciate your help. | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 1

Hi, I am currently doing Bob the builder machine learning but have not come up with the correct answer. I appreciate your help.

https://code.sololearn.com/cI702v96FBId/?ref=app

3rd Jan 2021, 2:10 PM
Juan Pablo Peña Moreno
Juan Pablo Peña Moreno - avatar
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.
4th Jan 2021, 8:03 AM
Priyanshu Saxena
Priyanshu Saxena - avatar
+ 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])
9th Feb 2021, 12:41 AM
Nathan Alston
Nathan Alston - avatar
0
If you would add a link to question as well that will help others look into what is the actual question asking about
3rd Jan 2021, 3:31 PM
Abhay
Abhay - avatar
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!
4th Jan 2021, 2:56 PM
Juan Pablo Peña Moreno
Juan Pablo Peña Moreno - avatar
0
This also works: model =LogisticRegression() model.fit(X,y) print(model.predict([datapoint])[0])
5th Feb 2022, 7:08 PM
keerthi sum
keerthi sum - avatar