import pandas as pd
import numpy as np
from keras.models import Sequential
from keras.layers import Dense, Dropout
from keras.wrappers.scikit_learn import KerasClassifier
from sklearn.model_selection import KFold, cross_val_score

seed = 32
np.random.seed(seed)
dataFile = "~/complete_API_cat_freq_tfidf.csv"

df = pd.read_csv(
    dataFile,
    sep=",",
)
dfL = pd.read_csv(
    "~/complete_malware_class_labels.csv",
    sep="\n",
    header=None,
)

X = df
Y = dfL.loc[:, 0]

Y = pd.get_dummies(Y)
X = X.values
Y = Y.values

# 192 278 64 8
def ann_model():
    model = Sequential()
    model.add(Dense(40, input_dim=60, activation="relu"))
    # model.add(Dropout(0.2))
    model.add(Dense(20, activation="relu"))
    model.add(Dense(8, activation="softmax"))
    model.compile(
        loss="categorical_crossentropy", optimizer="adam", metrics=["accuracy"]
    )
    return model


estimator = KerasClassifier(
    build_fn=ann_model, epochs=100, batch_size=10, verbose=1
)
kfold = KFold(n_splits=8, shuffle=True, random_state=seed)
results = cross_val_score(estimator, X, Y, cv=kfold)

print("Result: %.2f%% (%.2f%%)" % (results.mean() * 100, results.std() * 100))
