Issue
df = pd.read_csv('../input/etu-ai-club-competition-2/train.csv')
df.shape
(750000,77)
X = df.drop(columns = 'Target')
y = df['Target']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25)
model = MLPRegressor(hidden_layer_sizes = 60, activation = "relu", solver = "adam")
model
model.fit(X_train, y_train)
pr = model.predict(X_test)
pr.shape
(187500,)
model.score(y_test, pr)
ValueError: Expected 2D array, got 1D array instead:
array=[-120.79511811 -394.11307519 -449.59524477 ... -432.46130084 -492.81440014
-753.02016315].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
Just started getting into ml. I dont really understand why I need to have a 2d array to get score or how do I convert mine into one. I did try to reshape it as said in the error but when I do that I get the messages ValueError: X has 1 features, but MLPRegressor is expecting 76 features as input.
and ValueError: X has 187500 features, but MLPRegressor is expecting 76 features as input.
for reshaping into (-1, 1) and (1, -1) respectively.
Solution
The correct way to call the score
method would be:
model.score(X_test, y_test)
Internally, it first computes the predictions and then passes the predictions to a scoring function.
If you want to pass the predictions directly, you need to use one of the scoring functions in the metrics package, as explained here:
https://scikit-learn.org/0.15/modules/model_evaluation.html
Note: you might also want to have a look at the example code in the MLPRegressor
documentation:
https://scikit-learn.org/stable/modules/generated/sklearn.neural_network.MLPRegressor.html
Answered By - Jau A
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.