mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 23:11:09 +00:00
Test the exception conditions (#1853)
* Text exception conditions These are ValueErrors, not AttributeErrors. * fixup! Format Python code with psf/black push * Update perceptron.py * Update perceptron.py * Update perceptron.py * Revert the test Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
parent
3735e74296
commit
7ebe2b9593
|
@ -19,17 +19,28 @@ class Perceptron:
|
||||||
:param learning_rate: learning rate used in optimizing.
|
:param learning_rate: learning rate used in optimizing.
|
||||||
:param epoch_number: number of epochs to train network on.
|
:param epoch_number: number of epochs to train network on.
|
||||||
:param bias: bias value for the network.
|
:param bias: bias value for the network.
|
||||||
|
|
||||||
|
>>> p = Perceptron([], (0, 1, 2))
|
||||||
|
Traceback (most recent call last):
|
||||||
|
...
|
||||||
|
ValueError: Sample data can not be empty
|
||||||
|
>>> p = Perceptron(([0], 1, 2), [])
|
||||||
|
Traceback (most recent call last):
|
||||||
|
...
|
||||||
|
ValueError: Target data can not be empty
|
||||||
|
>>> p = Perceptron(([0], 1, 2), (0, 1))
|
||||||
|
Traceback (most recent call last):
|
||||||
|
...
|
||||||
|
ValueError: Sample data and Target data do not have matching lengths
|
||||||
"""
|
"""
|
||||||
self.sample = sample
|
self.sample = sample
|
||||||
if len(self.sample) == 0:
|
if len(self.sample) == 0:
|
||||||
raise AttributeError("Sample data can not be empty")
|
raise ValueError("Sample data can not be empty")
|
||||||
self.target = target
|
self.target = target
|
||||||
if len(self.target) == 0:
|
if len(self.target) == 0:
|
||||||
raise AttributeError("Target data can not be empty")
|
raise ValueError("Target data can not be empty")
|
||||||
if len(self.sample) != len(self.target):
|
if len(self.sample) != len(self.target):
|
||||||
raise AttributeError(
|
raise ValueError("Sample data and Target data do not have matching lengths")
|
||||||
"Sample data and Target data do not have matching lengths"
|
|
||||||
)
|
|
||||||
self.learning_rate = learning_rate
|
self.learning_rate = learning_rate
|
||||||
self.epoch_number = epoch_number
|
self.epoch_number = epoch_number
|
||||||
self.bias = bias
|
self.bias = bias
|
||||||
|
@ -98,7 +109,7 @@ class Perceptron:
|
||||||
classification: P...
|
classification: P...
|
||||||
"""
|
"""
|
||||||
if len(self.sample) == 0:
|
if len(self.sample) == 0:
|
||||||
raise AttributeError("Sample data can not be empty")
|
raise ValueError("Sample data can not be empty")
|
||||||
sample.insert(0, self.bias)
|
sample.insert(0, self.bias)
|
||||||
u = 0
|
u = 0
|
||||||
for i in range(self.col_sample + 1):
|
for i in range(self.col_sample + 1):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user