Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import keras
- import numpy as np
- def create_neural_network(input_shape, output_shape):
- model = keras.Sequential()
- model.add(keras.layers.Dense(output_shape, activation='softmax'))
- return model
- def train_neural_network(model, data):
- model.compile(loss='categorical_crossentropy', optimizer='adam')
- model.fit(data, epochs=10)
- def predict_neural_network(model, data):
- predictions = model.predict(data)
- return predictions
- def main():
- # Create the neural network
- model = create_neural_network(input_shape=(784,), output_shape=(10,))
- # Train the neural network
- data = keras.datasets.mnist.load_data()
- x_train = data['x_train']
- y_train = data['y_train']
- model.fit(x_train, y_train, epochs=10)
- # Predict the labels of the test data
- x_test = data['x_test']
- y_test_predictions = model.predict(x_test)
- # Evaluate the model
- accuracy = accuracy_score(y_test, y_test_predictions)
- print('Accuracy:', accuracy)
- if __name__ == '__main__':
- main()
- # 3/30/2023 -Root
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement