Kaggle competition: Ghouls, Goblins, and Ghosts... Boo!
<SOS> metric: categorizationaccuracy Kaggle data source: ghouls,-goblins,-and-ghosts...-boo!<load_pretrained>
df=pd.read_csv('.. /input/train.csv')
 %matplotlib inline
def read_pickle_from_file(pickle_file):
with open(pickle_file,'rb')as f:
x = pickle.load(f)
 return x
def write_pickle_to_file(pickle_file, x):
with open(pickle_file, 'wb')as f:
pickle.dump(x, f, pickle.HIGHEST_PROTOCOL )<load_from_csv>
y_train = df.pop("type")
 df = pd.get_dummies(df)
 print(df.columns )
train_df = pd.read_csv(f"{folder}train.csv")
 train_df.shape<load_from_csv>
features = ['bone_length', 'rotting_flesh', 'hair_length', 'has_soul',
'color_black', 'color_blood', 'color_blue', 'color_clear',
'color_green', 'color_white']
X = df[features]
id_ = df["id"]
test_df = pd.read_csv(f"{folder}test.csv")
 test_df.shape<define_variables>
features = ["bone_length","rotting_flesh","hair_length","color","has_soul"]
X = df[features]
y = df["type"]
target_columns = [
'question_asker_intent_understanding',
'question_body_critical',
'question_conversational',
'question_expect_short_answer',
'question_fact_seeking',
'question_has_commonly_accepted_answer',
'question_interestingness_others',
'question_interestingness_self',
'question_multi_intent',
'question_not_really_a_question',
'question_opinion_seeking',
'question_type_choice',
'question_type_compare',
'question_type_consequence',
'question_type_definition',
'question_type_entity',
'question_type_instructions',
'question_type_procedure',
'question_type_reason_explanation',
'question_type_spelling',
'question_well_written',
'answer_helpful',
'answer_level_of_information',
'answer_plausible',
'answer_relevance',
'answer_satisfaction',
'answer_type_instructions',
'answer_type_procedure',
'answer_type_reason_explanation',
'answer_well_written'
]
input_columns = [
'question_title',
'question_body',
'answer'
]<feature_engineering>
letype = LE()
y = letype.fit_transform(y_train)
 lecolor = LE()
for df in [train_df, test_df]:
df['domcom'] = df['url'].apply(lambda s: s.split('://')[1].split('/')[0].split('.'))
df['dom_cnt'] = df['domcom'].apply(lambda s: len(s))
df['domcom'] = df['domcom'].apply(lambda s: s + ['none', 'none'])
 for ii in range(0,4):
df['url_'+str(ii)] = df['domcom'].apply(lambda s: s[ii])
 df.drop('domcom', axis = 1, inplace = True )<create_dataframe>
logging.getLogger().setLevel(logging.INFO )
train_feature = pd.DataFrame()
test_feature = pd.DataFrame()<categorify>
classifier = learn.DNNClassifier(hidden_units=[15], n_classes=3)
 classifier.fit(x=X, y=y, max_steps=5500)
 predictions = classifier.predict(X)
 print(accuracy_score(y, predictions))
<import_modules><EOS> 
test_df = pd.read_csv(".. /input/test.csv")
 classifier.fit(x=X, y=y, max_steps=5500)
 test_df = pd.get_dummies(test_df)
 X_test = test_df[features]
id_ = test_df["id"]
pred = classifier.predict(X_test)
 pred = letype.inverse_transform(pred)
 output = pd.DataFrame({"id": id_,"type":pred})
 output.to_csv('ghost_after_getdummies.csv',index=False )