+ 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
9 Respuestas
+ 12
https://code.sololearn.com/c0fb9Ljgu2vH/?ref=app
https://code.sololearn.com/cA10A1a3872a/?ref=app
https://code.sololearn.com/cOBHO0WQxjq5/?ref=app
https://code.sololearn.com/c1GK2DxdJ4Sz/?ref=app
+ 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])))
+ 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])
+ 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])
+ 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
+ 1
Tasnim Hamdouni what is the difference between
np.array(datapoint).reshape(1,2)
And
[datapoint]
+ 1
Datapoint=object and np.array = ([array.data]) I understood ?
0
Can you please show your attempt please??
0
I have added my attempt with the question.