|
1 | 1 | # -*- coding: utf-8 -*-
|
2 | 2 |
|
3 | 3 | import sys
|
4 |
| -from statistics import median, mean |
5 |
| - |
6 |
| -sys.path.append('C:/Users/gzq-712/Desktop/Git/CLDP/') |
7 | 4 |
|
| 5 | +import warnings |
8 | 6 | import pandas as pd
|
9 | 7 | from pandas import DataFrame
|
| 8 | + |
| 9 | +sys.path.append('C:/Users/gzq-712/Desktop/Git/CLDP/') |
10 | 10 | from src.models.glance import *
|
| 11 | +from statistics import * |
| 12 | + |
| 13 | +# Ignore warning information |
| 14 | +warnings.filterwarnings('ignore') |
11 | 15 |
|
| 16 | +line_level_thresholds = [.05, .10, .15, .20, .25, .30, .35, .40, .45, .50] |
| 17 | +indicators = ['recall', 'far', 'ce', 'd2h', 'mcc', 'ifa', 'recall_20', 'ratio'] |
12 | 18 |
|
13 |
| -def run_Glance(prediction_model, line_level_threshold, effort_aware): |
14 |
| - for project, releases in get_project_releases_dict().items(): |
15 |
| - print(f'========== {prediction_model.model_name} CR PREDICTION for {project} =================='[:60]) |
16 |
| - for i in range(len(releases) - 1): |
17 |
| - # 1. Loading data. train data index = i, test data index = i + 1 |
18 |
| - model = prediction_model(releases[i], releases[i + 1], |
19 |
| - line_level_threshold=line_level_threshold, |
20 |
| - effort_aware=effort_aware, |
21 |
| - test=True) |
| 19 | +output_path = '../../result/RQ1/' |
| 20 | +make_path(output_path) |
22 | 21 |
|
23 |
| - model.file_level_prediction() |
24 |
| - model.analyze_file_level_result() |
25 | 22 |
|
26 |
| - model.line_level_prediction() |
27 |
| - model.analyze_line_level_result() |
| 23 | +def select_model(file_level_classifier, line_level_threshold, train='', test=''): |
| 24 | + if file_level_classifier == 'MD': |
| 25 | + model = Glance_MD(train, test, line_threshold=line_level_threshold, test=True) |
| 26 | + elif file_level_classifier == 'EA': |
| 27 | + model = Glance_EA(train, test, line_threshold=line_level_threshold, test=True) |
| 28 | + else: |
| 29 | + model = Glance_LR(train, test, line_threshold=line_level_threshold, test=True) |
| 30 | + return model |
28 | 31 |
|
29 | 32 |
|
30 |
| -def search_parameter(effort_aware=True): |
31 |
| - line_level_thresholds = [.05, .10, .15, .20, .25, .30, .35, .40, ] |
| 33 | +def search_parameter_Glance(clf): |
| 34 | + for threshold in line_level_thresholds: |
| 35 | + for project, releases in get_project_releases_dict().items(): |
| 36 | + for i in range(len(releases) - 1): |
| 37 | + # 1. Loading data. train data index = i, test data index = i + 1 |
| 38 | + model = select_model(clf, threshold, releases[i], releases[i + 1]) |
32 | 39 |
|
33 |
| - for threshold in line_level_thresholds[::-1]: |
34 |
| - run_Glance(Glance, threshold, effort_aware) |
| 40 | + print(f'========== {model.model_name} CR PREDICTION for {releases[i + 1]} =================='[:60]) |
| 41 | + model.file_level_prediction() |
| 42 | + model.analyze_file_level_result() |
35 | 43 |
|
| 44 | + model.line_level_prediction() |
| 45 | + model.analyze_line_level_result() |
36 | 46 |
|
37 |
| -def test_parameter(effort_aware=True): |
38 |
| - line_level_thresholds = [.05, .10, .15, .20, .25, .30, .35, .40, ] |
39 | 47 |
|
40 |
| - data = dict() |
41 |
| - names = list() |
| 48 | +def test_parameter(clf): |
| 49 | + print(f'Glance {clf}') |
| 50 | + # 水平展示的变化数据, 列名为与之 |
| 51 | + summary_data_horizontal, summary_data_vertical = list(), dict() |
| 52 | + for indicator in indicators: |
| 53 | + detail_data, column_names, mean_list = dict(), list(), list() |
| 54 | + for threshold in line_level_thresholds: |
| 55 | + model = select_model(clf, threshold) |
| 56 | + column_names.append(model.model_name) |
| 57 | + detail_data[model.model_name] = list(pd.read_csv(model.line_level_evaluation_file)[indicator]) |
42 | 58 |
|
43 |
| - mean_list = list() |
44 |
| - for threshold in line_level_thresholds[::-1]: |
45 |
| - m = Glance(line_level_threshold=threshold, effort_aware=effort_aware, test=True) |
46 |
| - df = pd.read_csv(m.line_level_evaluation_file) |
47 |
| - data[m.model_name] = list(df['d2h']) |
48 |
| - names.append(m.model_name) |
49 |
| - mean_list.append(mean(data[m.model_name])) |
50 |
| - print(mean_list) |
| 59 | + mean_list.append(round(mean(detail_data[model.model_name]), 3)) |
51 | 60 |
|
52 |
| - result = DataFrame(data, columns=names) |
| 61 | + summary_data_horizontal.append(mean_list) |
| 62 | + summary_data_vertical[indicator] = mean_list |
53 | 63 |
|
54 |
| - if effort_aware: |
55 |
| - result.to_csv(f'../../result/RQ1/RQ1-D2H-EA.csv', index=False) |
56 |
| - else: |
57 |
| - result.to_csv(f'../../result/RQ1/RQ1-D2H-MD.csv', index=False) |
| 64 | + detail_result = DataFrame(detail_data, index=get_test_releases_list(), columns=column_names) |
| 65 | + |
| 66 | + make_path(f'{output_path}RQ1-Glance-{clf}/') |
| 67 | + detail_result.to_csv(f'{output_path}RQ1-Glance-{clf}/{indicator}.csv', index=True) |
| 68 | + |
| 69 | + threshold_indices = ['5%', '10%', '15%', '20%', '25%', '30%', '35%', '40%', '45%', '50%', ] |
| 70 | + summary_result = DataFrame(summary_data_horizontal, index=indicators, columns=threshold_indices) |
| 71 | + summary_result.to_csv(f'{output_path}RQ1-summary-Glance-{clf}-horizontal.csv', index=True) |
| 72 | + summary_result = DataFrame(summary_data_vertical, index=threshold_indices, columns=indicators) |
| 73 | + summary_result.to_csv(f'{output_path}RQ1-summary-Glance-{clf}-vertical.csv', index=True) |
58 | 74 |
|
59 | 75 |
|
60 | 76 | if __name__ == '__main__':
|
61 | 77 | #
|
62 |
| - # search_parameter(True) |
63 |
| - # test_parameter(True) |
64 |
| - |
65 |
| - search_parameter(False) |
66 |
| - test_parameter(False) |
| 78 | + file_level_classifiers = ['MD', 'EA', 'LR'] |
| 79 | + for classifier in file_level_classifiers: |
| 80 | + # search_parameter_Glance(classifier) |
| 81 | + test_parameter(classifier) |
67 | 82 |
|
68 | 83 | pass
|
0 commit comments