<jupyter_start><jupyter_text>Cargo Data<jupyter_code>folder = 'fashion-mnist-itba-lab-2020q2/'
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')
x_train, x_valid, y_train, y_valid = train_test_split(x, y, test_size = 0.1)
y_train_categorical = to_categorical(y_train)
y_val_categorical = to_categorical(y_valid)
alto = 4
ancho = 8
f, axs = plt.subplots(alto, ancho, figsize=(30,4*alto))
axs = axs.reshape(-1)
for i in range(alto*ancho):
    axs[i].imshow(x_train[i], cmap='gray')
    axs[i].set_title(f'{classes[int(y_train[i])]} - class: {int(y_train[i])}\n{y_train_categorical[i]}')
    axs[i].axis('off')
output_size = 10
model_single_layer = Sequential()
model_single_layer.add(Flatten(input_shape=x_train.shape[1:]))
model_single_layer.add(Dense(256, activation='relu'))
model_single_layer.add(Dense(output_size, name='Salida'))
model_single_layer.add(Dense(10, activation='softmax'))

model_single_layer.summary()
lr = 0.001 
SGD = optimizers.SGD(lr=lr)
model_single_layer.compile(loss = 'categorical_crossentropy', optimizer='Adam', metrics=['accuracy'])
batch_size = 128
model_single_layer.fit(x_train, 
                       y_train_categorical,
                       epochs=50, batch_size=batch_size, 
                       verbose=1, 
                       validation_data = (x_valid, y_val_categorical)
                      )
f, (ax1, ax2) = plt.subplots(1, 2, figsize=(20,6))
ax1.plot(model_single_layer.history.history['loss'], label='train')
ax1.plot(model_single_layer.history.history['val_loss'], label='val')
ax1.set_title('Loss - Cross Entropy')
ax1.legend()
ax2.plot(model_single_layer.history.history['accuracy'], label='train')
ax2.plot(model_single_layer.history.history['val_accuracy'], label='val')
ax2.set_title('Metric - Accuracy')
ax2.legend()
plt.show()
loss, acc = model_single_layer.evaluate(x_valid, y_val_categorical, verbose=0)
print(acc, loss)
# Calculo probabilidades de cada clase para cada observación
test_prediction = model_single_layer.predict(x_test)
print(test_prediction.shape)
# Calculo clase
test_labels = np.argmax(test_prediction, axis = 1)
print(test_labels)<jupyter_output>[3 2 7 ... 2 0 7]<jupyter_text>Armo CSV para submitear<jupyter_code>import pandas
df = pandas.DataFrame(data={"Category": test_labels}).astype(int)
df.to_csv("./submission.csv", sep=',',index=True,  index_label='Id')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15151515151515152, 'fraction_numerical': 0.022222222222222223, 'mean_word_length': 5.820936639118457, 'pattern_counts': {'":': 1, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '468237', 'license': 'MIT', 'n_tokens_mistral': 986, 'n_tokens_neox': 935, 'n_words': 136, 'path': 'Fashion-mnist.ipynb', 'repo_name': 'Andres361/itba-dpl', 'size': '2475'}