In [1]:
from physlearn.NeuralNet.NeuralNet import NeuralNet
from physlearn.examples import Titanic
import matplotlib.pyplot as plt
%matplotlib inline

In [2]:
(learn_data, learn_output), (cv_data, cv_output) = Titanic.create_datasets(0.2)

In [3]:
net = NeuralNet(-7, 7)

In [4]:
net.add_input_layer(3)
net.add(100, net.sigmoid)
net.add(100, net.sigmoid)
net.add_output_layer(1, net.sigmoid)

In [5]:
net.compile()

In [6]:
net.set_train_type('logistic')

In [7]:
cost_list = net.train(learn_data, learn_output, 50, 100000, 0.001)
plt.plot(cost_list)


100%|██████████| 100000/100000 [01:01<00:00, 1621.03it/s]

In [8]:
net.calculate_cost(learn_data, learn_output)


Out[8]:
250.80030418898207

In [9]:
net.calculate_cost(cv_data, cv_output)


Out[9]:
82.832099858218086

In [10]:
ok_class = 0
output = net.run(learn_data)[0]
pred_clases = []
for item in output:
    if item >= 0.5:
        pred_clases.append(1)
    else:
        pred_clases.append(0)
for index, _ in enumerate(pred_clases):
    if pred_clases[index] == learn_output[0][index]:
        ok_class += 1
        
ok_percent = (ok_class / output.shape[0]) * 100
print('ok percent on learn data: ', ok_percent, '%')


ok percent on learn data:  81.08581436077058 %

In [11]:
ok_class = 0
output = net.run(cv_data)[0]
pred_clases = []
for item in output:
    if item >= 0.5:
        pred_clases.append(1)
    else:
        pred_clases.append(0)
for index, _ in enumerate(pred_clases):
    if pred_clases[index] == cv_output[0][index]:
        ok_class += 1
        
ok_percent = (ok_class / output.shape[0]) * 100
print('ok percent on cv data: ', ok_percent, '%')


ok percent on cv data:  77.62237762237763 %