def test_fit(self): p = Perceptron() p.fit([[1, 2], [3, 4]], [0, 1]) self.assertEqual(p.is_trained, True) self.assertEqual(len(p.weights), 2)
from perceptron.perceptron import Perceptron import numpy as np X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]]) y = np.array([[0], [1], [1], [1]]) print("[INFO] training perceptron...") p = Perceptron(X.shape[1], alpha=0.1) p.fit(X, y, epochs=20) print("[INFO[ testing perceptron...") for (x, target) in zip(X, y): pred = p.predict(x) print("[INFO] data = {}. ground truth={}, pred = {}".format( x, target[0], pred))
from perceptron.perceptron import Perceptron from linear_discriminant_analysis.fisher_lda import FisherLDA import pandas as pd import numpy as np # Pereceptron Test df = pd.read_csv('datasets/dataset_1.csv', names=['X1', 'X2', 'y']) df['y'] = df['y'].replace(0, -1) print(df.head()) p = Perceptron(0.01, 20, 2, 0, '3', './images/') X = np.array(df[['X1', 'X2']]) y = df['y'] p.fit(X, y) # Fishers LDA Test disc = FisherLDA(dataset=1) disc.visualize()