示例#1
0
def evaluate_test_results(my_results):
    solutions_dict = get_test_solutions()
    scores = []
    for uid, l in my_results.items():
        score = apk(solutions_dict[uid], l)
        scores.append(score)
    return sum(scores) / len(scores)
def evaluate_test_results(my_results):
    solutions_dict = get_test_solutions()
    scores = []
    for uid, l in my_results.iteritems():
        score = apk(solutions_dict[uid], l)
        scores.append(score)
    return sum(scores) / len(scores)
    def run_crossval(self):
        splits = self.get_crossval_data()
        print("length of splits " + str(len(splits)))
        print("length of splits of 0 " + str(len(splits[0])))
        print("length of splits of 0 of 0 : " + str(len(splits[0][0])))
        results = []
        for i in range(2):
            s = splits[i]
            other_s = splits[1 - i]

            z = [True] * len(s[0])
            w = [True] * len(s[0])
            print(len(z))
            remove_features_rfc = [19, 20]
            remove_features_lr = [
                19, 20, 21, 22, 23, 24, 25, 26, 29, 30, 31, 32
            ]

            for i in remove_features_rfc:
                z[i] = False
            for i in remove_features_lr:
                w[i] = False

            m1 = Model(compress=z, has_none=w)
            m1.fit(s[0], s[1])

            X = other_s[0]
            predictions = m1.test(X)
            keys = other_s[4]
            pred_dict = {}
            for j in xrange(len(keys)):
                uid, eid = keys[j]
                if uid not in pred_dict:
                    pred_dict[uid] = []
                pred_dict[uid].append((eid, predictions[j]))

            for uid, l in pred_dict.items():
                l.sort(key=lambda x: -x[1])
                l = [e[0] for e in l]
                results.append(apk(other_s[3][uid], l))

        print("done running cross val")
def run_crossval():
    splits = get_crossval_data()
    
    results = []
    for i in range(2):
        s = splits[i]
        other_s = splits[1 - i]
        
        z = [True] * len(s[0][0])
        w = [True] * len(s[0][0])
        remove_features_rfc = [19,20]
        remove_features_lr = [19,20,21,22,23,24,25,26,29,30,31,32]
        
        for i in remove_features_rfc:
            z[i] = False
        for i in remove_features_lr:
            w[i] = False
        
        m1 = Model(compress=z, has_none=w)
        m1.fit(s[0], s[1])
        
        X = other_s[0]
        predictions = m1.test(X)
        keys = other_s[4]
        pred_dict = {}
        for j in xrange(len(keys)):
            uid, eid = keys[j]
            if uid not in pred_dict:
                pred_dict[uid] = []
            pred_dict[uid].append((eid, predictions[j]))
            
        for uid, l in pred_dict.iteritems():
            l.sort(key=lambda x: -x[1])
            l = [e[0] for e in l]
            results.append(apk(other_s[3][uid], l))
        
    print sum(results) / len(results)