Untitled

mail@pastecode.io avatar
unknown
python
7 months ago
1.1 kB
1
Indexable
Never
# Первый вариант
class Net(nn.Module):
    def __init__(self, n_in_neurons, n_hidden_neurons_1, n_hidden_neurons_2, n_out_neurons):
        super(Net, self).__init__()
        self.fc1 = nn.Linear(n_in_neurons, n_hidden_neurons_1)
        self.act1 = nn.PReLU()
        self.fc2 = nn.Linear(n_hidden_neurons_1, n_hidden_neurons_2)
        self.act2 = nn.ReLU()
        self.fc3 = nn.Linear(n_hidden_neurons_2, n_out_neurons)
        self.act3 = nn.ELU()

    def forward(self, x):
        x = self.fc1(x)
        x = self.act1(x)
        x = self.fc2(x)
        x = self.act2(x)
        x = self.fc3(x)
        x = self.act3(x)
        return x
        
# Второй вариант
neuro_def_model = keras.Sequential([keras.layers.Dense(20, activation='relu', input_shape=(X_train.shape[1],)),

                                    keras.layers.Dense(1)
                                   ])
                                   
neuro_def_model.compile(optimizer='adam', loss='mean_squared_error')
neuro_def_model.fit(X_train, Y_train, epochs=200, batch_size=32, validation_data=(X_test, Y_test))
Leave a Comment