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 | """Results printing utilities for hyperparameter optimization. |
||
75 | def _print_results( |
||
76 | self, |
||
77 | objective_function, |
||
78 | best_score, |
||
79 | best_para, |
||
80 | best_iter, |
||
81 | best_additional_results, |
||
82 | random_seed, |
||
83 | ): |
||
84 | print(f"\nResults: '{objective_function.__name__}'", " ") |
||
85 | if best_para is None: |
||
86 | print(indent, "Best score:", best_score, " ") |
||
87 | print(indent, "Best parameter set:", best_para, " ") |
||
88 | print(indent, "Best iteration:", best_iter, " ") |
||
89 | |||
90 | else: |
||
91 | print(indent, "Best score:", best_score, " ") |
||
92 | |||
93 | if best_additional_results: |
||
94 | print(indent, "Best additional results:") |
||
95 | add_results_names = list(best_additional_results.keys()) |
||
96 | add_results_names_align = self.align_para_names(add_results_names) |
||
97 | |||
98 | for best_additional_result in best_additional_results.keys(): |
||
99 | added_spaces = add_results_names_align[best_additional_result] |
||
100 | print( |
||
101 | indent, |
||
102 | indent, |
||
103 | f"'{best_additional_result}'", |
||
104 | f"{added_spaces}:", |
||
105 | best_additional_results[best_additional_result], |
||
106 | " ", |
||
107 | ) |
||
108 | |||
109 | if best_para: |
||
110 | print(indent, "Best parameter set:") |
||
111 | para_names = list(best_para.keys()) |
||
112 | para_names_align = self.align_para_names(para_names) |
||
113 | |||
114 | for para_key in best_para.keys(): |
||
115 | added_spaces = para_names_align[para_key] |
||
116 | print( |
||
117 | indent, |
||
118 | indent, |
||
119 | f"'{para_key}'", |
||
120 | f"{added_spaces}:", |
||
121 | best_para[para_key], |
||
122 | " ", |
||
123 | ) |
||
124 | |||
125 | print(indent, "Best iteration:", best_iter, " ") |
||
126 | |||
127 | print(" ") |
||
128 | print(indent, "Random seed:", random_seed, " ") |
||
129 | print(" ") |
||
130 | |||
178 |