예제 #1
0
    def test_select_less_scores_than_k_min(self, bandit_mock):
        """If min length is lt k_min, super().compute_rewards is used.

        In this case, we expect the socres to be returned as they are.
        """

        # Set-up
        selector = RecentKReward(['RF', 'SVM'])

        bandit_mock.return_value = 'SVM'

        # Run
        choice_scores = {
            'DT': [0.7, 0.75, 0.73],
            'RF': [0.8],
            'SVM': [0.9, 0.95, 0.93],
        }
        best = selector.select(choice_scores)

        # Assert
        assert best == 'SVM'

        choice_rewards = {
            'RF': [0.8],
            'SVM': [0.9, 0.95, 0.93],
        }
        bandit_mock.assert_called_once_with(choice_rewards)
예제 #2
0
    def test_select_more_scores_than_k_min(self, bandit_mock):
        """If min length is gt k_min, self.compute_rewards is used.

        In this case, we expect the lower scores to be zeroed.
        """

        # Set-up
        selector = RecentKReward(['RF', 'SVM'])

        bandit_mock.return_value = 'SVM'

        # Run
        choice_scores = {
            'DT': [0.7, 0.75, 0.73],
            'RF': [0.8, 0.85, 0.83],
            'SVM': [0.9, 0.95, 0.93],
        }
        best = selector.select(choice_scores)

        # Assert
        assert best == 'SVM'

        choice_rewards = {
            'RF': [0.8, 0.85, 0.],
            'SVM': [0.9, 0.95, 0.],
        }
        bandit_mock.assert_called_once_with(choice_rewards)
예제 #3
0
    def test_compute_rewards(self):
        """Last scores are zeroed"""

        # Set-up
        selector = RecentKReward(['RF', 'SVM'], k=3)

        # Run
        scores = [0.5, 0.6, 0.75, 0.8, 0.9]
        rewards = selector.compute_rewards(scores)

        # Assert
        assert rewards == [0.5, 0.6, 0.75, 0., 0.]
예제 #4
0
    def test___init__(self):

        # Run
        selector = RecentKReward(['RF', 'SVM'], k=3)

        # Assert
        assert selector.choices == ['RF', 'SVM']
        assert selector.k == 3