<jupyter_start><jupyter_text>**Expt6_122021601009_Abhishek_Neural_network_for_classification**<jupyter_code>#importing libraries
import numpy as np #for array operations
import tensorflow as tf #to import tensorflow interfaces
import matplotlib.pyplot as plt #for visualization
import keras
from keras.utils.np_utils import to_categorical
from keras.layers import Dense
from keras.models import Sequential
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()
print("Training data shape: ", x_train.shape)
print("Test data shape", x_test.shape)
image_index = 7777
print(y_train[image_index])
plt.imshow(x_train[image_index], cmap='Greys' )
image_vector_size = 28*28
x_train = x_train.reshape(x_train.shape[0], image_vector_size)
x_test = x_test.reshape(x_test.shape[0], image_vector_size)
num_classes = 10
y_train = to_categorical(y_train, num_classes)
y_test = to_categorical(y_test, num_classes)
print( "First 5 training lables as one-hot encoded vectors:\n", y_train[:5])
image_size = 784 # 28*28
num_classes = 10 # ten unique digits
model = Sequential()
# The input layer requires the special input _shape parameter which should match the shape of
model.add(Dense(units=32, activation='sigmoid', input_shape=(image_size, )))
model.add(Dense(units=num_classes, activation='softmax' ) )
model.summary()
model.compile(optimizer="sgd", loss='categorical_crossentropy', metrics=[ 'accuracy' ])
history = model.fit(x_train, y_train, batch_size=128, epochs=10, validation_split=.3)
loss, accuracy = model.evaluate(x_test, y_test, verbose=False)
history.history
plt.plot(history.history['accuracy'])
plt.plot(history.history[ 'val_accuracy'])
plt.title( 'model accuracy')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(['train','test'], loc='upper_left')
plt.show()
plt.plot(history.history['loss'])
plt.plot(history.history['val_loss'])
plt.title('model_loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train','test'], loc='upper left')
plt.show()<jupyter_output>/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:8: MatplotlibDeprecationWarning: Unrecognized location 'upper_left'. Falling back on 'best'; valid locations are
	best
	upper right
	upper left
	lower left
	lower right
	right
	center left
	center right
	lower center
	upper center
	center
This will raise an exception in 3.3.
{'fraction_non_alphanumeric': 0.12425021422450729, 'fraction_numerical': 0.02099400171379606, 'mean_word_length': 7.521897810218978, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '514865', 'license': 'MIT', 'n_tokens_mistral': 849, 'n_tokens_neox': 795, 'n_words': 185, 'path': 'EXPT_06_122021601009_Abhishek_Neural_network_for_classification (1).ipynb', 'repo_name': 'avs-abhishek123/SoftComputingLab', 'size': '2334'}