<commit_before># coding: utf-8
from data_readers import get_matches, separate_samples, normalize
from sklearn.neighbors import KNeighborsClassifier
from random import random


def train(train_inputs, train_outputs, test_inputs, test_outputs,
          neighbors=10):
    classifier = KNeighborsClassifier(n_neighbors=neighbors)
    classifier.fit(train_inputs, train_outputs)

    score = classifier.score(test_inputs, test_outputs)

    return classifier, score


def full_train(input_features=None, output_feature='winner'):
    if input_features is None:
        input_features = ['matches_won_percent',
                          'podium_score_yearly',
                          'matches_won_percent_2',
                          'podium_score_yearly_2']

    matches = get_matches(with_team_stats=True,
                          duplicate_with_reversed=True)

    inputs, outputs = separate_samples(matches,
                                       input_features,
                                       output_feature)

    inputs = normalize(inputs)

    train_inputs, train_outputs, test_inputs, test_outputs = split_samples(inputs, outputs)

    predictor, score = train(train_inputs,
                             train_outputs,
                             test_inputs,
                             test_outputs)

    return predictor, score


def split_samples(inputs, outputs, percent=0.75):
    assert len(inputs) == len(outputs)

    inputs1 = []
    inputs2 = []
    outputs1 = []
    outputs2 = []

    for i, inputs_row in enumerate(inputs):
        if random() < percent:
            input_to = inputs1
            output_to = outputs1
        else:
            input_to = inputs2
            output_to = outputs2

        input_to.append(inputs_row)
        output_to.append(outputs[i])

    return inputs1, outputs1, inputs2, outputs2
<commit_msg>Added option to ignore tied matches<commit_after># coding: utf-8
from data_readers import get_matches, separate_samples, normalize
from sklearn.neighbors import KNeighborsClassifier
from random import random


def train(train_inputs, train_outputs, test_inputs, test_outputs,
          neighbors=10):
    classifier = KNeighborsClassifier(n_neighbors=neighbors)
    classifier.fit(train_inputs, train_outputs)

    score = classifier.score(test_inputs, test_outputs)

    return classifier, score


def full_train(input_features=None, output_feature='winner', remove_ties=False):
    if input_features is None:
        input_features = ['matches_won_percent',
                          'podium_score_yearly',
                          'matches_won_percent_2',
                          'podium_score_yearly_2']

    matches = get_matches(with_team_stats=True,
                          duplicate_with_reversed=True)

    if remove_ties:
        matches = matches[matches['score1'] != matches['score2']]

    inputs, outputs = separate_samples(matches,
                                       input_features,
                                       output_feature)

    inputs = normalize(inputs)

    train_inputs, train_outputs, test_inputs, test_outputs = split_samples(inputs, outputs)

    predictor, score = train(train_inputs,
                             train_outputs,
                             test_inputs,
                             test_outputs)

    return predictor, score


def split_samples(inputs, outputs, percent=0.75):
    assert len(inputs) == len(outputs)

    inputs1 = []
    inputs2 = []
    outputs1 = []
    outputs2 = []

    for i, inputs_row in enumerate(inputs):
        if random() < percent:
            input_to = inputs1
            output_to = outputs1
        else:
            input_to = inputs2
            output_to = outputs2

        input_to.append(inputs_row)
        output_to.append(outputs[i])

    return inputs1, outputs1, inputs2, outputs2

{'fraction_non_alphanumeric': 0.07313278008298756, 'fraction_numerical': 0.010892116182572614, 'mean_word_length': 2.1902398676592223, 'pattern_counts': {'":': 0, '<': 5, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '150825', 'n_tokens_mistral': 1086, 'n_tokens_neox': 1028, 'n_words': 221}