+ 2

Machine Learning - Bob the builder task - How to make???

Im stucked. Please help!!! Task to build a LogisticRegression model. My code looks working. But anyway Im passing only 4 test. 5th and 6th - not passed. It is hidded. And I dont know whats wrong and how to fix. Tried different things, but not successful. Who has passed this? Pls give advice import pandas as pd from sklearn.linear_model import LogisticRegression n = input() n_split= n.split() n_int = int(n_split[0]) X = [] for i in range(n_int): first, second = input().split() first= int(first) second = int(second) X.append([first,second]) y= [] for i in input().split(): i = int(i) y.append(i) x1,x2 = input().split() x1,x2 = int(x1), int(x2) x_pred = [x1, x2] model = LogisticRegression() model.fit(X,y) print(model.predict([x_pred])[0])

20th Dec 2020, 7:58 PM
Alexey Shikanov
Alexey Shikanov - avatar
19 Answers
+ 12
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 with this
29th Jan 2022, 3:22 PM
Sanjai R
+ 6
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) Pr = model.predict([datapoint]) print(Pr[0])
1st Mar 2022, 7:55 PM
Alcino Castelo
+ 4
Thank you guys for your codes. But is it possible to check where does mine code is wrong? How to improve it?
5th Jan 2021, 5:21 AM
Alexey Shikanov
Alexey Shikanov - avatar
+ 4
solved i tried similar code as yours and had the same problem : test 1:2:3m4 would pass test 5 and 6 would fail . i found the solution quite accidently. i reset code and found that sololearn has modified the starting code. they have introduced float instead of int also they have introduced a loop to read x values now the code works
26th Jan 2021, 9:08 PM
LKScoder
LKScoder - avatar
+ 3
Shubhi Srivastava Did you know what inputs data? Inputs, in this case, are points on the graph. So these points can be like (1.2, 3.1). Do you get it?
5th Jun 2021, 7:49 AM
Abhishek Kumar
Abhishek Kumar - avatar
+ 2
Kindly Explain this Priyanshu mam , use comments to " highlight the workflow in the code"
4th Jan 2021, 8:18 AM
Madhavan R.
Madhavan R. - avatar
+ 1
Okay great! Happy to help you! Shubhi Srivastava
9th Jun 2021, 2:30 PM
Abhishek Kumar
Abhishek Kumar - avatar
+ 1
from sklearn.linear_model import LogisticRegression 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()] # make your model. model = LogisticRegression() model.fit(X,y) y_pred = model.predict([datapoint]) print(y_pred[0])
10th Aug 2022, 11:46 AM
Mohammed Khalid Hamadameen
Mohammed Khalid Hamadameen - avatar
+ 1
I have tried with this and it's giving answer 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) prediction=model.predict([datapoint]) print(prediction[0])
21st Aug 2023, 3:16 PM
Nagesh Datar
Nagesh Datar - avatar
0
In the first loop try to change int(first) to float(first) same for x_pred
6th Jan 2021, 7:02 AM
Andrey Kurdyubov
Andrey Kurdyubov - avatar
0
I have tried, but result is the same.. anyway, thanks for concern.
6th Jan 2021, 7:43 AM
Alexey Shikanov
Alexey Shikanov - avatar
0
Thank you!!!
27th Jan 2021, 3:12 AM
Alexey Shikanov
Alexey Shikanov - avatar
0
why we have used float variable? I mean what's the use of it? anybody please explain
3rd Jun 2021, 8:16 AM
Shubhi Srivastava
Shubhi Srivastava - avatar
0
Abhishek Kumar okay I get it... Thank you so much
8th Jun 2021, 6:41 PM
Shubhi Srivastava
Shubhi Srivastava - avatar
0
None of the following answers was working for current version. After whole day of trying, copying, deleting, and trying again I've found the answer! Here's the code: 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 LinearRegression model = LinearRegression() model.fit(X, y) pred = model.predict([datapoint]) print(int(pred[0] >= 0.41 or pred[0] <= -0.41)) To solve case 3, and 6 I had to tweak the parameter in the last print point by point. The thing is, this predict returned float numbers, and I had to find where were the breaking point between 0, and 1. I wasn't fun, but after all I'm pretty proud of myself. ^^
23rd Dec 2022, 8:18 PM
Radosław Krośnicki
0
Guys, can someone explain why we put "datapoint" in [ ] and then why we do this [0]? Don't understand;(
11th Jan 2023, 8:47 PM
Gadzhi
Gadzhi - avatar
- 1
Алексей Шиканов , show your code so somebody can help you.
20th Dec 2020, 8:18 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
- 1
I would expect a value error for case 5 (too many values to unpack), but I don't know, why it wouldn't pass case 6.
22nd Dec 2020, 3:11 PM
Tenupz
- 1
from sklearn.linear_model import LogisticRegression 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 = LogisticRegression() model.fit(X, y) print(*model.predict([datapoint]))
9th Nov 2022, 1:08 PM
Виталий Меншиков
Виталий Меншиков - avatar