| Conditions | 6 |
| Total Lines | 59 |
| Code Lines | 46 |
| 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 | experiment, |
||
| 71 | best_score, |
||
| 72 | best_para, |
||
| 73 | best_iter, |
||
| 74 | best_additional_results, |
||
| 75 | random_seed, |
||
| 76 | ): |
||
| 77 | print("\nResults: '{}'".format(experiment.__class__.__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( |
||
| 90 | add_results_names |
||
| 91 | ) |
||
| 92 | |||
| 93 | for best_additional_result in best_additional_results.keys(): |
||
| 94 | added_spaces = add_results_names_align[ |
||
| 95 | best_additional_result |
||
| 96 | ] |
||
| 97 | print( |
||
| 98 | indent, |
||
| 99 | indent, |
||
| 100 | "'{}'".format(best_additional_result), |
||
| 101 | "{}:".format(added_spaces), |
||
| 102 | best_additional_results[best_additional_result], |
||
| 103 | " ", |
||
| 104 | ) |
||
| 105 | |||
| 106 | if best_para: |
||
| 107 | print(indent, "Best parameter set:") |
||
| 108 | para_names = list(best_para.keys()) |
||
| 109 | para_names_align = self.align_para_names(para_names) |
||
| 110 | |||
| 111 | for para_key in best_para.keys(): |
||
| 112 | added_spaces = para_names_align[para_key] |
||
| 113 | print( |
||
| 114 | indent, |
||
| 115 | indent, |
||
| 116 | "'{}'".format(para_key), |
||
| 117 | "{}:".format(added_spaces), |
||
| 118 | best_para[para_key], |
||
| 119 | " ", |
||
| 120 | ) |
||
| 121 | |||
| 122 | print(indent, "Best iteration:", best_iter, " ") |
||
| 123 | |||
| 124 | print(" ") |
||
| 125 | print(indent, "Random seed:", random_seed, " ") |
||
| 126 | print(" ") |
||
| 127 | |||
| 174 |