The make_moons dataset is a swirl pattern, or two moons. It is a set of points in 2D making two interleaving half circles. It displays 2 disjunctive clusters of data in a 2-dimensional representation space ( with coordinates x1 and x2 for two features). The areas are formed like 2 moon crescents as shown in the figure below.
from sklearn import datasets
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
numpy is used for scientific computing with Python. It is one of the fundamental packages you will use. Matplotlib library is used in Python for plotting graphs. The datasets package is the place from where you will import the make moons dataset. Sklearn library is used fo scientific computing. It has many features related to classification, regression and clustering algorithms including support vector machines.
0)
np.random.seed(= datasets.make_moons(100, noise=0.10)
feature_set_x, labels_y = train_test_split(feature_set_x, labels_y, test_size=0.33, random_state=42) X_train, X_test, y_train, y_test
In the script above we import the datasets class from the sklearn library. To create non-linear dataset of 100 data-points, we use the make_moons method and pass it 100 as the first parameter. The method returns a dataset, which when plotted contains two interleaving half circles, as shown in the figure below.You can clearly see that this data cannot be separated by a single straight line, hence the perceptron cannot be used to correctly classify this data.
from keras.models import Sequential
## Using TensorFlow backend.
## C:\Users\slaxm\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\tensorflow\python\framework\dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
## _np_qint8 = np.dtype([("qint8", np.int8, 1)])
## C:\Users\slaxm\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\tensorflow\python\framework\dtypes.py:517: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
## _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
## C:\Users\slaxm\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\tensorflow\python\framework\dtypes.py:518: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
## _np_qint16 = np.dtype([("qint16", np.int16, 1)])
## C:\Users\slaxm\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\tensorflow\python\framework\dtypes.py:519: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
## _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
## C:\Users\slaxm\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\tensorflow\python\framework\dtypes.py:520: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
## _np_qint32 = np.dtype([("qint32", np.int32, 1)])
## C:\Users\slaxm\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\tensorflow\python\framework\dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
## np_resource = np.dtype([("resource", np.ubyte, 1)])
## C:\Users\slaxm\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:541: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
## _np_qint8 = np.dtype([("qint8", np.int8, 1)])
## C:\Users\slaxm\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:542: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
## _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
## C:\Users\slaxm\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:543: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
## _np_qint16 = np.dtype([("qint16", np.int16, 1)])
## C:\Users\slaxm\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:544: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
## _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
## C:\Users\slaxm\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:545: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
## _np_qint32 = np.dtype([("qint32", np.int32, 1)])
## C:\Users\slaxm\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:550: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
## np_resource = np.dtype([("resource", np.ubyte, 1)])
from keras.layers import Dense, Activation
= Sequential()
model 50, input_dim=2, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model.add(Dense(compile(loss='binary_crossentropy', optimizer='adam', metrics= ['accuracy']) model.
## WARNING:tensorflow:From C:\Users\slaxm\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\tensorflow\python\ops\nn_impl.py:180: add_dispatch_support.<locals>.wrapper (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.
## Instructions for updating:
## Use tf.where in 2.0, which has the same broadcast rule as np.where
print(model.summary())
## Model: "sequential_1"
## _________________________________________________________________
## Layer (type) Output Shape Param #
## =================================================================
## dense_1 (Dense) (None, 50) 150
## _________________________________________________________________
## dense_2 (Dense) (None, 1) 51
## =================================================================
## Total params: 201
## Trainable params: 201
## Non-trainable params: 0
## _________________________________________________________________
## None
The model summary gives the number of parameters input to the model. Theare are total 201 parameters including the parameters from the bias unit. The two input units and one bias unit are fed via connection links to 50 neurons totaling 150 parameters, there after the hidden layer is connected to the 1 output and 1 bias unit also is connect to output neuron. Thus the computation of the paraters will be 150(Input, bias unit to hidden layer with 50 neurons) + 50(hidden layer to output) + 1 (bias unit in the output) = 201.
= model.fit(X_train, y_train , nb_epoch=100) results
## Epoch 1/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.6547 - accuracy: 0.8125
## 67/67 [==============================] - 0s 3ms/step - loss: 0.6510 - accuracy: 0.8358
## Epoch 2/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.6365 - accuracy: 0.8438
## 67/67 [==============================] - 0s 45us/step - loss: 0.6406 - accuracy: 0.8806
## Epoch 3/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.6279 - accuracy: 0.8438
## 67/67 [==============================] - 0s 45us/step - loss: 0.6313 - accuracy: 0.8806
## Epoch 4/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.6412 - accuracy: 0.8750
## 67/67 [==============================] - 0s 45us/step - loss: 0.6230 - accuracy: 0.8806
## Epoch 5/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.6239 - accuracy: 0.8438
## 67/67 [==============================] - 0s 44us/step - loss: 0.6146 - accuracy: 0.8806
## Epoch 6/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.6037 - accuracy: 0.9375
## 67/67 [==============================] - 0s 40us/step - loss: 0.6065 - accuracy: 0.8806
## Epoch 7/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.5950 - accuracy: 0.8438
## 67/67 [==============================] - 0s 45us/step - loss: 0.5983 - accuracy: 0.8806
## Epoch 8/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.5881 - accuracy: 0.8750
## 67/67 [==============================] - 0s 45us/step - loss: 0.5904 - accuracy: 0.8806
## Epoch 9/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.5787 - accuracy: 0.9062
## 67/67 [==============================] - 0s 45us/step - loss: 0.5826 - accuracy: 0.8806
## Epoch 10/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.5791 - accuracy: 0.8438
## 67/67 [==============================] - 0s 45us/step - loss: 0.5748 - accuracy: 0.8806
## Epoch 11/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.5457 - accuracy: 0.9062
## 67/67 [==============================] - 0s 45us/step - loss: 0.5679 - accuracy: 0.8806
## Epoch 12/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.5628 - accuracy: 0.8438
## 67/67 [==============================] - 0s 44us/step - loss: 0.5606 - accuracy: 0.8806
## Epoch 13/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.5422 - accuracy: 0.9062
## 67/67 [==============================] - 0s 60us/step - loss: 0.5543 - accuracy: 0.8806
## Epoch 14/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.5669 - accuracy: 0.8438
## 67/67 [==============================] - 0s 60us/step - loss: 0.5473 - accuracy: 0.8806
## Epoch 15/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.5198 - accuracy: 0.9062
## 67/67 [==============================] - 0s 45us/step - loss: 0.5412 - accuracy: 0.8657
## Epoch 16/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.5109 - accuracy: 0.9062
## 67/67 [==============================] - 0s 44us/step - loss: 0.5347 - accuracy: 0.8657
## Epoch 17/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.5318 - accuracy: 0.8750
## 67/67 [==============================] - 0s 45us/step - loss: 0.5281 - accuracy: 0.8657
## Epoch 18/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.5227 - accuracy: 0.8438
## 67/67 [==============================] - 0s 45us/step - loss: 0.5220 - accuracy: 0.8657
## Epoch 19/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.5233 - accuracy: 0.8125
## 67/67 [==============================] - 0s 45us/step - loss: 0.5160 - accuracy: 0.8657
## Epoch 20/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.4856 - accuracy: 0.8750
## 67/67 [==============================] - 0s 45us/step - loss: 0.5104 - accuracy: 0.8657
## Epoch 21/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.5019 - accuracy: 0.9062
## 67/67 [==============================] - 0s 45us/step - loss: 0.5048 - accuracy: 0.8657
## Epoch 22/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.5218 - accuracy: 0.8125
## 67/67 [==============================] - 0s 45us/step - loss: 0.4993 - accuracy: 0.8657
## Epoch 23/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.5096 - accuracy: 0.8125
## 67/67 [==============================] - 0s 45us/step - loss: 0.4940 - accuracy: 0.8657
## Epoch 24/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.4929 - accuracy: 0.9062
## 67/67 [==============================] - 0s 45us/step - loss: 0.4885 - accuracy: 0.8657
## Epoch 25/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.4944 - accuracy: 0.8750
## 67/67 [==============================] - 0s 45us/step - loss: 0.4829 - accuracy: 0.8657
## Epoch 26/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.5006 - accuracy: 0.8125
## 67/67 [==============================] - 0s 45us/step - loss: 0.4773 - accuracy: 0.8657
## Epoch 27/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.4799 - accuracy: 0.7812
## 67/67 [==============================] - 0s 45us/step - loss: 0.4720 - accuracy: 0.8657
## Epoch 28/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.4522 - accuracy: 0.9062
## 67/67 [==============================] - 0s 45us/step - loss: 0.4668 - accuracy: 0.8657
## Epoch 29/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.4590 - accuracy: 0.9062
## 67/67 [==============================] - 0s 45us/step - loss: 0.4616 - accuracy: 0.8657
## Epoch 30/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.4303 - accuracy: 0.9062
## 67/67 [==============================] - 0s 45us/step - loss: 0.4570 - accuracy: 0.8657
## Epoch 31/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.4619 - accuracy: 0.8438
## 67/67 [==============================] - 0s 30us/step - loss: 0.4521 - accuracy: 0.8657
## Epoch 32/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.4901 - accuracy: 0.8125
## 67/67 [==============================] - 0s 45us/step - loss: 0.4474 - accuracy: 0.8657
## Epoch 33/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.4683 - accuracy: 0.8438
## 67/67 [==============================] - 0s 44us/step - loss: 0.4429 - accuracy: 0.8657
## Epoch 34/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.4224 - accuracy: 0.8750
## 67/67 [==============================] - 0s 30us/step - loss: 0.4386 - accuracy: 0.8657
## Epoch 35/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3839 - accuracy: 0.9375
## 67/67 [==============================] - 0s 44us/step - loss: 0.4344 - accuracy: 0.8657
## Epoch 36/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.4487 - accuracy: 0.8125
## 67/67 [==============================] - 0s 44us/step - loss: 0.4300 - accuracy: 0.8657
## Epoch 37/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.4182 - accuracy: 0.9062
## 67/67 [==============================] - 0s 45us/step - loss: 0.4262 - accuracy: 0.8806
## Epoch 38/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.4233 - accuracy: 0.8750
## 67/67 [==============================] - 0s 45us/step - loss: 0.4220 - accuracy: 0.8806
## Epoch 39/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.4274 - accuracy: 0.8750
## 67/67 [==============================] - 0s 44us/step - loss: 0.4178 - accuracy: 0.8806
## Epoch 40/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.4287 - accuracy: 0.8750
## 67/67 [==============================] - 0s 44us/step - loss: 0.4137 - accuracy: 0.8806
## Epoch 41/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3735 - accuracy: 0.9062
## 67/67 [==============================] - 0s 45us/step - loss: 0.4098 - accuracy: 0.8806
## Epoch 42/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.4385 - accuracy: 0.8438
## 67/67 [==============================] - 0s 45us/step - loss: 0.4058 - accuracy: 0.8806
## Epoch 43/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3985 - accuracy: 0.9062
## 67/67 [==============================] - 0s 44us/step - loss: 0.4022 - accuracy: 0.8806
## Epoch 44/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.4333 - accuracy: 0.8438
## 67/67 [==============================] - 0s 45us/step - loss: 0.3986 - accuracy: 0.8806
## Epoch 45/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3947 - accuracy: 0.9062
## 67/67 [==============================] - 0s 30us/step - loss: 0.3956 - accuracy: 0.8806
## Epoch 46/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.4588 - accuracy: 0.8125
## 67/67 [==============================] - 0s 45us/step - loss: 0.3925 - accuracy: 0.8806
## Epoch 47/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3433 - accuracy: 0.9062
## 67/67 [==============================] - 0s 45us/step - loss: 0.3895 - accuracy: 0.8806
## Epoch 48/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3869 - accuracy: 0.9062
## 67/67 [==============================] - 0s 45us/step - loss: 0.3864 - accuracy: 0.8806
## Epoch 49/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3527 - accuracy: 0.9375
## 67/67 [==============================] - 0s 44us/step - loss: 0.3833 - accuracy: 0.8806
## Epoch 50/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3567 - accuracy: 0.9062
## 67/67 [==============================] - 0s 45us/step - loss: 0.3803 - accuracy: 0.8806
## Epoch 51/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3531 - accuracy: 0.9062
## 67/67 [==============================] - 0s 45us/step - loss: 0.3773 - accuracy: 0.8806
## Epoch 52/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3355 - accuracy: 0.8750
## 67/67 [==============================] - 0s 30us/step - loss: 0.3743 - accuracy: 0.8806
## Epoch 53/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3728 - accuracy: 0.8750
## 67/67 [==============================] - 0s 45us/step - loss: 0.3714 - accuracy: 0.8806
## Epoch 54/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3447 - accuracy: 0.8750
## 67/67 [==============================] - 0s 45us/step - loss: 0.3685 - accuracy: 0.8806
## Epoch 55/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3760 - accuracy: 0.8750
## 67/67 [==============================] - 0s 45us/step - loss: 0.3656 - accuracy: 0.8806
## Epoch 56/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3738 - accuracy: 0.8750
## 67/67 [==============================] - 0s 45us/step - loss: 0.3627 - accuracy: 0.8806
## Epoch 57/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3076 - accuracy: 0.9062
## 67/67 [==============================] - 0s 45us/step - loss: 0.3601 - accuracy: 0.8806
## Epoch 58/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3081 - accuracy: 0.9375
## 67/67 [==============================] - 0s 45us/step - loss: 0.3576 - accuracy: 0.8806
## Epoch 59/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3263 - accuracy: 0.8750
## 67/67 [==============================] - 0s 45us/step - loss: 0.3551 - accuracy: 0.8806
## Epoch 60/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3877 - accuracy: 0.8438
## 67/67 [==============================] - 0s 42us/step - loss: 0.3530 - accuracy: 0.8806
## Epoch 61/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3142 - accuracy: 0.9062
## 67/67 [==============================] - 0s 44us/step - loss: 0.3508 - accuracy: 0.8806
## Epoch 62/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.2962 - accuracy: 0.9062
## 67/67 [==============================] - 0s 60us/step - loss: 0.3484 - accuracy: 0.8806
## Epoch 63/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3617 - accuracy: 0.8750
## 67/67 [==============================] - 0s 45us/step - loss: 0.3461 - accuracy: 0.8806
## Epoch 64/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.2823 - accuracy: 0.9375
## 67/67 [==============================] - 0s 45us/step - loss: 0.3438 - accuracy: 0.8806
## Epoch 65/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3445 - accuracy: 0.8438
## 67/67 [==============================] - 0s 44us/step - loss: 0.3414 - accuracy: 0.8806
## Epoch 66/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3175 - accuracy: 0.8750
## 67/67 [==============================] - 0s 45us/step - loss: 0.3392 - accuracy: 0.8806
## Epoch 67/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3522 - accuracy: 0.9062
## 67/67 [==============================] - 0s 44us/step - loss: 0.3369 - accuracy: 0.8806
## Epoch 68/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3096 - accuracy: 0.9062
## 67/67 [==============================] - 0s 45us/step - loss: 0.3348 - accuracy: 0.8806
## Epoch 69/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3012 - accuracy: 0.9375
## 67/67 [==============================] - 0s 44us/step - loss: 0.3329 - accuracy: 0.8806
## Epoch 70/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3253 - accuracy: 0.9062
## 67/67 [==============================] - 0s 74us/step - loss: 0.3310 - accuracy: 0.8806
## Epoch 71/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3211 - accuracy: 0.8438
## 67/67 [==============================] - 0s 45us/step - loss: 0.3293 - accuracy: 0.8806
## Epoch 72/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3511 - accuracy: 0.8750
## 67/67 [==============================] - 0s 45us/step - loss: 0.3276 - accuracy: 0.8806
## Epoch 73/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3300 - accuracy: 0.9062
## 67/67 [==============================] - 0s 44us/step - loss: 0.3260 - accuracy: 0.8806
## Epoch 74/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.2983 - accuracy: 0.9062
## 67/67 [==============================] - 0s 45us/step - loss: 0.3242 - accuracy: 0.8806
## Epoch 75/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3263 - accuracy: 0.9375
## 67/67 [==============================] - 0s 44us/step - loss: 0.3225 - accuracy: 0.8806
## Epoch 76/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.2803 - accuracy: 0.8750
## 67/67 [==============================] - 0s 45us/step - loss: 0.3206 - accuracy: 0.8806
## Epoch 77/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3199 - accuracy: 0.8750
## 67/67 [==============================] - 0s 29us/step - loss: 0.3187 - accuracy: 0.8806
## Epoch 78/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3482 - accuracy: 0.8438
## 67/67 [==============================] - 0s 45us/step - loss: 0.3169 - accuracy: 0.8806
## Epoch 79/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3264 - accuracy: 0.8750
## 67/67 [==============================] - 0s 44us/step - loss: 0.3153 - accuracy: 0.8806
## Epoch 80/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.2980 - accuracy: 0.8750
## 67/67 [==============================] - 0s 29us/step - loss: 0.3136 - accuracy: 0.8806
## Epoch 81/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3369 - accuracy: 0.8438
## 67/67 [==============================] - 0s 44us/step - loss: 0.3123 - accuracy: 0.8806
## Epoch 82/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.2441 - accuracy: 0.9375
## 67/67 [==============================] - 0s 45us/step - loss: 0.3110 - accuracy: 0.8806
## Epoch 83/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3470 - accuracy: 0.8438
## 67/67 [==============================] - 0s 29us/step - loss: 0.3094 - accuracy: 0.8806
## Epoch 84/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3599 - accuracy: 0.8438
## 67/67 [==============================] - 0s 45us/step - loss: 0.3081 - accuracy: 0.8806
## Epoch 85/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.2844 - accuracy: 0.9062
## 67/67 [==============================] - 0s 30us/step - loss: 0.3070 - accuracy: 0.8806
## Epoch 86/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.2757 - accuracy: 0.9375
## 67/67 [==============================] - 0s 44us/step - loss: 0.3056 - accuracy: 0.8806
## Epoch 87/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.2856 - accuracy: 0.8750
## 67/67 [==============================] - 0s 45us/step - loss: 0.3040 - accuracy: 0.8806
## Epoch 88/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.2921 - accuracy: 0.9062
## 67/67 [==============================] - 0s 30us/step - loss: 0.3025 - accuracy: 0.8806
## Epoch 89/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.2863 - accuracy: 0.9062
## 67/67 [==============================] - 0s 44us/step - loss: 0.3011 - accuracy: 0.8806
## Epoch 90/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.2562 - accuracy: 0.9375
## 67/67 [==============================] - 0s 45us/step - loss: 0.2996 - accuracy: 0.8806
## Epoch 91/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.2731 - accuracy: 0.9062
## 67/67 [==============================] - 0s 45us/step - loss: 0.2984 - accuracy: 0.8806
## Epoch 92/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3106 - accuracy: 0.8750
## 67/67 [==============================] - 0s 44us/step - loss: 0.2968 - accuracy: 0.8806
## Epoch 93/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3033 - accuracy: 0.8750
## 67/67 [==============================] - 0s 45us/step - loss: 0.2956 - accuracy: 0.8806
## Epoch 94/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3113 - accuracy: 0.9062
## 67/67 [==============================] - 0s 44us/step - loss: 0.2942 - accuracy: 0.8806
## Epoch 95/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3416 - accuracy: 0.8438
## 67/67 [==============================] - 0s 45us/step - loss: 0.2931 - accuracy: 0.8806
## Epoch 96/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3390 - accuracy: 0.8438
## 67/67 [==============================] - 0s 44us/step - loss: 0.2919 - accuracy: 0.8806
## Epoch 97/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.4181 - accuracy: 0.8125
## 67/67 [==============================] - 0s 45us/step - loss: 0.2908 - accuracy: 0.8806
## Epoch 98/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.2784 - accuracy: 0.9062
## 67/67 [==============================] - 0s 30us/step - loss: 0.2898 - accuracy: 0.8806
## Epoch 99/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.2644 - accuracy: 0.8750
## 67/67 [==============================] - 0s 44us/step - loss: 0.2889 - accuracy: 0.8806
## Epoch 100/100
##
## 32/67 [=============>................] - ETA: 0s - loss: 0.3877 - accuracy: 0.7812
## 67/67 [==============================] - 0s 30us/step - loss: 0.2879 - accuracy: 0.8806
##
## C:/Users/slaxm/AppData/Local/r-miniconda/envs/r-reticulate/python.exe:1: UserWarning: The `nb_epoch` argument in `fit` has been renamed `epochs`.
## WARNING:tensorflow:From C:\Users\slaxm\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\keras\backend\tensorflow_backend.py:422: The name tf.global_variables is deprecated. Please use tf.compat.v1.global_variables instead.
= model.evaluate(X_test, y_test, verbose=0)
score print('Test score:', score[0])
## Test score: 0.3023785786195235
print('Test accuracy:', score[1])
## Test accuracy: 0.8787878751754761
Once the model is compiled then we use the training data to train the model via the fit function having paraters such as features set and the target label and number of iterations. Once the training is complete we evaluate the model to determine the loss and the accuracy.
The lower the loss, the better a model (unless the model has over-fitted to the training data). The loss is calculated on training and validation and its interpretation is how well the model is doing for these two sets. Unlike accuracy, loss is not a percentage. It is a summation of the errors made for each example in training or validation sets.
The accuracy of a model is usually determined after the model parameters are learned and fixed and no learning is taking place. Then the test samples are fed to the model and the number of mistakes (zero-one loss) the model makes are recorded, after comparison to the true targets. Then the percentage of miss classification is calculated.
For example, if the number of test samples is 1000 and model classifies 875 of those correctly, then the model’s accuracy is 87.5%.
from sklearn import metrics
= model.predict_classes(X_test)
prediction_values print(metrics.confusion_matrix(y_test, prediction_values))
## [[14 2]
## [ 2 15]]
print(metrics.classification_report(y_test, prediction_values))
## precision recall f1-score support
##
## 0 0.88 0.88 0.88 16
## 1 0.88 0.88 0.88 17
##
## accuracy 0.88 33
## macro avg 0.88 0.88 0.88 33
## weighted avg 0.88 0.88 0.88 33