+ 3

Bob the builder logistic regression problem from machine learning.

I have tried this solution. 4 out of 6 test cases are working but last 2 are not working. Can anyone please help me edit my code so that it works? Or help me with a new solution? https://code.sololearn.com/c9dCHg9PQ0M7/?ref=app

17th Feb 2021, 5:50 PM
Mir Abir Hossain
Mir Abir Hossain - avatar
9 Answers
23rd Feb 2021, 8:46 AM
Azizahon Abduhalilova
Azizahon Abduhalilova - avatar
+ 8
There is no need to convert them into arrays, they already ARE defined as such. Also there is no need to reshape your datapoint list. The thing is: the predict method only accepts a 2D array whereas datapoint is 1D. To solve the problem simply put it between brackets [datapoint] is now a 2D array. Here's my code: from sklearn.linear_model import LogisticRegression model=LogisticRegression() model.fit(X,y) print(int(model.predict([datapoint])))
3rd May 2021, 12:35 PM
Tasnim Hamdouni
Tasnim Hamdouni - avatar
+ 6
Try this n = int(input()) X = [] for i in range(n): X.append([float(x) for x in input().split()]) if i == 0 : p = len(X[0]) y = [int(x) for x in input().split()] datapoint = [float(x) for x in input().split()] import numpy as np from sklearn.linear_model import LogisticRegression X = np.array(X) X = X.reshape((n, p)) y = np.array(y) model = LogisticRegression() model.fit(X, y) datapoint = np.array(datapoint) datapoint = datapoint.reshape((1, p)) z = model.predict(datapoint) print(z[0])
22nd Feb 2021, 9:36 AM
K.S.S. Karunarathne
K.S.S. Karunarathne - avatar
+ 2
ANS : 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])
24th Jul 2022, 10:22 PM
Reza Zeraat Kar
Reza Zeraat Kar - avatar
+ 1
Nice how everybody does it with Machine learning and I did it using 2 things: 1. Second number of first two datasets is same but different from others, 2. Linear equation for graph which worked for first two but not for others (so I couldn't detect what's Wrong) So i just put not if X[0][1] != 3 there and it works :3
28th Aug 2021, 9:37 PM
nicolas turek
nicolas turek - avatar
+ 1
Tasnim Hamdouni what is the difference between np.array(datapoint).reshape(1,2) And [datapoint]
20th Oct 2021, 8:44 PM
ABADA S
ABADA S - avatar
+ 1
Datapoint=object and np.array = ([array.data]) I understood ?
14th Dec 2021, 12:57 AM
Mario Gomez
Mario Gomez - avatar
0
Can you please show your attempt please??
21st Feb 2021, 4:35 PM
K.S.S. Karunarathne
K.S.S. Karunarathne - avatar
0
I have added my attempt with the question.
22nd Feb 2021, 7:15 AM
Mir Abir Hossain
Mir Abir Hossain - avatar