Logistic Regressionによるニューラルネットを実装したのですが，その正解率が低すぎるので，直したいです．  
入力xはshape(1,64)でyはラベルでshape(1,6)の配列です．バッチサイズやニューロンの数を変えたりと，ハイパラメータを変えてみたのですが，正答率が上がりませんでした．どなたか，正答率を上げるために，どのような方法がいいでしょうか，ご教示の程，よろしくお願い致します．

```

    import torch
    import torch.nn as nn
    import numpy as np
    from bindsnet.network import Network
    from bindsnet.network.nodes import Input, LIFNodes
    from bindsnet.network.topology import Connection
    from bindsnet.network.monitors import Monitor
    from sklearn.model_selection import train_test_split
    from bindsnet.encoding import poisson_loader
    import matplotlib.pyplot as plt
    # モデルの定義
    class LogisticRegression(nn.Module):
    　　def __init__(self, input_size, num_classes):
        　　super(LogisticRegression, self).__init__()
        　　self.linear = nn.Linear(input_size, num_classes)
        　　self.dropout = nn.Dropout(0.5)
    
    　　def forward(self, x):
        　　x = x.view(-1, 64)
        　　return self.linear(x)
    network = Network(dt=1.0)
    input_size = 64
    num_classes = 6
    time = 64     　
    network = Network(dt=1.0)
    _BATCH_SIZE = 300
    num_epochs = 6
    inpt = Input(64, shape=(1,64))
    middle = LIFNodes(900, thresh=-52 + torch.randn(900))
    center = LIFNodes(900, thresh=-52 + torch.randn(900))
    final = LIFNodes(900, thresh=-52 + torch.randn(900))
    output = LIFNodes(6, thresh=-52 + torch.randn(6))
    network.add_layer(inpt, name='A')
    network.add_layer(middle, name='B')
    network.add_layer(center, name='C')
    network.add_layer(final, name='D')
    network.add_layer(output, name='E')
    
    network.add_connection(Connection(inpt, middle, w=torch.randn(inpt.n, middle.n)), 'A', 'B')
    network.add_connection(Connection(middle, center, w=torch.randn(middle.n, center.n)), 'B', 'C')
    network.add_connection(Connection(center, final, w=torch.randn(center.n, final.n)), 'C', 'D')
    network.add_connection(Connection(final, output, w=torch.randn(final.n, output.n)), 'D', 'E')
    network.add_connection(Connection(output, output, w=torch.randn(output.n, output.n)), 'E', 'E')
    # 入力と出力層だけMonitorを作成(電圧とスパイクを記録)
    inpt_monitor = Monitor(obj=inpt, state_vars=("s", "v"), time=500,)
    middle_monitor = Monitor(obj=inpt, state_vars=("s", "v"), time=500,)
    center_monitor = Monitor(obj=inpt, state_vars=("s", "v"), time=500,)
    final_monitor = Monitor(obj=inpt, state_vars=("s", "v"), time=500,)
    out_monitor = Monitor(obj=inpt, state_vars=("s", "v"), time=500,)
    
    # Monitorをネットワークに接続
    network.add_monitor(monitor=inpt_monitor, name="A")
    network.add_monitor(monitor=middle_monitor, name="B")
    network.add_monitor(monitor=center_monitor, name="C")
    network.add_monitor(monitor=final_monitor, name="D")
    network.add_monitor(monitor=out_monitor, name="E")
    
    for l in network.layers:
    　　m = Monitor(network.layers[l], state_vars=['s'], time=time)
    　　network.add_monitor(m, name=l)
    
    npzfile = np.load("C:/Users/name/Desktop/myo-python-1.0.4/myo-armband-nn-master/data/train_set.npz")
    x = npzfile['x']
    y = npzfile['y']
    x_train, x_test = train_test_split(x, test_size=0.3)
    y_train, y_test = train_test_split(y,test_size=0.3)
    # tensor型に変換
    x_train = torch.from_numpy(x_train).float()
    y_train = torch.from_numpy(y_train).float()
    x_train = torch.clamp(x_train,min=0,max=100)
    loader = zip(poisson_loader(x_train * 0.64, time=64), iter(y_train))
    
    training_pairs = []
    for i, (datum, y_train) in enumerate(loader):
        inputs = {'A': datum.repeat(time, 1), 'E_b': torch.ones(time, 1)}
        network.run(inputs=inputs, time=time)
    　　training_pairs.append([network.monitors['E'].get('s').sum(-1), y_train])
    　　network.reset_state_variables()
    　　if (i + 1) % 30 == 0: print('Train progress: (%d / 900)' % (i + 1))
    　　if (i + 1) == 900: print(); break
    
    　　model = LogisticRegression(input_size, num_classes)
    　　criterion = nn.CrossEntropyLoss()   # m2に相当
    　　optimizer = torch.optim.SGD(model.parameters(), lr=0.1)
    # スパイクとラベルのトレーニング
    for epoch in range(num_epochs):
    　　　for i, (s, y_train) in enumerate(training_pairs):
        　　　optimizer.zero_grad()
        　　　output = model(s.float().softmax(0))
        　　　y = torch.reshape(y_train, (-1,))
        　　　y_train = y_train.view(-1, 6)
        　　　y_train = torch.argmax(y_train, dim=-1)
        　　　loss = criterion(output,  y_train.long())
        　　　loss.backward()
        　　　optimizer.step()
    x_test = torch.from_numpy(x_test).float()
    y_test = torch.from_numpy(y_test).long()
    x_test = torch.clamp(x_test, min=0, max=100)
    loader = zip(poisson_loader(x_test * 0.64, time=64), iter(y_test))
    test_pairs = []
    for i, (datum, y_test) in enumerate(loader):
        inputs = {'A': datum.repeat(time, 1), 'E_b': torch.ones(time, 1)}
        network.run(inputs=inputs, time=time)
        test_pairs.append([network.monitors['E'].get('s').sum(-1), y_test])
        network.reset_state_variables()
    
    if (i + 1) % 30 == 0: print('Test progress: (%d / 300)' % (i + 1))
    if (i + 1) == 300: print(); break
    
    correct, total = 0, 0
    for s, y_test in test_pairs:
        output = model(s.float().softmax(0)); _, predicted = torch.max(output.data, 1)
        total += 1
        y_test = torch.argmax(y_test, dim=-1)
        correct += int(predicted == y_test.long())
        accuracy = 100 * correct / total
     print('Accuracy of logistic regression on test examples: %2f %%\n ' % (100 * correct / total))
    
```

