Conversation
| @@ -11,6 +11,7 @@ | |||
|
|
|||
| """ | |||
|
|
|||
There was a problem hiding this comment.
Lines 36-40 refactored with the following changes:
- Replace manual loop counter with call to enumerate (
convert-to-enumerate)
This removes the following comments ( why? ):
# counter
| num_correct = sum(int(a == y) for a, y in zip(predictions, test_data[1])) | ||
| print("Baseline classifier using an SVM.") | ||
| print(str(num_correct) + " of " + str(len(test_data[1])) + " values correct.") | ||
| print(f'{str(num_correct)} of {len(test_data[1])} values correct.') |
There was a problem hiding this comment.
Function svm_baseline refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Remove unnecessary calls to
str()from formatted values in f-strings (remove-str-from-fstring)
| print("Epoch {} : {} / {}".format(j,self.evaluate(test_data),n_test)) | ||
| print(f"Epoch {j} : {self.evaluate(test_data)} / {n_test}") | ||
| else: | ||
| print("Epoch {} complete".format(j)) | ||
| print(f"Epoch {j} complete") |
There was a problem hiding this comment.
Function Network.SGD refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting)
| print("Epoch %s training complete" % j) | ||
| print(f"Epoch {j} training complete") | ||
|
|
||
| if monitor_training_cost: | ||
| cost = self.total_cost(training_data, lmbda) | ||
| training_cost.append(cost) | ||
| print("Cost on training data: {}".format(cost)) | ||
| print(f"Cost on training data: {cost}") | ||
| if monitor_training_accuracy: | ||
| accuracy = self.accuracy(training_data, convert=True) | ||
| training_accuracy.append(accuracy) | ||
| print("Accuracy on training data: {} / {}".format(accuracy, n)) | ||
| print(f"Accuracy on training data: {accuracy} / {n}") | ||
| if monitor_evaluation_cost: | ||
| cost = self.total_cost(evaluation_data, lmbda, convert=True) | ||
| evaluation_cost.append(cost) | ||
| print("Cost on evaluation data: {}".format(cost)) | ||
| print(f"Cost on evaluation data: {cost}") | ||
| if monitor_evaluation_accuracy: | ||
| accuracy = self.accuracy(evaluation_data) | ||
| evaluation_accuracy.append(accuracy) | ||
| print("Accuracy on evaluation data: {} / {}".format(self.accuracy(evaluation_data), n_data)) | ||
| print( | ||
| f"Accuracy on evaluation data: {self.accuracy(evaluation_data)} / {n_data}" | ||
| ) | ||
|
|
There was a problem hiding this comment.
Function Network.SGD refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring) - Replace call to format with f-string. (
use-fstring-for-formatting)
| result_accuracy = sum(int(x == y) for (x, y) in results) | ||
| return result_accuracy | ||
| return sum(int(x == y) for (x, y) in results) |
There was a problem hiding this comment.
Function Network.accuracy refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| f = open(filename, "w") | ||
| json.dump(data, f) | ||
| f.close() | ||
| with open(filename, "w") as f: | ||
| json.dump(data, f) |
There was a problem hiding this comment.
Function Network.save refactored with the following changes:
- Use
withwhen opening file to ensure closure (ensure-file-closed)
| f = open(filename, "r") | ||
| data = json.load(f) | ||
| f.close() | ||
| with open(filename, "r") as f: | ||
| data = json.load(f) |
There was a problem hiding this comment.
Function load refactored with the following changes:
- Use
withwhen opening file to ensure closure (ensure-file-closed)
|
|
||
| # define the (regularized) cost function, symbolic gradients, and updates | ||
| l2_norm_squared = sum([(layer.w**2).sum() for layer in self.layers]) | ||
| l2_norm_squared = sum((layer.w**2).sum() for layer in self.layers) |
There was a problem hiding this comment.
Function Network.SGD refactored with the following changes:
- Replace unneeded comprehension with generator (
comprehension-to-generator)
| for i in range(iters): | ||
| for _ in range(iters): | ||
| r = f() | ||
| t1 = time.time() | ||
| print("Looping %d times took %f seconds" % (iters, t1 - t0)) | ||
| print("Result is %s" % (r,)) | ||
| print(f"Result is {r}") |
There was a problem hiding this comment.
Function testTheano refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring)
Sourcery Code Quality Report❌ Merging this PR will decrease code quality in the affected files by 0.03%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
Branch
masterrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
masterbranch, then run:Help us improve this pull request!