예제 #1
0
    def test_evaluate_assert_it_returns_prob_array(self):
        arch = MagicMock()
        arch.evaluate.return_value = [0.1, 0.8, 0.1]
        model = Model(arch)

        result = model.evaluate(None)

        self.assertEqual(result, [0.1, 0.8, 0.1])
예제 #2
0
        evaluations = self.evaluate(dataset)
        error = labels - evaluations
        self._weights += np.sum(self._learning_rate * error *
                                np.transpose(dataset),
                                axis=1)
        return (np.average(error), evaluations)

    def evaluate(self, dataset):
        sum_ = np.sum(dataset * self._weights, axis=1)
        return (sum_ > self._threshold).astype(int)


model = Model(Perceptron(2))

epochs, costs, accuracies, *_ = model.train(
    np.array([[0, 0], [0, 1], [1, 0], [1, 1]]),
    np.array([0, 0, 0, 1]),
    None,
    None,
    SimpleTrainer(),
    PairwiseMeasurer(),
    None,
    epochs=10,
)

print('Epochs:     ', epochs)
print('Costs:      ', costs)
print('Accuracies: ', accuracies)
print('Predictions:', model.evaluate(np.array([[0, 0], [0, 1], [1, 0], [1,
                                                                        1]])))