I'm having issues with my epochs and the accuracy of my runs. The accuracy is all over the place and it has to do with the fact that I want to estimate a number. I want the test to pass if the estimated amount is say +/- 2% or something.
Code:
seed = 7
basepath = '.'
# find the right path for batch ai vs local
outpath = os.path.join (basepath, "out")
if not os.path.exists(outpath):
os.makedirs(outpath)
# Importing the dataset
dataset = pd.read_csv(os.path.join (basepath, 'data.csv'))
# fix random seed for reproducibility
np.random.seed(seed)
#Encode columns using label encoding
#use a new label encoder everytime is important!
vixpercentencoder = LabelEncoder()
dataset['VIX Open Percent'] = responsetimeencoder.fit_transform(dataset['VIX Open Percent'])
fiftydayaverageencoder = LabelEncoder()
dataset['50 day average'] = suppliesgroupencoder.fit_transform(dataset['50 day average'])
twohundreddayaverageencoder = LabelEncoder()
dataset['200 day average'] = suppliessubgroupencoder.fit_transform(dataset['200 day average'])
openingencoder = LabelEncoder()
dataset['opening'] = regionencoder.fit_transform(dataset['opening'])
#routetomarketencoder = LabelEncoder()
#dataset['Route To Market'] = routetomarketencoder.fit_transform(dataset['Route To Market'])
#What are the correlations between columns and target
correlations = dataset.corr()['closing'].sort_values()
#Throw out unneeded columns
dataset = dataset.drop('Date', axis=1)
dataset = dataset.drop('VIX Open', axis=1)
dataset = dataset.drop('VIX Close', axis=1)
dataset = dataset.drop('Ticker', axis=1)
#dataset = dataset.drop('VIX Open Percent', axis=1)
#One Hot Encode columns that are more than binary
# avoid the dummy variable trap
#dataset = pd.concat([pd.get_dummies(dataset['Route To Market'], prefix='Route To Market', drop_first=True),dataset], axis=1)
#dataset = dataset.drop('Route To Market', axis=1)
#Create the input data set (X) and the outcome (y)
X = dataset.drop('closing', axis=1).iloc[:, 0:dataset.shape[1] - 1].values
y = dataset.iloc[:, dataset.columns.get_loc('closing')].values
# Feature Scaling
sc = StandardScaler()
X = sc.fit_transform(X)
# Initilzing the ANN
model = Sequential()
#Adding the input layer
model.add(Dense(units = 8, activation = 'relu', input_dim=X.shape[1], name= 'Input_Layer'))
#Add hidden layer
model.add(Dense(units = 8, activation = 'relu', name= 'Hidden_Layer_1'))
#Add the output layer
model.add(Dense(units = 1, activation = 'sigmoid', name= 'Output_Layer'))
# compiling the ANN
model.compile(optimizer= 'nadam', loss = 'binary_crossentropy', metrics=['accuracy'])
# summary to console
print (model.summary())
#Fit the ANN to the training set
history = model.fit(X, y, validation_split = .20, batch_size = 64, epochs = 25)
# summarize history for accuracy
plt.plot(history.history['acc'])
plt.plot(history.history['val_acc'])
plt.title('model accuracy')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()
# summarize history for loss
plt.plot(history.history['loss'])
plt.plot(history.history['val_loss'])
plt.title('model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'test'], loc='upper left')
plt.show()