@@ -28,11 +28,11 @@ class Perceptron:
2828 Examples:
2929 ---------
3030 >>> import numpy as np
31- >>> X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
31+ >>> samples = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
3232 >>> y = np.array([0, 0, 0, 1])
3333 >>> perceptron = Perceptron(learning_rate=0.1, epochs=10)
34- >>> _ = perceptron.fit(X , y)
35- >>> perceptron.predict(X ).tolist()
34+ >>> _ = perceptron.fit(samples , y)
35+ >>> perceptron.predict(samples ).tolist()
3636 [0, 0, 0, 1]
3737 """
3838
@@ -43,13 +43,13 @@ def __init__(self, learning_rate: float = 0.01, epochs: int = 1000) -> None:
4343 self .bias = 0.0
4444 self .errors = []
4545
46- def fit (self , X : np .ndarray , y : np .ndarray ) -> "Perceptron" :
46+ def fit (self , samples : np .ndarray , y : np .ndarray ) -> "Perceptron" :
4747 """
4848 Fit training data.
4949
5050 Parameters:
5151 -----------
52- X : shape = [n_samples, n_features]
52+ samples : shape = [n_samples, n_features]
5353 Training vectors, where n_samples is the number of samples
5454 and n_features is the number of features.
5555 y : shape = [n_samples]
@@ -62,19 +62,19 @@ def fit(self, X: np.ndarray, y: np.ndarray) -> "Perceptron":
6262 Examples:
6363 ---------
6464 >>> import numpy as np
65- >>> X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
65+ >>> samples = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
6666 >>> y = np.array([0, 0, 0, 1])
6767 >>> perceptron = Perceptron(learning_rate=0.1, epochs=10)
68- >>> _ = perceptron.fit(X , y)
68+ >>> _ = perceptron.fit(samples , y)
6969 """
70- n_samples , n_features = X .shape
70+ _ , n_features = samples .shape
7171 self .weights = np .zeros (n_features )
7272 self .bias = 0.0
7373 self .errors = []
7474
7575 for _ in range (self .epochs ):
7676 errors = 0
77- for xi , target in zip (X , y ):
77+ for xi , target in zip (samples , y ):
7878 # Calculate update
7979 update = self .learning_rate * (target - self .predict (xi ))
8080 self .weights += update * xi
@@ -83,21 +83,21 @@ def fit(self, X: np.ndarray, y: np.ndarray) -> "Perceptron":
8383 self .errors .append (errors )
8484 return self
8585
86- def predict (self , X : np .ndarray ) -> np .ndarray :
86+ def predict (self , samples : np .ndarray ) -> np .ndarray :
8787 """
8888 Return class label after unit step
8989
9090 Examples:
9191 ---------
9292 >>> import numpy as np
93- >>> X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
93+ >>> samples = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
9494 >>> y = np.array([0, 0, 0, 1])
9595 >>> perceptron = Perceptron(learning_rate=0.1, epochs=10)
96- >>> _ = perceptron.fit(X , y)
97- >>> perceptron.predict(X ).tolist()
96+ >>> _ = perceptron.fit(samples , y)
97+ >>> perceptron.predict(samples ).tolist()
9898 [0, 0, 0, 1]
9999 """
100- linear_output = np .dot (X , self .weights ) + self .bias
100+ linear_output = np .dot (samples , self .weights ) + self .bias
101101 return self .activation_function (linear_output )
102102
103103 def activation_function (self , x : np .ndarray ) -> np .ndarray :
@@ -120,12 +120,12 @@ def activation_function(self, x: np.ndarray) -> np.ndarray:
120120 doctest .testmod ()
121121
122122 # Example usage
123- X = np .array ([[0 , 0 ], [0 , 1 ], [1 , 0 ], [1 , 1 ]])
123+ samples = np .array ([[0 , 0 ], [0 , 1 ], [1 , 0 ], [1 , 1 ]])
124124 y = np .array ([0 , 0 , 0 , 1 ]) # AND gate
125125
126126 perceptron = Perceptron (learning_rate = 0.1 , epochs = 10 )
127- perceptron .fit (X , y )
127+ perceptron .fit (samples , y )
128128
129129 print ("Weights:" , perceptron .weights )
130130 print ("Bias:" , perceptron .bias )
131- print ("Predictions:" , perceptron .predict (X ))
131+ print ("Predictions:" , perceptron .predict (samples ))
0 commit comments