Kaggle competition: Leaf Classification
<SOS> metric: MulticlassLoss Kaggle data source: leaf-classification<save_to_csv>
%pylab inline
pred_test = model_f1.predict(X_test)
 print('Saving Predictions')
 sub = pd.DataFrame()
sub['id'] = ids
sub['target'] = pred_test
sub.to_csv('1st_submission.csv' , index = False , float_format ='%.5f' )<load_from_csv>
data = pd.read_csv('.. /input/train.csv')
 parent_data = data.copy()
ID = data.pop('id' )
print('Loading data...')
 data_path = '.. /input/'
train = pd.read_csv(data_path + 'train.csv', dtype={'msno' : 'category',
'source_system_tab' : 'category',
'source_screen_name' : 'category',
'source_type' : 'category',
'target' : np.uint8,
'song_id' : 'category'})
 test = pd.read_csv(data_path + 'test.csv', dtype={'msno' : 'category',
'source_system_tab' : 'category',
'source_screen_name' : 'category',
'source_type' : 'category',
'song_id' : 'category'})
 songs = pd.read_csv(data_path + 'songs.csv',dtype={'genre_ids': 'category',
'language' : 'category',
'artist_name' : 'category',
'composer' : 'category',
'lyricist' : 'category',
'song_id' : 'category'})
 members = pd.read_csv(data_path + 'members.csv',
dtype={'city' : 'category',
'bd' : np.uint8,
'gender' : 'category',
'registered_via' : 'category'}
,parse_dates=["registration_init_time","expiration_date"])
 songs_extra = pd.read_csv(data_path + 'song_extra_info.csv')
 print('Data preprocessing...' )<merge>
y = data.pop('species')
 y = LabelEncoder().fit(y ).transform(y)
 y_cat = to_categorical(y)
 X = StandardScaler().fit(data ).transform(data)
song_cols = ['song_id', 'artist_name', 'genre_ids', 'song_length', 'language']
train = train.merge(songs[song_cols], on='song_id', how='left')
 test = test.merge(songs[song_cols], on='song_id', how='left')
 members['registration_year'] = members['registration_init_time'].apply(lambda x: int(str(x)[0:4]))
members['expiration_year'] = members['expiration_date'].apply(lambda x: int(str(x)[0:4]))
members['expiration_month'] = members['expiration_date'].apply(lambda x: int(str(x)[4:6]))
members['membership_days'] =(members['expiration_date'] - members['registration_init_time'] ).dt.days.astype(int)
<data_type_conversions>
model = Sequential()
model.add(Dense(250, input_dim=192, init='uniform', activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(150, activation='relu'))
model.add(Dropout(0.4))
model.add(Dense(99, activation='softmax'))
model.compile(loss='categorical_crossentropy',optimizer='rmsprop', metrics = ["accuracy"])
 history = model.fit(X, y_cat, batch_size=64, nb_epoch=250, verbose=0, validation_split=0.2 )
<merge><EOS> 
test = pd.read_csv('.. /input/test.csv')
 index = test.pop('id')
 test = StandardScaler().fit(test ).transform(test)
 yPred = model.predict_proba(test)
 yPred = pd.DataFrame(yPred,index=index,columns=sort(parent_data.species.unique()))
fp = open('submission_nn_kernel.csv','w')
 fp.write(yPred.to_csv() )