Kaggle competition: Plant Seedlings Classification
testing_set[columns_impute_test[17]].value_counts()<filter>
%reload_ext autoreload
%autoreload 2
%matplotlib inline
testing_set[testing_set[columns_impute_test[17]].isnull() ][["BsmtFinType1","GarageCond","GarageQual","BldgType"]]<data_type_conversions>
from fastai import *
from fastai.vision import *
import os
import pandas as pd
from fastai.metrics import error_rate
testing_set[columns_impute_test[17]].fillna(value="Fa",inplace=True )<count_values>
train_dir = '.. /input/plant-seedlings-classification/train/'
test_dir = '.. /input/plant-seedlings-classification/test/'
testing_set[columns_impute_test[18]].value_counts()<filter>
tfms = get_transforms()
data = ImageDataBunch.from_folder(
 path = train_dir,
test=".. /test",
valid_pct = 0.2,
bs = 16,
size = 336,
ds_tfms = tfms,
num_workers = 0
).normalize(imagenet_stats)
 data
print(data.classes)
 data.show_batch()
testing_set[testing_set[columns_impute_test[18]].isnull() ][["BsmtFinType1","GarageCond","GarageQual","BldgType"]]<data_type_conversions>
learn = cnn_learner(data, models.resnet152, metrics=accuracy, model_dir="/tmp/models" )
testing_set[columns_impute_test[18]].fillna(value="Fa",inplace=True )<count_values>
learn.fit_one_cycle(3 )
testing_set[columns_impute_test[19]].value_counts()<filter>
interp = ClassificationInterpretation.from_learner(learn )
testing_set[testing_set[columns_impute_test[19]].isnull() ][["BldgType","GarageType"]]<count_values>
class_score, y = learn.get_preds(DatasetType.Test)
 class_score = np.argmax(class_score, axis=1 )
testing_set[testing_set["BldgType"]=="TwnhsE"][columns_impute_test[19]].value_counts()<feature_engineering>
predicted_classes = [data.classes[i] for i in class_score]
predicted_classes[:10]
testing_set.loc[(testing_set[columns_impute_test[19]].isnull())&(testing_set["BldgType"] == "1Fam"),"GarageType"] = "Attchd"
testing_set.loc[(testing_set[columns_impute_test[19]].isnull())&(testing_set["BldgType"] == "Duplex"),"GarageType"] = "Detchd"
testing_set.loc[(testing_set[columns_impute_test[19]].isnull())&(testing_set["BldgType"] == "2fmCon"),"GarageType"] = "Detchd"
testing_set.loc[(testing_set[columns_impute_test[19]].isnull())&(testing_set["BldgType"] == "Twnhs"),"GarageType"] = "Detchd"
testing_set.loc[(testing_set[columns_impute_test[19]].isnull())&(testing_set["BldgType"] == "TwnhsE"),"GarageType"] = "Attchd"<count_values>
submission = pd.DataFrame({
"file": os.listdir(test_dir),
"species": predicted_classes
})
 submission.to_csv("submission_resnet152.csv", index=False)
 submission[:10]