So whenever I run my TensorFlow model the margin of error (loss / val_loss) graph is extremely back and fourth and I was wondering how I could stop this /reduce it here is a picture
Graph
here's the code if anyone wants to run it should work fine as long as you have the pips
import pandas as pd
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
import numpy as np
import matplotlib.pyplot as plt
import datetime
import tensorboard
from keras.models import Sequential
from keras.layers import Dense
train_df = pd.read_csv('https://www.dropbox.com/s/ednsabkdzs8motw/ROK%20INPUT%20DATA%20-%20Sheet1.csv?dl=1')
eval_df = pd.read_csv('https://www.dropbox.com/s/irnqwc1v67wmbfk/ROK%20EVAL%20DATA%20-%20Sheet1.csv?dl=1')
train_df['Troops'] = train_df['Troops'].astype(float)
train_df['Enemy Troops'] = train_df['Enemy Troops'].astype(float)
train_df['Damage'] = train_df['Damage'].astype(float)
eval_df['Troops'] = eval_df['Troops'].astype(float)
eval_df['Enemy Troops'] = eval_df['Enemy Troops'].astype(float)
eval_df['Damage'] = eval_df['Damage'].astype(float)
damage = train_df.pop('Damage')
dataset = tf.data.Dataset.from_tensor_slices((train_df.values, damage.values))
test_labels = eval_df.pop('Damage')
test_features = eval_df.copy()
model = keras.Sequential(
[
tf.keras.layers.InputLayer(input_shape = (8,)),
tf.keras.layers.Dense(8, activation='relu'),
tf.keras.layers.Dense(64, activation='relu'),
tf.keras.layers.Dense(64, activation='relu'),
tf.keras.layers.Dense(1),
]
)
model.compile(optimizer='adam', loss='mean_squared_error')
model.summary()
history = model.fit(train_df, damage, validation_split=0.2, epochs=5000)
def plot_loss(history):
plt.plot(history.history['loss'], label='loss')
plt.plot(history.history['val_loss'], label='val_loss')
plt.ylim([0, 2000])
plt.xlabel('Epoch')
plt.ylabel('Error [MPG]')
plt.legend()
plt.grid(True)
plot_loss(history)
plt.show()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…