Kaggle competition: Spooky Author Identification
learn.save('stage1-resnet50-mnist' )<load_pretrained>
train = pd.read_csv('.. /input/train.csv')
 test = pd.read_csv('.. /input/test.csv')
 subm = pd.read_csv('.. /input/sample_submission.csv')
learn.load('stage1-resnet50-mnist' )<find_best_params>
train.groupby('author' ).size()
learn.lr_find(num_it=600 )<train_model>
from sklearn import preprocessing
learn.fit_one_cycle(10,slice(1e-5,1e-4/5))<save_model>
le = preprocessing.LabelEncoder()
le.fit(train.author)
 num_of_labels = len(list(le.classes_))
list(le.classes_)
learn.save('stage2-resnet50-mnist' )<set_options>
y_labels = le.transform(train.author)
 y_labels
PATH.ls()<choose_model_class>
le.inverse_transform(y_labels )
interp = ClassificationInterpretation.from_learner(learn )<define_variables>
row, column = np.where(pd.isnull(train))
print(row, column )
test = ImageList.from_folder(TEST)
 test<load_pretrained>
re_tok = re.compile(f'([{string.punctuation}“”¨«»®´·º½¾¿¡§£₤‘’])')
 def tokenize(s): return re_tok.sub(r' \1 ', s ).split()
learn = load_learner(PATH, test=test )<predict_on_test>
n = train.shape[0]
preds, _ = learn.get_preds(ds_type=DatasetType.Test )<define_variables>
TEXT = 'text'
vec = TfidfVectorizer(ngram_range=(1,2), tokenizer=tokenize,
min_df=3, max_df=0.9, strip_accents='unicode', use_idf=1,
smooth_idf=1, sublinear_tf=1)
 trn_term_doc = vec.fit_transform(train[TEXT])
 test_term_doc = vec.transform(test[TEXT] )
probabilities = preds[0].tolist()
[f"{index}: {probabilities[index]}" for index in range(len(probabilities)) ]<prepare_output>
trn_term_doc, test_term_doc
class_score = np.argmax(preds, axis=1 )<load_from_csv>
x = trn_term_doc
test_x = test_term_doc
sample_submission = pd.read_csv(".. /input/digit-recognizer/sample_submission.csv")
 sample_submission.head() 
<define_variables>
def get_model(y):
m = LogisticRegression(C=4, dual=True)
 return m.fit(x, y )
ImageId = [os.path.splitext(p)[0].split('test_')[1] for p in os.listdir(TEST)]
ImageId = [int(path)for path in ImageId]
ImageId = [ID+1 for ID in ImageId]<sort_values>
preds = np.zeros(( len(test), num_of_labels))
m = get_model(y_labels)
 preds = m.predict_proba(test_x )
<save_to_csv><EOS> 
submid = pd.DataFrame({'id': subm["id"]})
 submission = pd.concat([submid, pd.DataFrame(preds, columns = ['EAP','HPL','MWS'])], axis=1)
 submission.to_csv('submission.csv', index=False)