Can someone spot the error please?

username: krishna511
cooked: <pre><code class="lang-auto">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))
</code></pre>
<p>As you can see code is able to find accuracy, classification report, and confusion matrix.<br>
But don’t know in this situation how to plot.<br>
Tried the code below using some online resource. But getting a small error here.</p>
<pre><code class="lang-auto">scores_train = []
scores_test = []


epoch = 0
while epoch &lt; 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 &gt;= 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()
</code></pre>
<p>The error is :TypeError: only integer scalar arrays can be converted to a scalar index at line</p>
<pre><code class="lang-auto">  model.partial_fit(x_train[indices], y_train[indices], classes=7)
</code></pre>
<p>I know it’s not directly related to Pyorch but I hope if someone can guide me.</p>

username: m3tobom_M
cooked: <p>Can you print types and shapes of x_train, y_train? <code>type(x_train), x_train.shape, ...</code></p>

username: eduardo4jesus
cooked: <p>I would recommend providing a minimum working example (MWE)<br>
as a Colab Notebook in a Github Gist. Then people can quickly reproduce the problem.</p>
<p>Also,</p>
<aside class="quote no-group" data-username="krishna511" data-post="1" data-topic="122906">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/krishna511/48/30486_2.png" class="avatar"> krishna511:</div>
<blockquote>
<pre><code class="lang-auto">scores_train = []
scores_test = []


epoch = 0
while epoch &lt; 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 &gt;= 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
</code></pre>
</blockquote>
</aside>
<p>You don’t have to do this manually. You could use <code>from torch.utils.data import DataLoader</code> and drop the last batch. Something like this:</p>
<pre><code class="lang-auto">train_set = VisionDataset(root=path, train=True, download=True, transform=transform)
train_loader = DataLoader(train_set, batch_size, drop_last=True, shuffle=True, num_workers=num_workers, pin_memory=True)
</code></pre>
<p>Then, for training a epoch, you can do something like:</p>
<pre><code class="lang-auto">for inputs, labels in train_loader:
    inputs, labels = inputs.to(self._device), labels.to(self._device)
    ...
</code></pre>

username: krishna511
cooked: <p>Thank you <a class="mention" href="/u/m3tobom_m">@m3tobom_M</a> for reply <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"> The shapes are :</p>
<pre><code class="lang-auto">print(x_train.shape)
(360, 180)
type(x_train)
Out[8]: numpy.ndarray
len(y_train)
Out[7]: 360
 type(y_train)
Out[9]: list
</code></pre>

username: m3tobom_M
cooked: <p>Can you try converting y_train to numpy.array? <code>y_train = np.array(y_train)</code></p>

username: krishna511
cooked: <p>Tried that sir <a class="mention" href="/u/m3tobom_m">@m3tobom_M</a> , not working <img src="https://discuss.pytorch.org/images/emoji/apple/frowning.png?v=9" title=":frowning:" class="emoji" alt=":frowning:"><br>
Actually y_train is a string, y_train[1]=‘class_label’</p>

username: m3tobom_M
cooked: <p>Probably your class labels shouldn’t be a string and should be represented with numbers. I think you should do some research about your task. You can start with reading <code>word embeddings</code>. (I guess).</p>

username: krishna511
cooked: <p><a class="mention" href="/u/m3tobom_m">@m3tobom_M</a> sir My task is classification sir. and MLPClassifier can deal with string type targets.<br>
But this loss and accuracy plot is problem for me now.</p>

username: krishna511
cooked: <p><a class="mention" href="/u/m3tobom_m">@m3tobom_M</a> Sir I am following <a href="https://stackoverflow.com/questions/46912557/is-it-possible-to-get-test-scores-for-each-iteration-of-mlpclassifier#new-answer" rel="noopener nofollow ugc">this</a> link. Changed my x_train, y_train type exactly same they both are</p>
<pre><code class="lang-auto">type(x_train)
Out[10]: numpy.ndarray

type(y_train)
Out[11]: numpy.ndarray
</code></pre>
<p>as in given example.<br>
Now when I m trying its giving error<br>
<code>ValueError: Expected array-like (array or non-string sequence), got 7</code></p>
<p>The complete traceback is</p>
<pre><code class="lang-auto"> model.partial_fit(x_train[indices], y_train[indices], classes=7)

  File "C:\Users\krishna\Anaconda3\lib\site-packages\sklearn\neural_network\_multilayer_perceptron.py", line 1061, in _partial_fit
    if _check_partial_fit_first_call(self, classes):

  File "C:\Users\krishna\Anaconda3\lib\site-packages\sklearn\utils\multiclass.py", line 316, in _check_partial_fit_first_call
    if not np.array_equal(clf.classes_, unique_labels(classes)):

  File "C:\Users\krishna\Anaconda3\lib\site-packages\sklearn\utils\multiclass.py", line 77, in unique_labels
    ys_types = set(type_of_target(x) for x in ys)

  File "C:\Users\krishna\Anaconda3\lib\site-packages\sklearn\utils\multiclass.py", line 77, in &lt;genexpr&gt;
    ys_types = set(type_of_target(x) for x in ys)

  File "C:\Users\krishna\Anaconda3\lib\site-packages\sklearn\utils\multiclass.py", line 243, in type_of_target
raise ValueError('Expected array-like (array or non-string sequence), '

ValueError: Expected array-like (array or non-string sequence), got 7
</code></pre>
<p><a class="mention" href="/u/ptrblck">@ptrblck</a> sir you are my last hope <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>

username: krishna511
cooked: <p>Got the result by just putting</p>
<pre><code class="lang-auto">early_stopping=False,warm_start=True
</code></pre>
<p>in MLPClassifier. Don’t know much about it, but solved the purpose.<br>
Got the result by just putting</p>
<pre><code class="lang-auto">early_stopping=False,warm_start=True
</code></pre>
<p>in MLPClassifier. Don’t know much about it, but solved the purpose.<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/6/9/695513ff4999a67507b147eed7f9111450b6784b.png" alt="image" data-base62-sha1="f1OpDaBQqrIy4xNwQ0sWCVKbFvZ" width="372" height="279"><br>
Thanks</p>