0

Sololearn Code projet. Where am i wrong?

I spent a lot of time to fix that code but unfortunately I'm unable. Even if the output is 1 or 0 Sololearn says that it is not correct. I want to now why? Thanks. 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) pred = model.predict(X) print(pred[0])

5th Feb 2023, 10:17 PM
Gaoussou Maiga
Gaoussou Maiga - avatar
3 Réponses
+ 1
Here is an updated version of your code: import sklearn from sklearn.linear_model import LogisticRegression n = int(input()) X = [] for i in range(n): row = [float(x) for x in input().split()] X.append(row) y = [int(x) for x in input().split()] datapoint = [float(x) for x in input().split()] model = LogisticRegression() model.fit(X,y) pred = model.predict(X) for p in pred: print(p) new_pred = model.predict([datapoint]) print(new_pred[0])
6th Feb 2023, 6:00 AM
ArsenicolupinIII
0
There is no specific bug that I can see in your code, however, there are a few things you could improve: The input values for X and y are not correctly stored in the arrays. The input function reads the entire line as a string, not separate values. You should use the split() method to split the string into separate values and then convert them to floats or ints. The code is missing an import statement for the scikit-learn library, which would cause an error. You need to add import sklearn at the top of your code. The pred[0] line of code only prints the first prediction from the model, which might not be what you want. If you want to print all the predictions, you can use a for loop to iterate over the pred array and print each value. You also need to call the predict() function with the new data point stored in datapoint to get a prediction for that point.
6th Feb 2023, 6:00 AM
ArsenicolupinIII
0
Yes it is working now, Thanks.
6th Feb 2023, 11:49 PM
Gaoussou Maiga
Gaoussou Maiga - avatar