Example #1
0
    def test_outcome_fraction_should_compute_percentage_of_positive_outcome(self):
        df = pd.DataFrame(data=np.random.rand(12, 2), columns=["var1", "var2"])
        df["Outcome"] = [random.sample(range(2), 1)[0] for i in range(12)]

        value = len(df[df["Outcome"] == 1]) / len(df)
        result = utils.outcome_fraction_(df)

        self.assertEqual(value, result)
Example #2
0
    def test_outcome_fraction_should_compute_percentage_of_positive_outcome_with_custom_name(
            self):
        df = pd.DataFrame(data=np.random.rand(12, 2), columns=['var1', 'var2'])
        df['result'] = [random.sample(range(2), 1)[0] for i in range(12)]

        value = len(df[df['result'] == 1]) / len(df)
        result = utils.outcome_fraction_(df, col_outcome='result')

        self.assertEqual(value, result)