import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

from sklearn.naive_bayes import MultinomialNB
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.cross_validation import StratifiedKFold
from sklearn.metrics import roc_auc_score

np.random.seed(1337)

from matplotlib import style
style.use('ggplot')
%matplotlib inline

train = pd.read_json("./data/train.json")

train["ingredients"] = train.ingredients.apply(lambda x: " ".join(x))

train.head()

cv = CountVectorizer().fit(train.ingredients)

X = cv.transform(train.ingredients)

y = train.cuisine

"""
Explanation: What's Cooking
This code is for the What's Cooking Kaggle competion. Currently it is just a very simple naive bayes prediction based on the ingredients.
End of explanation
"""


skf = StratifiedKFold(y, n_folds=5)

for train_index, test_index in skf:
    X_train, X_test = X[train_index], X[test_index]
    y_train, y_test = y[train_index], y[test_index]
    clf = MultinomialNB().fit(X_train, y_train)
    print clf.score(X_test, y_test)

"""
Explanation: Test out the model
End of explanation
"""


clf = MultinomialNB().fit(X, y)

test = pd.read_json("./data/test.json")
test["ingredients"] = test.ingredients.apply(lambda x: " ".join(x))

test.head()

X_test = cv.transform(test.ingredients)
test["cuisine"] = clf.predict(X_test)
submit = test[["id", "cuisine"]]

submit.head()

submit.to_csv("submit.csv", index=False)

"""
Explanation: Not great, but it is a pretty simple model!
Make submission file
End of explanation
"""


