Kaggle competition: What's Cooking? (Kernels Only)
<SOS> metric: CategorizationAccuracy Kaggle data source: whats-cooking?-(kernels-only)<find_best_params>
print(os.listdir(".. /input"))
for run in np.arange(1, runs + 1):
magic_number = K *(10 **(RADIUS - N_NEIGHBORS + 1)) // run
print(f'Run
for step, ids in tqdm_notebook(enumerate(neighbors[:magic_number], 1), total=magic_number):
if step % 10 ** 6 == 0:
new_total_score = path_score(path)
 last_improvement = total_score - new_total_score
print(f"score {new_total_score:.2f} | last 10^6 {last_improvement:.2f} | total {initial_score - new_total_score:.2f}.")
 print(cases_improved[run - 1])
 total_score = new_total_score
if last_improvement > K:
make_submission(f'frunkopt_{path_score(path):.4f}', path)
 idx = sorted(path_index[ids])
 new_idx = idx - idx[0]
pslice = slice(idx[0], idx[-1] + 2)
 chunk = path[pslice]
best_score = chunk_score(chunk, idx[0])
 best_move = -1
for move_type in numba.prange(1, frunkopt_moves_count):
new_chunk = chunk.copy()
frunkopt_move(new_chunk, new_idx, move_type)
 new_score = chunk_score(new_chunk, idx[0])
 if new_score < best_score:
best_score = new_score
best_move = move_type
best_chunk = new_chunk.copy()
if best_move > -1:
path[pslice] = best_chunk
path_index = np.argsort(path[:-1])
 cases_improved[run - 1, best_move] += 1 
<compute_test_metric>
train = pd.read_json('.. /input/train.json')
 test = pd.read_json('.. /input/test.json')
 train['cuisine'].value_counts() [:5]
total_score = path_score(path)
 print(f'Total improvement | {initial_score - total_score:.2f}')
 print('Final scores |', path_score_full(path))<compute_test_metric>
dataset = pd.concat([train,test],sort=True)
 ingredients = pd.Series([item for sublist in list(dataset['ingredients'])for item in sublist])\ 
.value_counts()
print(ingredients.head(6))
unique_ing = np.array(ingredients.index)
 print('
',len(unique_ing),'ingrédients différents en tout' )
make_submission(f'final_frunkopt_{path_score(path):.4f}', path )<feature_engineering>
vect = TfidfVectorizer(tokenizer=lambda x: [i.strip() for i in x.split(',')], lowercase=False)
 vect.fit(dataset['ingredients'].apply(','.join))
Xtf_train = vect.transform(train['ingredients'].apply(','.join)).toarray()
Xtf_train = pd.DataFrame(Xtf_train,columns=vect.get_feature_names())
 Xtf_test = vect.transform(test['ingredients'].apply(','.join)).toarray()
Xtf_test = pd.DataFrame(Xtf_test,columns=vect.get_feature_names())
 print(Xtf_train.shape,Xtf_test.shape)
 lb = LabelEncoder()
target = train['cuisine']
y_train = lb.fit_transform(target)
 print(y_train.shape )
t0 = time.time()<install_modules>
svc = LinearSVC()
print(cross_val_score(svc,Xtf_train,y_train,cv=3))
!conda install -y --channel numba numba<install_modules>
svc.fit(Xtf_train,y_train)
 y_predict = svc.predict(Xtf_test)
 y_string = lb.inverse_transform(y_predict )
<set_options><EOS> 
my_submission = pd.DataFrame({'id':test['id'],'cuisine':y_string})
 my_submission.to_csv('submission.csv', index=False )