<jupyter_start><jupyter_text>Logistic Regression with Keras  Imports<jupyter_code>import keras
from keras.models import Sequential
from keras.layers import Dense, Activation
from keras.datasets import mnist
from keras.utils import np_utils<jupyter_output>Using TensorFlow backend.<jupyter_text>Load the Data<jupyter_code>(x_train, y_train), _ = mnist.load_data()

# Flatten the 28x28 pixel arrays to 784
x_train = x_train.reshape(x_train.shape[0], 28*28)

# We need to one-hot encode the labels
y_train = np_utils.to_categorical(y_train, 10)<jupyter_output><empty_output><jupyter_text>Create the ModelWith Keras, you can build a neural network with very few lines of code.  Here we define a model, add operations to it, and then compile it.<jupyter_code>model = Sequential()

model.add(Dense(10, input_dim=784))
model.add(Activation('softmax'))

model.compile(loss=keras.losses.categorical_crossentropy,
              optimizer=keras.optimizers.Adam(),
              metrics=['accuracy'])<jupyter_output><empty_output><jupyter_text>Try it out!<jupyter_code>%%time
history = model.fit(x_train, y_train, epochs=50, batch_size=1000)<jupyter_output>Epoch 1/50
60000/60000 [==============================] - 1s 23us/step - loss: 8.4475 - acc: 0.4641
Epoch 2/50
60000/60000 [==============================] - 0s 7us/step - loss: 4.8857 - acc: 0.6895
Epoch 3/50
60000/60000 [==============================] - 0s 7us/step - loss: 4.3267 - acc: 0.7253
Epoch 4/50
60000/60000 [==============================] - 0s 8us/step - loss: 3.8405 - acc: 0.7551
Epoch 5/50
60000/60000 [==============================] - 0s 7us/step - loss: 3.0092 - acc: 0.8068
Epoch 6/50
60000/60000 [==============================] - 0s 8us/step - loss: 2.7746 - acc: 0.8222
Epoch 7/50
60000/60000 [==============================] - 0s 7us/step - loss: 2.7132 - acc: 0.8257
Epoch 8/50
60000/60000 [==============================] - 0s 7us/step - loss: 2.6475 - acc: 0.8306
Epoch 9/50
60000/60000 [==============================] - 0s 7us/step - loss: 2.6120 - acc: 0.8327
Epoch 10/50
60000/60000 [==============================] - 0s 8us/step - loss: 2.5895 - acc: 0.8345
Epoch 11[...]
{'fraction_non_alphanumeric': 0.2502325581395349, 'fraction_numerical': 0.12976744186046513, 'mean_word_length': 4.861035422343324, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '114974', 'license': 'MIT', 'n_tokens_mistral': 973, 'n_tokens_neox': 766, 'n_words': 182, 'path': 'Logistic Regression with Keras.ipynb', 'repo_name': 'heegd/FunWithMNIST', 'size': '2150'}