|
11 | 11 |
|
12 | 12 |
|
13 | 13 | class Perceptron:
|
14 |
| - def __init__(self, sample, target, learning_rate=0.01, epoch_number=1000, bias=-1): |
| 14 | + def __init__( |
| 15 | + self, |
| 16 | + sample: list[list[float]], |
| 17 | + target: list[int], |
| 18 | + learning_rate: float = 0.01, |
| 19 | + epoch_number: int = 1000, |
| 20 | + bias: float = -1, |
| 21 | + ) -> None: |
15 | 22 | """
|
16 | 23 | Initializes a Perceptron network for oil analysis
|
17 | 24 | :param sample: sample dataset of 3 parameters with shape [30,3]
|
@@ -46,7 +53,7 @@ def __init__(self, sample, target, learning_rate=0.01, epoch_number=1000, bias=-
|
46 | 53 | self.bias = bias
|
47 | 54 | self.number_sample = len(sample)
|
48 | 55 | self.col_sample = len(sample[0]) # number of columns in dataset
|
49 |
| - self.weight = [] |
| 56 | + self.weight: list = [] |
50 | 57 |
|
51 | 58 | def training(self) -> None:
|
52 | 59 | """
|
@@ -94,7 +101,7 @@ def training(self) -> None:
|
94 | 101 | # if epoch_count > self.epoch_number or not error:
|
95 | 102 | break
|
96 | 103 |
|
97 |
| - def sort(self, sample) -> None: |
| 104 | + def sort(self, sample: list[float]) -> None: |
98 | 105 | """
|
99 | 106 | :param sample: example row to classify as P1 or P2
|
100 | 107 | :return: None
|
@@ -221,11 +228,11 @@ def sign(self, u: float) -> int:
|
221 | 228 | print("Finished training perceptron")
|
222 | 229 | print("Enter values to predict or q to exit")
|
223 | 230 | while True:
|
224 |
| - sample = [] |
| 231 | + sample: list = [] |
225 | 232 | for i in range(len(samples[0])):
|
226 |
| - observation = input("value: ").strip() |
227 |
| - if observation == "q": |
| 233 | + user_input = input("value: ").strip() |
| 234 | + if user_input == "q": |
228 | 235 | break
|
229 |
| - observation = float(observation) |
| 236 | + observation = float(user_input) |
230 | 237 | sample.insert(i, observation)
|
231 | 238 | network.sort(sample)
|
0 commit comments