Conditions | 6 |
Total Lines | 55 |
Code Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | # Author: Simon Blanke |
||
68 | def _print_results( |
||
69 | self, |
||
70 | objective_function, |
||
71 | best_score, |
||
72 | best_para, |
||
73 | best_iter, |
||
74 | best_additional_results, |
||
75 | random_seed, |
||
76 | ): |
||
77 | print("\nResults: '{}'".format(objective_function.__name__), " ") |
||
78 | if best_para is None: |
||
79 | print(indent, "Best score:", best_score, " ") |
||
80 | print(indent, "Best parameter set:", best_para, " ") |
||
81 | print(indent, "Best iteration:", best_iter, " ") |
||
82 | |||
83 | else: |
||
84 | print(indent, "Best score:", best_score, " ") |
||
85 | |||
86 | if best_additional_results: |
||
87 | print(indent, "Best additional results:") |
||
88 | add_results_names = list(best_additional_results.keys()) |
||
89 | add_results_names_align = self.align_para_names(add_results_names) |
||
90 | |||
91 | for best_additional_result in best_additional_results.keys(): |
||
92 | added_spaces = add_results_names_align[best_additional_result] |
||
93 | print( |
||
94 | indent, |
||
95 | indent, |
||
96 | "'{}'".format(best_additional_result), |
||
97 | "{}:".format(added_spaces), |
||
98 | best_additional_results[best_additional_result], |
||
99 | " ", |
||
100 | ) |
||
101 | |||
102 | if best_para: |
||
103 | print(indent, "Best parameter set:") |
||
104 | para_names = list(best_para.keys()) |
||
105 | para_names_align = self.align_para_names(para_names) |
||
106 | |||
107 | for para_key in best_para.keys(): |
||
108 | added_spaces = para_names_align[para_key] |
||
109 | print( |
||
110 | indent, |
||
111 | indent, |
||
112 | "'{}'".format(para_key), |
||
113 | "{}:".format(added_spaces), |
||
114 | best_para[para_key], |
||
115 | " ", |
||
116 | ) |
||
117 | |||
118 | print(indent, "Best iteration:", best_iter, " ") |
||
119 | |||
120 | print(" ") |
||
121 | print(indent, "Random seed:", random_seed, " ") |
||
122 | print(" ") |
||
123 | |||
170 |