import pandas as pd
import matplotlib.pyplot as plt
import tensorflow as tf
from sklearn.model_selection import cross_val_score

def load_data():
    apples = pd.read_csv("apple_quality_clean.csv")


    return apples.drop(columns=["Quality"]), apples["Quality"]

X, Y = load_data()
# Convert values from a 0..1 range to a (-1)..1 range
# Conclusion: makes no difference
#X = X.map(lambda x: x*2 - 1)

tf.keras.utils.set_random_seed(42)

model = tf.keras.models.Sequential([
  tf.keras.layers.Dense(1, activation='relu')
])

model.build(input_shape=[None,len(X.columns)])

model.compile(
  optimizer=tf.keras.optimizers.Adam(learning_rate=0.01),
  loss='binary_crossentropy',
  metrics=['accuracy'],
)

history = model.fit(
  X,
  Y,
  batch_size=len(X),
  epochs=200,
  shuffle=True,
  validation_split=0.2
)

# print("10-fold cross validation score:", cross_val_score(model, X, Y, cv=10))

# print("Accuracy", history.history['acc'][-1])
# print(model.score)

plt.plot(history.history['accuracy'])
plt.plot(history.history['val_accuracy'])
plt.xlabel('Iterations')
plt.ylabel('accuracy')
plt.show()
