From a74883865108d23338b731096107efd34f53cc6f Mon Sep 17 00:00:00 2001 From: algobytewise Date: Fri, 26 Mar 2021 15:14:02 +0530 Subject: [PATCH 1/6] Update perceptron.py --- neural_network/perceptron.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/neural_network/perceptron.py b/neural_network/perceptron.py index 23b409b227c4..9e651dce7c2b 100644 --- a/neural_network/perceptron.py +++ b/neural_network/perceptron.py @@ -11,7 +11,7 @@ class Perceptron: - def __init__(self, sample, target, learning_rate=0.01, epoch_number=1000, bias=-1): + def __init__(self, sample: list[list[float]], target: list[int], learning_rate: float = 0.01, epoch_number: int = 1000, bias: float = -1) -> None: """ Initializes a Perceptron network for oil analysis :param sample: sample dataset of 3 parameters with shape [30,3] @@ -46,7 +46,7 @@ def __init__(self, sample, target, learning_rate=0.01, epoch_number=1000, bias=- self.bias = bias self.number_sample = len(sample) self.col_sample = len(sample[0]) # number of columns in dataset - self.weight = [] + self.weight: list = [] def training(self) -> None: """ @@ -94,7 +94,7 @@ def training(self) -> None: # if epoch_count > self.epoch_number or not error: break - def sort(self, sample) -> None: + def sort(self, sample: list[float]) -> None: """ :param sample: example row to classify as P1 or P2 :return: None @@ -221,11 +221,11 @@ def sign(self, u: float) -> int: print("Finished training perceptron") print("Enter values to predict or q to exit") while True: - sample = [] + sample: list = [] for i in range(len(samples[0])): - observation = input("value: ").strip() - if observation == "q": + user_input = input("value: ").strip() + if user_input == "q": break - observation = float(observation) + observation = float(user_input) sample.insert(i, observation) network.sort(sample) From 294ffb107e512f38c5dfcf2ddb02743358b348de Mon Sep 17 00:00:00 2001 From: algobytewise Date: Fri, 26 Mar 2021 15:27:00 +0530 Subject: [PATCH 2/6] Update binary_tree_traversals.py --- traversals/binary_tree_traversals.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/traversals/binary_tree_traversals.py b/traversals/binary_tree_traversals.py index cb471ba55bac..f919a2962354 100644 --- a/traversals/binary_tree_traversals.py +++ b/traversals/binary_tree_traversals.py @@ -188,7 +188,7 @@ def pre_order_iter(node: TreeNode) -> None: """ if not isinstance(node, TreeNode) or not node: return - stack: List[TreeNode] = [] + stack: list[TreeNode] = [] n = node while n or stack: while n: # start from root node, find its left child @@ -218,7 +218,7 @@ def in_order_iter(node: TreeNode) -> None: """ if not isinstance(node, TreeNode) or not node: return - stack: List[TreeNode] = [] + stack: list[TreeNode] = [] n = node while n or stack: while n: From 32796e1e76d7a9c63fb941ab24d7de4ad6812a45 Mon Sep 17 00:00:00 2001 From: algobytewise Date: Fri, 26 Mar 2021 15:38:02 +0530 Subject: [PATCH 3/6] fix machine_learning --- machine_learning/forecasting/run.py | 4 ++-- machine_learning/k_means_clust.py | 2 +- machine_learning/word_frequency_functions.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/machine_learning/forecasting/run.py b/machine_learning/forecasting/run.py index 0e11f958825f..ae7aa21d4bec 100644 --- a/machine_learning/forecasting/run.py +++ b/machine_learning/forecasting/run.py @@ -29,8 +29,8 @@ def linear_regression_prediction( >>> abs(n - 5.0) < 1e-6 # Checking precision because of floating point errors True """ - x = [[1, item, train_mtch[i]] for i, item in enumerate(train_dt)] - x = np.array(x) + temp = [[1, item, train_mtch[i]] for i, item in enumerate(train_dt)] + x = np.array(temp) y = np.array(train_usr) beta = np.dot(np.dot(np.linalg.inv(np.dot(x.transpose(), x)), x.transpose()), y) return abs(beta[0] + test_dt[0] * beta[1] + test_mtch[0] + beta[2]) diff --git a/machine_learning/k_means_clust.py b/machine_learning/k_means_clust.py index f155d4845f41..c45be8a4c064 100644 --- a/machine_learning/k_means_clust.py +++ b/machine_learning/k_means_clust.py @@ -200,7 +200,7 @@ def kmeans( def ReportGenerator( - df: pd.DataFrame, ClusteringVariables: np.array, FillMissingReport=None + df: pd.DataFrame, ClusteringVariables: np.ndarray, FillMissingReport=None ) -> pd.DataFrame: """ Function generates easy-erading clustering report. It takes 2 arguments as an input: diff --git a/machine_learning/word_frequency_functions.py b/machine_learning/word_frequency_functions.py index 9cf7b694c6be..3e8faf39cf07 100644 --- a/machine_learning/word_frequency_functions.py +++ b/machine_learning/word_frequency_functions.py @@ -61,7 +61,7 @@ def term_frequency(term: str, document: str) -> int: return len([word for word in tokenize_document if word.lower() == term.lower()]) -def document_frequency(term: str, corpus: str) -> int: +def document_frequency(term: str, corpus: str) -> tuple[int, int]: """ Calculate the number of documents in a corpus that contain a given term From db7261120faabf024ff30a1cfb3e554e3bcac58e Mon Sep 17 00:00:00 2001 From: algobytewise Date: Fri, 26 Mar 2021 15:42:22 +0530 Subject: [PATCH 4/6] Update build.yml --- .github/workflows/build.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 74b885b90343..87cc8b67341d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,10 +38,13 @@ jobs: genetic_algorithm geodesy knapsack + machine_learning networking_flow + neural_network quantum scheduling sorts + traversals - name: Run tests run: pytest --doctest-modules --ignore=project_euler/ --ignore=scripts/ --cov-report=term-missing:skip-covered --cov=. . - if: ${{ success() }} From 27f561a2f35d058892499425b672d19ea9b9947f Mon Sep 17 00:00:00 2001 From: algobytewise Date: Fri, 26 Mar 2021 15:48:37 +0530 Subject: [PATCH 5/6] Update perceptron.py --- neural_network/perceptron.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/neural_network/perceptron.py b/neural_network/perceptron.py index 9e651dce7c2b..063be5ea554c 100644 --- a/neural_network/perceptron.py +++ b/neural_network/perceptron.py @@ -11,7 +11,14 @@ class Perceptron: - def __init__(self, sample: list[list[float]], target: list[int], learning_rate: float = 0.01, epoch_number: int = 1000, bias: float = -1) -> None: + def __init__( + self, + sample: list[list[float]], + target: list[int], + learning_rate: float = 0.01, + epoch_number: int = 1000, + bias: float = -1, + ) -> None: """ Initializes a Perceptron network for oil analysis :param sample: sample dataset of 3 parameters with shape [30,3] From db6ddb51b5a48c4ffc4c0404efa9b1881ae79f32 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 26 Mar 2021 12:02:34 +0100 Subject: [PATCH 6/6] Update machine_learning/forecasting/run.py --- machine_learning/forecasting/run.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/machine_learning/forecasting/run.py b/machine_learning/forecasting/run.py index ae7aa21d4bec..b11a230129eb 100644 --- a/machine_learning/forecasting/run.py +++ b/machine_learning/forecasting/run.py @@ -29,8 +29,7 @@ def linear_regression_prediction( >>> abs(n - 5.0) < 1e-6 # Checking precision because of floating point errors True """ - temp = [[1, item, train_mtch[i]] for i, item in enumerate(train_dt)] - x = np.array(temp) + x = np.array([[1, item, train_mtch[i]] for i, item in enumerate(train_dt)]) y = np.array(train_usr) beta = np.dot(np.dot(np.linalg.inv(np.dot(x.transpose(), x)), x.transpose()), y) return abs(beta[0] + test_dt[0] * beta[1] + test_mtch[0] + beta[2])