トレーニングのaccuracy

```

    Accuracy of logistic regression on train examples: 23.740000 %
    
    Accuracy of logistic regression on train examples: 23.860000 %
    
    Accuracy of logistic regression on train examples: 23.940000 %
    
    Accuracy of logistic regression on train examples: 23.980000 %
    
    Accuracy of logistic regression on train examples: 24.008000 %
    
    Accuracy of logistic regression on train examples: 24.030000 %
    
    Accuracy of logistic regression on train examples: 24.045714 %
    
    Accuracy of logistic regression on train examples: 24.057500 %
    
    Accuracy of logistic regression on train examples: 24.064444 %
    
    Accuracy of logistic regression on train examples: 24.070000 %
    
    Accuracy of logistic regression on train examples: 24.074545 %
    
    Accuracy of logistic regression on train examples: 24.078333 %
    
    Accuracy of logistic regression on train examples: 24.081538 %
    
    Accuracy of logistic regression on train examples: 24.084286 %
                           :
                           :
                           :
    
    Accuracy of logistic regression on train examples: 24.080540 %
    
```
CC BY-SA 4.0
2020-12-21T13:23:05.453
72802
2021-05-05T00:48:34.383
2021-05-05T00:48:34.383
19110
41671
question
python 機械学習 pytorch
Logistic Regressionで実装しましたが，accuracyが20パーセント台と低いです．
もう試していらっしゃるかもしれませんが、パッと思いついたのはこのような作業です。  
・同じような問題に取り組んでいる先行文献の設定に従う  
・データ数がそれほど多くないならnn.Dropout(0.5)をもう少し小さくして0.1～0.2くらいにする  
・accuracyを見ると上昇傾向にはあるので、もう少し長い時間回す  
・もしまだ行っていなかったら、入力データの正規化（例えば、平均を引いて分散で割る）を行う  
・オプティマイザーを変更する。
CC BY-SA 4.0
2021-01-16T16:31:43.433
73352
2021-01-16T16:31:43.433
30785
72802
answer