|
5 | 5 | from keras.optimizers import RMSprop
|
6 | 6 | import pandas as pd
|
7 | 7 |
|
| 8 | +## 1. Import File |
8 | 9 | data = pd.read_csv("/Users/trailbrazer/Desktop/udemy/DataScience-Python3/mammographic_masses.data.txt", na_values=['?'],
|
9 | 10 | header=None)
|
10 | 11 |
|
| 12 | +## Preprocessing using Pandas |
11 | 13 | data.dropna(inplace=True)
|
12 | 14 |
|
13 | 15 | trainingData = data.iloc[:700, 0:4]
|
|
18 | 20 |
|
19 | 21 | (mnist_train_images, mnist_train_labels), (mnist_test_images, mnist_test_labels) = (trainingData, trainingLabel), (testingData, testingLabel)
|
20 | 22 |
|
| 23 | +#Categorical Labels: For 0 and 1 would be 2. Number of Categories |
21 | 24 | train_labels = keras.utils.to_categorical(mnist_train_labels, 2)
|
22 | 25 | test_labels = keras.utils.to_categorical(mnist_test_labels, 2)
|
23 | 26 |
|
| 27 | +# Model Boiler Plate from Keras, TensorFlow |
24 | 28 | model = Sequential()
|
| 29 | +#Input Layer Must match the input features |
25 | 30 | model.add(Dense(5, activation='relu', input_shape=(4,)))
|
26 | 31 | model.add(Dense(12, activation='relu'))
|
27 | 32 | model.add(Dense(2, activation='softmax'))
|
| 33 | +#Output Categories = 2 must match the number of categories |
| 34 | +#Activation Function = Relu, Softmax is nothing but determining what ouput => classifier |
28 | 35 |
|
| 36 | +# Model Sumaary |
29 | 37 | model.summary()
|
30 | 38 |
|
31 | 39 | model.compile(loss='categorical_crossentropy',
|
32 | 40 | optimizer=RMSprop(),
|
33 | 41 | metrics=['accuracy'])
|
34 | 42 |
|
| 43 | +# Start the training |
35 | 44 | history = model.fit(trainingData, train_labels,
|
36 | 45 | batch_size=100,
|
37 | 46 | epochs=1000,
|
38 | 47 | verbose=2,
|
39 | 48 | validation_data=(testingData, test_labels))
|
40 | 49 |
|
| 50 | +#Evaluates the prediction |
41 | 51 | score = model.evaluate(mnist_test_images, test_labels, verbose=0)
|
| 52 | +# Accuracy and loss |
42 | 53 | print('Test loss:', score[0])
|
43 | 54 | print('Test accuracy:', score[1])
|
0 commit comments