x_train, x_test, y_train, y_test = load_data(test_size=0.25)
n_epoch=50
model = MLPClassifier(alpha=0.01, batch_size=128, epsilon=1e-08, hidden_layer_sizes=(300,), learning_rate='adaptive',max_iter=500,early_stopping=True)
model.fit(x_train, y_train)
y_pred = model.predict(x_test)
accuracy = accuracy_score(y_true=y_test, y_pred=y_pred)
print(classification_report(y_pred, y_test))
As you can see code is able to find accuracy, classification report, and confusion matrix.
But don’t know in this situation how to plot.
Tried the code below using some online resource. But getting a small error here.
scores_train = []
scores_test = []
epoch = 0
while epoch < n_epoch:
print('epoch: ', epoch)
# SHUFFLING
random_perm = np.random.permutation(x_train.shape[0])
mini_batch_index = 0
while True:
# MINI-BATCH
indices = random_perm[mini_batch_index:mini_batch_index + 128]
model.partial_fit(x_train[indices], y_train[indices], classes=7)
mini_batch_index += 128
if mini_batch_index >= x_train.shape[0]:
break
# SCORE TRAIN
scores_train.append(model.score(x_train, y_train))
# SCORE TEST
scores_test.append(model.score(x_test, y_test))
epoch += 1
plt.plot(scores_train, color='green', alpha=0.8, label='Train')
plt.plot(scores_test, color='magenta', alpha=0.8, label='Test')
plt.title("Accuracy over epochs", fontsize=14)
plt.xlabel('Epochs')
plt.legend(loc='upper left')
plt.show()
The error is :TypeError: only integer scalar arrays can be converted to a scalar index at line
model.partial_fit(x_train[indices], y_train[indices], classes=7)
I know it’s not directly related to Pyorch but I hope if someone can guide me.