-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverfit.py
56 lines (32 loc) · 1.31 KB
/
overfit.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import tensorflow
from tensorflow import keras
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout
import numpy as np
import pandas as pd
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
df = pd.read_csv("data/processed/train.csv")
test_df = pd.read_csv("data/processed/test.csv")
y = df["Survived"].values
x = df.drop(["Survived"], axis=1).values
test_y = test_df["Survived"].values
test_x = test_df.drop(["Survived"], axis=1).values
x = x.astype("float32")
y = y.astype("float32")
scaler = StandardScaler()
x = scaler.fit_transform(x)
test_x = test_x.astype("float32")
test_y = test_y.astype("float32")
test_x = scaler.fit_transform(test_x)
x, val_x, y, val_y = train_test_split(x,y, test_size=0.3, shuffle=True)
model = Sequential()
model.add(Dense(64, activation="relu"))
model.add(Dropout(0.2))
model.add(Dense(64, activation="relu"))
model.add(Dropout(0.2))
model.add(Dense(1, activation="sigmoid"))
model.compile(loss="binary_crossentropy", optimizer="adam", metrics=["binary_accuracy"])
history = model.fit(x,y, epochs=200, batch_size=64, validation_data = (val_x, val_y), verbose=1).history
model.save("model/overfit/model.h5")
pd.DataFrame.from_dict(history).to_csv("model/overfit/data.csv", index=False)