<commit_before>import numpy as np

def computeMetrics(predicted, test,label_set=None):
    #predicted = np.array([[1, 0, 0, 0,1], [0,0,1,1,1],[0,0,1,1,1],[1,1,1,1,1],[0,0,0,1,1],[0,1,1,1,0]], np.int32)
    #test = np.array([[1, 0, 1, 0,1], [0,1,1,0,1],[01,1,1,1,1],[1,0,0,0,1],[0,1,0,1,1],[1,1,0,0,0]], np.int32)
    #label_set = ["A","b","c","d","e"]
    CM = np.zeros((2,2))
    HL = 0
    test_sample_size = predicted.shape[0]
    n_categories = predicted.shape[1]
    for i in range( n_categories ):
        #print  label_set[i]
        predicted_vector = predicted[:,i]
        test_vector = test[:,i]
        for x, y in np.nditer([predicted_vector,test_vector]):
            a = int(x)
            b = int(y)
            CM[a][b] = CM[a][b] + 1
            #print type(yt) is np.ndarray
        #print CM
        precision = CM[1][1] / (CM[1][1]+CM[1][0])
        recall = CM[1][1] / (CM[1][1]+CM[0][ 1])
        F1_score  =  2 * (precision * recall) / (precision + recall)
        #print F1_score
        HL = HL + CM[0][1]+CM[1][0]
        CM = np.zeros((2,2))

    HL = HL/(test_sample_size*n_categories)
    print HL
    return HL<commit_msg>PRINT HAMMING LOSS AND HAMMING SCORE RESPECTIVELY<commit_after>import numpy as np

def hamming_score(y_true, y_pred, normalize=True, sample_weight=None):
    acc_list = []
    for i in range(y_true.shape[0]):
        set_true = set( np.where(y_true[i])[0] )
        set_pred = set( np.where(y_pred[i])[0] )
        tmp_a = None
        if len(set_true) == 0 and len(set_pred) == 0:
            tmp_a = 1
        else:
            tmp_a = len(set_true.intersection(set_pred))/\
                    float( len(set_true.union(set_pred)) )
        acc_list.append(tmp_a)
    return np.mean(acc_list)
    
def computeMetrics(predicted, test,label_set):
    #predicted = np.array([[1, 0, 0, 0,1], [0,0,1,1,1],[0,0,1,1,1],[1,1,1,1,1],[0,0,0,1,1],[0,1,1,1,0]], np.int32)
    #test = np.array([[1, 0, 1, 0,1], [0,1,1,0,1],[01,1,1,1,1],[1,0,0,0,1],[0,1,0,1,1],[1,1,0,0,0]], np.int32)  
    #label_set = ["A","b","c","d","e"]
    CM = np.zeros((2,2))
    HL = 0 
    test_sample_size = predicted.shape[0]
    n_categories = len(label_set)
    for i in range( n_categories ):
        print  label_set[i]
        predicted_vector = predicted[:,i]
        test_vector = test[:,i]
        for x, y in np.nditer([predicted_vector,test_vector]): 
            a = int(x)
            b = int(y)
            CM[a][b] = CM[a][b] + 1
    #print type(yt) is np.ndarray
        print CM
        precision = CM[1][1] / (CM[1][1]+CM[1][0])
        recall = CM[1][1] / (CM[1][1]+CM[0][ 1])
        F1_score  =  2 * (precision * recall) / (precision + recall)
        print F1_score
        HL = HL + CM[0][1]+CM[1][0]
        CM = np.zeros((2,2))
    HL = HL/(test_sample_size*n_categories)
    print HL
    print hamming_score(predicted,test)
    return HL

{'fraction_non_alphanumeric': 0.20041608876560332, 'fraction_numerical': 0.06553398058252427, 'mean_word_length': 2.633501259445844, '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': '4581031', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1208, 'n_words': 213}