Kaggle competition: Mercari Price Suggestion Challenge
labels = [('cat' if 'cat.' in str(fname)else 'dog')for fname in train_fnames]
labels[:5]<load_pretrained>
df_train = pd.read_csv('/kaggle/input/mercari-price-suggestion-challenge/train.tsv', delimiter='\t')
 df_test = pd.read_csv('/kaggle/input/mercari-price-suggestion-challenge/test_stg2.tsv', delimiter='\t' )
np.random.seed(123)
 data = ImageDataBunch.from_lists(
 path='/kaggle/working/train',
fnames=train_fnames,
labels=labels,
valid_pct=0.2,
ds_tfms=get_transforms(flip_vert=False),
size=224,
bs=32
).normalize(imagenet_stats )<define_variables>
df = pd.concat([df_train, df_test], axis=0)
 df.head()
data.show_batch(rows=3, figsize=(12, 12))<set_options>
nrow_train=df_train.shape[0]
torch.cuda.is_available()<set_options>
y_train = np.log1p(df_train["price"] )
torch.backends.cudnn.enabled<choose_model_class>
del df_train
gc.collect()
learner = cnn_learner(data, models.resnet50, metrics=error_rate ).to_fp16()<find_best_params>
count = CountVectorizer(min_df=10)
 X_name = count.fit_transform(df["name"] )
learner.lr_find(start_lr=1e-6 )<define_search_space>
count_category = CountVectorizer()
df["category_name"] = df["category_name"].fillna("Other" ).astype("category")
 X_category = count_category.fit_transform(df["category_name"] )
max_lr_choice = 5e-4<train_model>
count_descp = TfidfVectorizer(max_features = 50000,ngram_range =(1,3),stop_words = "english")
 df["item_description"] = df["item_description"].fillna("None")
 X_descp = count_descp.fit_transform(df["item_description"] )
learner.fit_one_cycle(4, max_lr=max_lr_choice )<save_model>
df["brand_name"] = df["brand_name"].fillna("unknown")
 pop_brands = df["brand_name"].value_counts().index[:2500]
df.loc[~df["brand_name"].isin(pop_brands), "brand_name"] = "Other"
df["brand_name"] = df["brand_name"].astype("category")
 vect_brand = LabelBinarizer(sparse_output=True)
 X_brand = vect_brand.fit_transform(df["brand_name"] )
learner.save('imgsize224-stage1' )<choose_model_class>
import scipy
interp = ClassificationInterpretation.from_learner(learner )<compute_test_metric>
df["item_condition_id"] = df["item_condition_id"].astype("category")
 X_dummies = scipy.sparse.csr_matrix(pd.get_dummies(df[["item_condition_id", "shipping"]] ).values )
accuracy =(interp.confusion_matrix() [0, 0] + interp.confusion_matrix() [1, 1])/ len(data.valid_ds)
 accuracy<define_variables>
X = scipy.sparse.hstack(( X_dummies,X_category,X_descp,X_brand,X_name)).tocsr()
data_no_split = ImageDataBunch.from_lists(
 path='/kaggle/working/train',
fnames=train_fnames,
labels=labels,
valid_pct=0,
ds_tfms=get_transforms(flip_vert=False),
size=224,
bs=32
).normalize(imagenet_stats )<load_pretrained>
X_train = X[:nrow_train]
model = Ridge(solver = "lsqr", fit_intercept=False)
 model.fit(X_train, y_train)
 model.score(X_train, y_train )
<feature_engineering><EOS> 
X_test = X[nrow_train:]
preds = model.predict(X_test)
 df_test["price"] = np.expm1(preds)
 df_test[["test_id", "price"]].to_csv("submission_ridge.csv", index = False )