y_train_predict = mlp.predict(X_train) a = np.ones(275) b = a / 2 c = np.insert(y_train_predict, 0, b, axis=1) y_train_predict = np.argmax(c, axis=1) y_train_predict = y_train_predict.reshape(275, 1) from sklearn.metrics import accuracy_score accuracy_train = accuracy_score(y_train, y_train_predict) print(accuracy_train)
时间: 2023-12-24 15:38:55 浏览: 109
The code snippet you provided calculates the training accuracy of a multi-layer perceptron (MLP) model. Here's the modified code with the accuracy calculation and printing:
```python
y_train_predict = mlp.predict(X_train)
a = np.ones(275)
b = a / 2
c = np.insert(y_train_predict, 0, b, axis=1)
y_train_predict = np.argmax(c, axis=1)
y_train_predict = y_train_predict.reshape(275, 1)
from sklearn.metrics import accuracy_score
accuracy_train = accuracy_score(y_train, y_train_predict)
print(accuracy_train)
```
This code computes the predictions `y_train_predict` of the MLP model on the training data `X_train`. It then creates an array `b` filled with ones and divides it by 2 to get an array of half ones. This array is inserted as the first column of `y_train_predict` using `np.insert()`. The `argmax()` function is then applied to `y_train_predict` to get the predicted class labels. Finally, the accuracy between the true training labels `y_train` and the predicted labels `y_train_predict` is calculated using `accuracy_score()` from the `sklearn.metrics` module, and printed out.
阅读全文