Kaggle competition: What's Cooking? (Kernels Only)
<SOS> metric: CategorizationAccuracy Kaggle data source: whats-cooking?-(kernels-only)<load_pretrained>
init_notebook_mode(connected=True)
 %matplotlib inline
arch.load('model-v1' )<train_model>
df_train = pd.read_json('.. /input/train.json')
 df_test = pd.read_json('.. /input/test.json' )
arch.fit_one_cycle(3, max_lr=slice(lr/1000,lr/100))<predict_on_test>
def get_random_colors(n):
lst = []
for i in range(n):
r = lambda: random.randint(0,255)
 lst.append('
return lst
prediction, y = arch.get_preds(ds_type=DatasetType.Test )<load_from_csv>
df_train['joined_ing'] = df_train['ingredients'].apply(lambda x: ' '.join(x ).lower())
 df_test['joined_ing'] = df_test['ingredients'].apply(lambda x: ' '.join(x ).lower() )
test_data = pd.read_csv(output)
 test_data.has_cactus = prediction.numpy() [:, 0]
test_data.head(10 )<save_to_csv>
y_train = df_train['cuisine'].values.tolist()
le = LabelEncoder()
y_train = le.fit_transform(y_train )
test_data.to_csv('submission.csv', index=False )<set_options>
cnt_vec = CountVectorizer()
cnt_vec.fit(df_train['joined_ing'].values.tolist())
 x_train_cnt = cnt_vec.transform(df_train['joined_ing'].values.tolist())
 x_test_cnt = cnt_vec.transform(df_test['joined_ing'].values.tolist() )
%reload_ext autoreload
%autoreload 2
%matplotlib inline<import_modules>
tfidf_vec = TfidfVectorizer(binary=True)
 tfidf_vec.fit(df_train['joined_ing'].values.tolist())
 x_train_tfidf = tfidf_vec.transform(df_train['joined_ing'].values.tolist())
 x_test_tfidf = tfidf_vec.transform(df_test['joined_ing'].values.tolist() )
from fastai import *
from fastai.vision import *<define_variables>
x_train = np.hstack(( x_train_cnt.todense() , x_train_tfidf.todense()))
x_test = np.hstack(( x_test_cnt.todense() , x_test_tfidf.todense()))
bs = 64<define_variables>
model = OneVsRestClassifier(LogisticRegression())
 model.fit(x_train, y_train )
path = Path('.. /input')
 path_train = path/'train/train'
path_test = path/'test/test/'
path, path_train, path_test<load_from_csv>
y_pred = model.predict(x_test )
labels_df = pd.read_csv(path/'train.csv')
 test_df = pd.read_csv(path/'sample_submission.csv')
 labels_df.head()<categorify>
id_test = df_test['id']
y_pred = le.inverse_transform(y_pred )
np.random.seed(42)
 test = ImageList.from_df(test_df, path=path_test)
 data =(
 ImageList.from_df(labels_df, path=path_train)
.split_by_rand_pct(0.01)
.label_from_df() 
.add_test(test)
.transform(get_transforms(
 flip_vert = True, 
), size = 128)
.databunch(path=path, bs = bs ).normalize(imagenet_stats)
 )<define_variables>
df_sub = pd.DataFrame()
df_sub['id'] = id_test
df_sub['cuisine'] = y_pred
df_sub.to_csv('ans_sub.csv', index=False )