Lowest price ever! Learn Generative AI for 48% less!
Get my discount+ 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])
19 Answers
+ 11
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
+ 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])
+ 4
Thank you guys for your codes. But is it possible to check where does mine code is wrong? How to improve it?
+ 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
+ 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?
+ 2
Kindly Explain this Priyanshu mam , use comments to " highlight the workflow in the code"
+ 1
Okay great!
Happy to help you! Shubhi Srivastava
+ 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])
+ 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])
0
In the first loop try to change int(first) to float(first)
same for x_pred
0
I have tried, but result is the same.. anyway, thanks for concern.
0
Thank you!!!
0
why we have used float variable? I mean what's the use of it? anybody please explain
0
Abhishek Kumar okay I get it... Thank you so much
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. ^^
0
Guys, can someone explain why we put "datapoint" in [ ] and then why we do this [0]? Don't understand;(
- 1
Алексей Шиканов , show your code so somebody can help you.
- 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.
- 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]))