-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChapter14_WineEarlyStop.py
More file actions
33 lines (25 loc) · 950 Bytes
/
Copy pathChapter14_WineEarlyStop.py
File metadata and controls
33 lines (25 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from keras.models import Sequential
from keras.layers import Dense
from keras.callbacks import EarlyStopping
import pandas as pd
import numpy
import os
import matplotlib.pyplot as plt
import tensorflow as tf
seed = 0
numpy.random.seed(seed)
tf.set_random_seed(seed)
df_pre = pd.read_csv('./006958/deeplearning/dataset/wine.csv', header=None)
df = df_pre.sample(frac=0.15)
dataset = df.values
X = dataset[:, 0:12]
Y = dataset[:, 12]
model = Sequential()
model.add(Dense(30, input_dim=12, activation='relu'))
model.add(Dense(12, activation='relu'))
model.add(Dense(8, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
early_stopping_callback = EarlyStopping(monitor='val_loss', patience=100)
model.fit(X, Y, validation_split=0.2, epochs=2000, batch_size=500, callbacks=[early_stopping_callback])
print("\n Accuracy: %.4f" % (model.evaluate(X, Y)[1]))