<commit_before>import unittest
import pandas as pd
import numpy as np

from snape.score_dataset import *


class TestScoreDataset(unittest.TestCase):
    def setUp(self):
        np.random.seed(seed=42)
        y_rand = (np.random.rand(200))
        r = {'y': y_rand * 10,
             'y_hat': y_rand * 10 - y_rand
             }
        self.regression_df = pd.DataFrame(r)

        c = {'y': [1, 1, 1, 1, 0, 0, 0, 0],
             'y_hat': [1, 0.9, 0.4, 0.95, 0, 0.1, 0.6, 0.15]
             }
        self.classification_df = pd.DataFrame(c)

        m = {'y': [0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3],
             'y_hat': [0, 1, 0, 1, 1, 3, 1, 2, 2, 3, 2, 3]
             }
        self.multiclass_df = pd.DataFrame(m)

    def test_guess_problem_type(self):
        self.assertEqual(guess_problem_type(self.regression_df['y']), 'regression')
        self.assertEqual(guess_problem_type(self.classification_df['y']), 'binary')
        self.assertEqual(guess_problem_type(self.multiclass_df['y']), 'multiclass')

    def test_score_binary_classification(self):
        y = self.classification_df['y']
        y_hat = self.classification_df['y_hat']
        self.assertAlmostEquals(score_binary_classification(y,y_hat, report=False)[0], 0.9375)
        self.assertTrue("---Binary Classification Score---" in score_binary_classification(y, y_hat, report=False)[1])

    def test_score_multiclass_classification(self):
        y = self.multiclass_df['y']
        y_hat = self.multiclass_df['y_hat']
        self.assertAlmostEquals(round(score_multiclass_classification(y,y_hat, report=False)[0],2), 0.67)
        self.assertTrue("---Multiclass Classification Score---" in score_multiclass_classification(y, y_hat, report=False)[1])

    def test_score_regression(self):
        y = self.regression_df['y']
        y_hat = self.regression_df['y_hat']
        self.assertAlmostEquals(round(score_regression(y,y_hat, report=False)[0],2), 0.48)
        self.assertTrue("---Regression Score---" in score_regression(y, y_hat, report=False)[1])







if __name__ == '__main__':<commit_msg>reformat<commit_after>import unittest
import pandas as pd
import numpy as np

from snape.score_dataset import *


class TestScoreDataset(unittest.TestCase):
    def setUp(self):
        np.random.seed(seed=42)
        y_rand = (np.random.rand(200))
        r = {'y': y_rand * 10,
             'y_hat': y_rand * 10 - y_rand
             }
        self.regression_df = pd.DataFrame(r)

        c = {'y': [1, 1, 1, 1, 0, 0, 0, 0],
             'y_hat': [1, 0.9, 0.4, 0.95, 0, 0.1, 0.6, 0.15]
             }
        self.classification_df = pd.DataFrame(c)

        m = {'y': [0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3],
             'y_hat': [0, 1, 0, 1, 1, 3, 1, 2, 2, 3, 2, 3]
             }
        self.multiclass_df = pd.DataFrame(m)

    def test_guess_problem_type(self):
        self.assertEqual(guess_problem_type(self.regression_df['y']), 'regression')
        self.assertEqual(guess_problem_type(self.classification_df['y']), 'binary')
        self.assertEqual(guess_problem_type(self.multiclass_df['y']), 'multiclass')

    def test_score_binary_classification(self):
        y = self.classification_df['y']
        y_hat = self.classification_df['y_hat']
        self.assertAlmostEquals(score_binary_classification(y,y_hat, report=False)[0], 0.9375)
        self.assertTrue("---Binary Classification Score---" in score_binary_classification(y, y_hat, report=False)[1])

    def test_score_multiclass_classification(self):
        y = self.multiclass_df['y']
        y_hat = self.multiclass_df['y_hat']
        self.assertAlmostEquals(round(score_multiclass_classification(y,y_hat, report=False)[0],2), 0.67)
        self.assertTrue("---Multiclass Classification Score---" in score_multiclass_classification(y, y_hat, report=False)[1])

    def test_score_regression(self):
        y = self.regression_df['y']
        y_hat = self.regression_df['y_hat']
        self.assertAlmostEquals(round(score_regression(y,y_hat, report=False)[0],2), 0.48)
        self.assertTrue("---Regression Score---" in score_regression(y, y_hat, report=False)[1])

if __name__ == '__main__':
{'fraction_non_alphanumeric': 0.149289670117987, 'fraction_numerical': 0.0366000481579581, 'mean_word_length': 3.0606060606060606, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6938124', 'n_tokens_mistral': 1610, 'n_tokens_neox': 1455, 'n_words': 275}