Skip to content

Commit d727046

Browse files
committed
Fixing Pylint errors.
1 parent d8a8241 commit d727046

File tree

12 files changed

+39
-11
lines changed

12 files changed

+39
-11
lines changed
+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
"""Anomaly Detection Module"""
2+
13
from .gaussian_anomaly_detection import GaussianAnomalyDetection

homemade/anomaly_detection/gaussian_anomaly_detection.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Anomaly Detection Module"""
2+
13
import numpy as np
24
import math
35

@@ -81,25 +83,25 @@ def select_threshold(labels, probabilities):
8183

8284
# The number of false positives: the ground truth label says it’s not
8385
# an anomaly, but our algorithm incorrectly classified it as an anomaly.
84-
fp = np.sum((predictions == 1) & (labels == 0))
86+
false_positives = np.sum((predictions == 1) & (labels == 0))
8587

8688
# The number of false negatives: the ground truth label says it’s an anomaly,
8789
# but our algorithm incorrectly classified it as not being anomalous.
88-
fn = np.sum((predictions == 0) & (labels == 1))
90+
false_negatives = np.sum((predictions == 0) & (labels == 1))
8991

9092
# The number of true positives: the ground truth label says it’s an
9193
# anomaly and our algorithm correctly classified it as an anomaly.
92-
tp = np.sum((predictions == 1) & (labels == 1))
94+
true_positives = np.sum((predictions == 1) & (labels == 1))
9395

9496
# Prevent division by zero.
95-
if (tp + fp) == 0 or (tp + fn) == 0:
97+
if (true_positives + false_positives) == 0 or (true_positives + false_negatives) == 0:
9698
continue
9799

98100
# Precision.
99-
precision = tp / (tp + fp)
101+
precision = true_positives / (true_positives + false_positives)
100102

101103
# Recall.
102-
recall = tp / (tp + fn)
104+
recall = true_positives / (true_positives + false_negatives)
103105

104106
# F1.
105107
f1 = 2 * precision * recall / (precision + recall)

homemade/k_means/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
"""KMeans Module"""
2+
13
from .k_means import KMeans

homemade/k_means/k_means.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""KMeans Module"""
2+
13
import numpy as np
24

35

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
"""Linear Regression Module"""
2+
13
from .linear_regression import LinearRegression
+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
"""Logistic Regression Module"""
2+
13
from .logistic_regression import LogisticRegression

homemade/logistic_regression/logistic_regression.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Logistic Regression Module"""
2+
13
import numpy as np
24
from scipy.optimize import minimize
35
from ..utils.features import prepare_for_training
@@ -75,6 +77,8 @@ def train(self, lambda_param=0, max_iterations=1000):
7577
return self.thetas, cost_histories
7678

7779
def predict(self, data):
80+
"""Prediction function"""
81+
7882
num_examples = data.shape[0]
7983

8084
data_processed = prepare_for_training(

homemade/neural_network/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
"""Neural Network Module"""
2+
13
from .multilayer_perceptron import MultilayerPerceptron

homemade/neural_network/multilayer_perceptron.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Neural Network Module"""
2+
13
import numpy as np
24
from ..utils.features import prepare_for_training
35
from ..utils.hypothesis import sigmoid, sigmoid_gradient
@@ -29,6 +31,8 @@ def __init__(self, data, labels, layers, epsilon, normalize_data=False):
2931
self.thetas = MultilayerPerceptron.thetas_init(layers, epsilon)
3032

3133
def train(self, regularization_param=0, max_iterations=1000, alpha=1):
34+
"""Train the model"""
35+
3236
# Flatten model thetas for gradient descent.
3337
unrolled_thetas = MultilayerPerceptron.thetas_unroll(self.thetas)
3438

@@ -65,7 +69,7 @@ def predict(self, data):
6569

6670
@staticmethod
6771
def gradient_descent(
68-
data, labels, unrolled_theta, layers, regularization_param, max_iteration, alpha
72+
data, labels, unrolled_theta, layers, regularization_param, max_iteration, alpha
6973
):
7074
"""Gradient descent function.
7175
@@ -187,6 +191,8 @@ def cost_function(data, labels, thetas, layers, regularization_param):
187191

188192
@staticmethod
189193
def feedforward_propagation(data, thetas, layers):
194+
"""Feedforward propagation function"""
195+
190196
# Calculate the total number of layers.
191197
num_layers = len(layers)
192198

homemade/utils/features/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Dataset Features Related Utils"""
2+
13
from .normalize import normalize
24
from .add_polynomials import add_polynomials
35
from .add_sinusoids import add_sinusoids

homemade/utils/hypothesis/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
"""Dataset Hypothesis Related Utils"""
2+
13
from .sigmoid import sigmoid
24
from .sigmoid_gradient import sigmoid_gradient

notebooks/anomaly_detection/anomaly_detection_gaussian_demo.ipynb

+4-4
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@
377377
},
378378
{
379379
"cell_type": "code",
380-
"execution_count": 11,
380+
"execution_count": 8,
381381
"metadata": {},
382382
"outputs": [
383383
{
@@ -426,7 +426,7 @@
426426
},
427427
{
428428
"cell_type": "code",
429-
"execution_count": 19,
429+
"execution_count": 9,
430430
"metadata": {},
431431
"outputs": [
432432
{
@@ -482,7 +482,7 @@
482482
},
483483
{
484484
"cell_type": "code",
485-
"execution_count": 25,
485+
"execution_count": 10,
486486
"metadata": {},
487487
"outputs": [
488488
{
@@ -491,7 +491,7 @@
491491
"[]"
492492
]
493493
},
494-
"execution_count": 25,
494+
"execution_count": 10,
495495
"metadata": {},
496496
"output_type": "execute_result"
497497
},

0 commit comments

Comments
 (0)