def test_trees(T_P, x2): T, P = zip(*T_P) predictions = [] for i in x2.index.values: example = x2.loc[i] T_P_D = [] for j in range(0, len(T_P)): prediction, depth = TreeNode.dfs_with_depth(T[j], example) T_P_D.append([prediction, P[j], depth]) prediction_choice = choose_prediction_optimised(T_P_D) predictions.append(prediction_choice + 1) return pd.DataFrame(predictions)
def test_forest_trees(forest_T, x2): predictions = [] for i in x2.index.values: example = x2.loc[i] all_emotion_prediction = [] for T in forest_T: emotion_prediction = [] depths = [] for tree in T: # how emotion votes prediction, depth = TreeNode.dfs_with_depth(tree, example) emotion_prediction.append(prediction) depths.append(depth) sum_per_emotion = sum(emotion_prediction) sum_depths = sum(depths) all_emotion_prediction.append((sum_per_emotion, sum_depths)) prediction_choice = choose_majority_vote_optimised( all_emotion_prediction) predictions.append(prediction_choice + 1) return pd.DataFrame(predictions)