Exemplo n.º 1
0
    def test_load_data(self):
        data = load_data('example.txt')
        self.assertIn('rules', data)
        self.assertIn('your_ticket', data)
        self.assertIn('nearby_tickets', data)

        self.assertIn('class', data['rules'])
        self.assertIn('row', data['rules'])
        self.assertIn('seat', data['rules'])

        self.assertIsNone(assert_array_equal((1, 3),
                                             data['rules']['class'][0]))
        self.assertIsNone(assert_array_equal((5, 7),
                                             data['rules']['class'][1]))

        self.assertIsNone(assert_array_equal((6, 11), data['rules']['row'][0]))
        self.assertIsNone(assert_array_equal((33, 44),
                                             data['rules']['row'][1]))

        self.assertIsNone(
            assert_array_equal((13, 40), data['rules']['seat'][0]))
        self.assertIsNone(
            assert_array_equal((45, 50), data['rules']['seat'][1]))

        self.assertIsNone(assert_array_equal([7, 1, 14], data['your_ticket']))

        self.assertIsNone(
            assert_array_equal([7, 3, 47], data['nearby_tickets'][0]))
        self.assertIsNone(
            assert_array_equal([40, 4, 50], data['nearby_tickets'][1]))
        self.assertIsNone(
            assert_array_equal([55, 2, 20], data['nearby_tickets'][2]))
        self.assertIsNone(
            assert_array_equal([38, 6, 12], data['nearby_tickets'][3]))
Exemplo n.º 2
0
    def test_determine_coumn_rules(self):
        data = load_data('example.txt')
        valid_tickets, error_rate = validate_tickets(data)
        column_rules = determine_column_rules(data, valid_tickets)

        self.assertEqual(column_rules[0], 'row')
        self.assertEqual(column_rules[1], 'class')
        self.assertEqual(column_rules[2], 'seat')
Exemplo n.º 3
0
def find_encryption_weakness(input_filename, preamble_size):
    fail_number = find_invalid_number(input_filename, preamble_size)
    if fail_number is not None:
        data = load_data(input_filename)
        for i in range(len(data)):
            for j in range(i + 1, len(data) + 1):
                snip = data[i:j]
                if np.sum(snip) == fail_number:
                    return np.min(snip) + np.max(snip)
    dataset = sys.argv[1]
    dataset_dir = 'Datasets/{}/'.format(dataset.title())
    drop_columns = []

    if dataset == 'housing':
        target_column = 'SalePrice'
        drop_columns = ['Id']

    elif dataset == 'grades':
        target_column = 'finalgrade'

    else:
        raise Exception('Unknown dataset')

    df = load_data(dataset_dir + 'train.csv', target_column, drop_columns)
    train, test = split_train_test(df)

    train = TrainData(train, target_column)
    test = TestData(test, target_column, train.get_imputation_map(),
                    train.get_categorical_maps())

    with open(dataset_dir + 'config.json', 'r') as f:
        gbrt_config = json.load(f)

    gbrt = GBRT(**gbrt_config)
    train_errors, test_errors = gbrt.fit(train, test)

    fig = plt.figure()
    fig.suptitle('MSE as function of NumberOfBasisFunctions')
    plt.plot(range(1,
Exemplo n.º 5
0
 def test_example(self):
     from part1 import validate_tickets
     data = load_data('example.txt')
     valid_tickets, error_rate = validate_tickets(data)
     self.assertEqual(error_rate, 71)
Exemplo n.º 6
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('input_filename', type=str)
    args = parser.parse_args()

    play_game(*build_cards(load_data(args.input_filename)))
Exemplo n.º 7
0
 def test_load_data(self):
     from part1 import load_data
     initial_state = np.array([['.', '#', '.'], ['.', '.', '#'],
                               ['#', '#', '#']])
     data = load_data('example1.txt')
     self.assertIsNone(assert_array_equal(initial_state, data))