Kaggle competition: Fashion MNIST-ITBA-LAB 2020
<SOS> metric: categorizationaccuracy Kaggle data source: fashion-mnist-itba-lab-2020<load_from_csv>
from sklearn.model_selection import train_test_split
from keras.utils import to_categorical
from keras.callbacks import ModelCheckpoint
from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Activation, Flatten
from keras.layers.normalization import BatchNormalization
from keras import optimizers
from keras import initializers
import numpy as np
from matplotlib import pyplot as plt
%%time
train = pd.read_csv('.. /input/train_V2.csv')
 train = reduce_mem_usage(train)
 test = pd.read_csv('.. /input/test_V2.csv')
 test = reduce_mem_usage(test)
 print(train.shape, test.shape )<filter>
classes = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat', 'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']
nullValues = train[train.isnull().any(axis=1)]
nullValues<train_model>
folder = '/kaggle/input/fashion-mnist-itba-lab-2020/'
x = np.load(folder+'train_images.npy')
 y = np.loadtxt(folder+'train_labels.csv', delimiter=',', skiprows=1)
 x_test = np.load(folder+'test_images.npy' )
print('null values:', len(nullValues))
train.dropna(inplace=True )<count_values>
x_train, x_valid, y_train, y_valid = train_test_split(x, y, test_size = 0.1 )
train['matchType'].value_counts()<sort_values>
y_train_categorical = to_categorical(y_train)
 y_val_categorical = to_categorical(y_valid )
corr_matrix = train.corr()
corr_matrix['winPlacePerc'].sort_values(ascending=False )<count_unique_values>
output_size = 10
model_single_layer = Sequential()
model_single_layer.add(Flatten(input_shape=x_train.shape[1:]))
model_single_layer.add(Dense(output_size, name='Salida'))
model_single_layer.add(Activation('softmax'))
model_single_layer.summary()
for c in ['Id', 'groupId', 'matchId']:
print(f'{c} different values:', train[c].nunique() )<count_values>
lr = 0.000001
SGD = optimizers.sgd(lr=lr)
 model_single_layer.compile(loss = 'categorical_crossentropy', optimizer=SGD, metrics=['accuracy'] )
for q in ['maxPlace == numGroups', 'maxPlace != numGroups']:
print(q, ':', len(train.query(q)) )<feature_engineering>
batch_size = 512
model_single_layer.fit(x_train,
y_train_categorical,
epochs=20, batch_size=batch_size,
verbose=1,
validation_data =(x_valid, y_val_categorical)
 )
<feature_engineering>
loss, acc = model_single_layer.evaluate(x_valid, y_val_categorical, verbose=0)
 print(acc, loss )
train['totalDistance'] = train['walkDistance'] + train['rideDistance'] + train['swimDistance']
train['killsWithoutMoving'] =(( train['kills'] > 0)&(train['totalDistance'] == 0))
train.query('killsWithoutMoving == True' ).shape<drop_column>
test_prediction = model_single_layer.predict(x_test)
 print(test_prediction.shape )
train.drop('killsWithoutMoving', axis=1, inplace=True )<drop_column>
test_labels = np.argmax(test_prediction, axis = 1)
 print(test_labels )
train.drop(train.query('Id == "c3e444f7d1289f"' ).index, inplace=True )<drop_column>
df = pandas.DataFrame(data={"Category": test_labels} ).astype(int)
 df.to_csv("./submission.csv", sep=',',index=True, index_label='Id' )