import numpy
#import pandas
from keras.models import Sequential
from keras.layers import Dense
from keras.wrappers.scikit_learn import KerasClassifier
from keras.utils import np_utils
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import KFold
from sklearn.preprocessing import LabelEncoder
from sklearn.pipeline import Pipeline

# fix random seed for reproducibility
seed = 7
numpy.random.seed(seed)

# load dataset
# dataframe = pandas.read_csv("nurvey.csv", header=None)
# dataset = dataframe.values
dataset = numpy.loadtxt('nurvey3600.csv', delimiter=',')
X = dataset[:, 0:24]
Y = dataset[:, 24]

# encode class values as integers
encoder = LabelEncoder()
encoder.fit(Y)
encoded_Y = encoder.transform(Y)
# convert integers to dummy variables (i.e. one hot encoded)
dummy_y = np_utils.to_categorical(encoded_Y)

# define baseline model
def baseline_model():
    model = Sequential()
    model.add(Dense(24, input_dim=24, activation='relu'))
    model.add(Dense(12, activation='relu'))
    model.add(Dense(12, activation='relu'))
    model.add(Dense(8, activation='softmax'))
    model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
    return model

estimator = KerasClassifier(build_fn=baseline_model, epochs=2, batch_size=5)
kfold = KFold(n_splits=4, shuffle=True, random_state=seed)
results = cross_val_score(estimator, X, dummy_y, cv=kfold)
acc = []
acc.append(results.mean()*100)
print("Baseline: %.2f%% (%.2f%%)" % (results.mean()*100, results.std()*100))
print(acc)
