Keras を使用して訓練し、n 桁の 10 進数の i 番目の桁を予測しています。たとえば、入力が 123456 (つまり、n = 6) で i=2 の場合、プログラムは値 4 を見つける必要があります。入力を x_values に保存し、それに対応するトレーニング、テスト、および検証の値を保存します。 x_values の要素は y_values にあります。
# Generate x_values by reading the first column from the csv
from io import StringIO
df = pd.read_csv(dst_path, skipinitialspace=True)
x_values = df['Input']
y_values = df['OutputA'] # OutputA indicates 0th element (i.e., i = 0)
私は2つのモデルを持っています。最初のものは単純な 'relu' で、スカラー入力を受け取り、それを 8 つの「ニューロン」に送ります。その後に、最後の層が 1 つのニューロンです。
# Using Keras to create a simple model architecture
model_1 = tf.keras.Sequential()
# First layer takes a scalar input and feeds it through 8 "neurons". The
# neurons decide whether to activate based on the 'relu' activation function.
model_1.add(keras.layers.Dense(8, activation='relu', input_shape=(1,)))
# Final layer is a single neuron, since we want to output a single value
model_1.add(keras.layers.Dense(1))
# Compile the model using the standard 'adam' optimizer and the mean squared error or 'mse' loss function for regression.
model_1.compile(optimizer='adam', loss='mse', metrics=['mae'])
2 番目のモデルは、16 ニューロン x 32 の深さです (最初のモデルよりかなり大きい)。
model = tf.keras.Sequential()
# First layer takes a scalar input and feeds it through 16 "neurons". The
# neurons decide whether to activate based on the 'relu' activation function.
NUM_NEURONS = 16
model.add(keras.layers.Dense(NUM_NEURONS, activation='relu', input_shape=(1,)))
# The new layers will help the network learn more complex representations
NUM_LAYERS = 30
for layer in range(NUM_LAYERS):
model.add(keras.layers.Dense(NUM_NEURONS, activation='relu'))
# Final layer is a single neuron, since we want to output a single value
model.add(keras.layers.Dense(1))
# Compile the model using the standard 'adam' optimizer and the mean squared error or 'mse' loss function for regression.
model.compile(optimizer='adam', loss="mse", metrics=["mae"])
私の全体的なトレーニング セットには 15000 個のサンプルがあります。入力セットをトレーニング、テスト、検証セットに分割しました。
# Train the model on our training data while validating on our validation set
history_1 = model_1.fit(x_train, y_train, epochs=500, batch_size=64,
validation_data=(x_validate, y_validate))
これらすべての後、損失と平均平均誤差を計算すると、両方とも非常に高くなっています (それぞれ約 8.3 と 2.5)。
この問題を解決する最善の方法は何でしょうか? ネットワークの幅、深さ、またはエポックの値をいじっても、目に見える効果はありませんでした。どんなヒントでも大歓迎です。