import tensorflow as tf
import pandas as pd
import matplotlib.pyplot as plt

data = pd.read_csv('dataset/credit-a.csv', header=None)

# print(data.head())
# print(data.iloc[:, -1].value_counts())

x = data.iloc[:, :-1]
y = data.iloc[:, -1].replace(-1, 0)

model = tf.keras.Sequential()
model.add(tf.keras.layers.Dense(4, input_shape=(15,), activation='relu'))
model.add(tf.keras.layers.Dense(4, activation='relu'))
# 将数据映射到0-1之间

# 逻辑函数 sigmoid f(x)=1/(1+e^(-x))
# 适合用于求解分类问题
model.add(tf.keras.layers.Dense(1, activation='sigmoid'))

model.summary()

model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['acc'])

history = model.fit(x, y, epochs=100)

print(history.history.keys())
