Kaggle competition: What's Cooking? (Kernels Only)
<SOS> metric: CategorizationAccuracy Kaggle data source: whats-cooking?-(kernels-only)<save_to_csv>
with open('.. /input/train.json')as json_file:
train_data = json.load(json_file)
 with open('.. /input/test.json')as json_file:
test_data = json.load(json_file)
 cuisines = []
for i in range(0, len(train_data)) :
cuisines.append(train_data[i]['cuisine'])
 cuisines = list(set(cuisines))
ingredients_train = []
for i in range(0, len(train_data)) :
for j in range(0, len(train_data[i]['ingredients'])) :
ingredients_train.append(train_data[i]['ingredients'][j])
 ingredients_train = list(set(ingredients_train))
ingredients_test = []
for i in range(0, len(test_data)) :
for j in range(0, len(test_data[i]['ingredients'])) :
ingredients_test.append(test_data[i]['ingredients'][j])
 ingredients_test = list(set(ingredients_test))
ingredients = list(set(ingredients_train)| set(ingredients_test))
for i in range(0, len(train_data)) :
train_data[i]['cuisine'] = list.index(cuisines, train_data[i]['cuisine'])+ 1
for j in range(0, len(train_data[i]['ingredients'])) :
train_data[i]['ingredients'][j] = list.index(ingredients, train_data[i]['ingredients'][j])+ 1
dataset_submission = pd.DataFrame()
dataset_submission['ID_code'] = dataset_sctp_test_ID_code
dataset_submission['target'] = sctp_predictions_lgbm
dataset_submission.to_csv('lgbm_twoclass_model_submission.csv', index=False )<save_to_csv>
train_features = []
train_targets = []
for i in range(0, len(train_data)) :
train_features.append(train_data[i]['ingredients'])
 train_targets.append([train_data[i]['cuisine']])
 oneHotFeatures = np.zeros(( len(train_data), len(ingredients)))
 for i in range(0, len(train_data)) :
for j in range(0, len(ingredients)) :
if j + 1 in train_data[i]['ingredients']:
oneHotFeatures[i][j] = 1
else:
oneHotFeatures[i][j] = 0
oneHotTargets = np.zeros(( len(train_data), len(cuisines)))
 for i in range(0, len(train_data)) :
for j in range(0, len(cuisines)) :
if j + 1 == train_data[i]['cuisine']:
oneHotTargets[i][j] = 1
else:
oneHotTargets[i][j] = 0
oneHotFeatures = np.int32(oneHotFeatures)
 train_features = oneHotFeatures
oneHotTargets = np.int32(oneHotTargets)
 train_targets = oneHotTargets
dataset_submission = pd.DataFrame()
dataset_submission['ID_code'] = dataset_sctp_test_ID_code
dataset_submission['target'] = sctp_predictions_lgbm_pp
dataset_submission.to_csv('lgbm_pp_twoclass_model_submission.csv', index=False )<train_model>
model = GradientBoostingClassifier(n_estimators=50, max_depth=10)
 model.fit(train_features, train_targets)
print("Notebook Runtime: %0.2f Minutes"%(( time.time() - notebookstart)/60))<set_options>
test_features = []
for i in range(0, len(test_data)) :
test_features.append(test_data[i]['ingredients'])
 oneHotFeatures = np.zeros(( len(test_data), len(ingredients)))
 for i in range(0, len(test_data)) :
for j in range(0, len(ingredients)) :
if ingredients[j] in test_data[i]['ingredients']:
oneHotFeatures[i][j] = 1
else:
oneHotFeatures[i][j] = 0
oneHotFeatures = np.int32(oneHotFeatures)
 test_features = oneHotFeatures
<set_options><EOS> 
predictions = model.predict(test_features)
 cuisinePredictions = []
for i in range(0, len(predictions)) :
cuisinePredictions.append(cuisines[list.index(list(predictions[i]), max(predictions[i])) ])
 ids = np.int32(np.array([test_data[i]['id'] for i in range(0, len(test_data)) ]))
submission = pd.DataFrame(ids, columns={"id"})
 submission['cuisine'] = cuisinePredictions
submission = submission[["id", "cuisine"]]
submission.to_csv('cuisine-prediction-submission-3.csv', index=False )