<commit_before>import sklearn


def make_train_pair(filename):
    h5 = open_h5_file_read(filename)
    title = get_title(h5)
    pitches = get_segments_pitches(h5)[:11] # limit: only look at beginning
    pitch_diffs = [pitches[i] - pitches[i - 1] for i in xrange(1, len(pitches))]
    h5.close()
    return {'title': title, 'pitch_diffs': pitch_diffs}
# some lines omitted
neigh = NearestNeighbors(n_neighbors=1) # predict the closest song
# a title list is also maintained
neigh.fit([sum(diff) for diff in pitch_diff_list[5000:]])
neigh.kneighbors(sum(pitch_diff_list[2029])) # example prediction<commit_msg>Add corresponding hdf5 parsing file<commit_after>import sklearn
from hdf5_getters import *
import os

def make_train_pair(filename):
    h5 = open_h5_file_read(filename)
    title = get_title(h5)
    pitches = get_segments_pitches(h5)[:11] # limit: only look at beginning
    pitch_diffs = [pitches[i] - pitches[i - 1] for i in xrange(1, len(pitches))]
    h5.close()
    return {'title': title, 'pitch_diffs': pitch_diffs}

for root, dirs, files in os.walk('data'):
    files = glob.glob(os.path.join(root, '*h5'))
    for f in files:
        train_pair = make_train_pair(f)
        titles.append(train_pair['title'])
        pitch_diff_list.append(train_pair['pitch_diffs'])

# some lines omitted
neigh = NearestNeighbors(n_neighbors=1) # predict the closest song
# a title list is also maintained
neigh.fit([sum(diff) for diff in pitch_diff_list[5000:]])
neigh.kneighbors(sum(pitch_diff_list[2029])) # example prediction
{'fraction_non_alphanumeric': 0.11799217731421122, 'fraction_numerical': 0.025423728813559324, 'mean_word_length': 4.926640926640927, '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': '4863554', 'n_tokens_mistral': 573, 'n_tokens_neox': 541, 'n_words': 131}