def treePredict(): #build the decision tree model label, the label 0 means choose 4G and 1 means choose 5G label_list = [] predict_label_list = [] data_list = [] total_num = 0 for i in webSet_test: if (not ((i, '4G') in fileStatistics.keys())) or (not ((i, '5G') in fileStatistics.keys())): continue #ipdb.set_trace() if ((len(fileStatistics[(i, "4G")]) <= 1) or (len(fileStatistics[(i, "5G")]) <= 1)): continue final_statistics[(i, "4G")] = mergeList(fileStatistics[(i, '4G')]) final_statistics[(i, "5G")] = mergeList(fileStatistics[(i, '5G')]) dict_4g = final_statistics[(i, "4G")] dict_5g = final_statistics[(i, "5G")] dict_4g, dict_5g = treeFeatureGeneration(alpha, beta, dict_4g, dict_5g, standard_tuple, mn_tuple) #construct the decision tree dataset if (dict_4g['comparison_metric'] < dict_5g['comparison_metric']): label_list.append(0) else: label_list.append(1) merge_feature_dict = mergeList(fileStatistics[(i, '4G')] + fileStatistics[(i, '5G')]) feature_list = [merge_feature_dict["pageSize"], merge_feature_dict["objectNumber"], merge_feature_dict["averageObjectSize"], merge_feature_dict["memeCounter"][0], merge_feature_dict["memeCounter"][1], merge_feature_dict["dynamicObjratio"], merge_feature_dict["dynamic-size-ratio"]] data_list.append(feature_list) predict_label = clf.predict([feature_list])[0] predict_label_list.append(predict_label)
clf_list = [clf1, clf2, clf3, clf4, clf5] for (index, alpha_beta) in enumerate(alpha_beta_list): clf = clf_list[index] alpha, beta = alpha_beta label_list = [] data_list = [] for i in webSet_train: if (not ((i, '4G') in fileStatistics.keys())) or (not ((i, '5G') in fileStatistics.keys())): continue #ipdb.set_trace() if ((len(fileStatistics[(i, "4G")]) <= webset_threshold) or (len(fileStatistics[(i, "5G")]) <= webset_threshold)): continue final_statistics[(i, "4G")] = mergeList(fileStatistics[(i, '4G')]) final_statistics[(i, "5G")] = mergeList(fileStatistics[(i, '5G')]) dict_4g = final_statistics[(i, "4G")] dict_5g = final_statistics[(i, "5G")] dict_4g, dict_5g = treeFeatureGeneration(alpha, beta, dict_4g, dict_5g, standard_tuple, mn_tuple) #construct the decision tree dataset if (dict_4g['comparison_metric'] < dict_5g['comparison_metric']): label_list.append(0) else: label_list.append(1) merge_feature_dict = mergeList(fileStatistics[(i, '4G')] + fileStatistics[(i, '5G')]) feature_list = [merge_feature_dict["pageSize"], merge_feature_dict["objectNumber"], merge_feature_dict["averageObjectSize"], merge_feature_dict["memeCounter"][0], merge_feature_dict["memeCounter"][1], merge_feature_dict["dynamicObjratio"], merge_feature_dict["dynamic-size-ratio"]]