Ejemplo n.º 1
0
 def test_perc_not(self):
     p_not = neurons.Perceptron([-1], 0.5)
     self.assertEqual(p_not.feed([0]), 1)
     self.assertEqual(p_not.feed([1]), 0)
Ejemplo n.º 2
0
 def test_perc_nand(self):
     p_nand = neurons.Perceptron([-2, -2], 3)
     self.assertEqual(p_nand.feed([0, 0]), 1)
     self.assertEqual(p_nand.feed([0, 1]), 1)
     self.assertEqual(p_nand.feed([1, 0]), 1)
     self.assertEqual(p_nand.feed([1, 1]), 0)
Ejemplo n.º 3
0
 def test_perc_or(self):
     p_or = neurons.Perceptron([1, 1], -0.5)
     self.assertEqual(p_or.feed([0, 0]), 0)
     self.assertEqual(p_or.feed([0, 1]), 1)
     self.assertEqual(p_or.feed([1, 0]), 1)
     self.assertEqual(p_or.feed([1, 1]), 1)
Ejemplo n.º 4
0
 def test_perc_and(self):
     p_and = neurons.Perceptron([1, 1], -1.5)
     self.assertEqual(p_and.feed([0, 0]), 0)
     self.assertEqual(p_and.feed([0, 1]), 0)
     self.assertEqual(p_and.feed([1, 0]), 0)
     self.assertEqual(p_and.feed([1, 1]), 1)
Ejemplo n.º 5
0
import pandas as pd

# Needed for VScode to function correctly, can be deleted for normal operation
os.chdir(
    '/home/cameron/Dropbox/University/PhD/Teaching/COMP219-AI/PythonMachineLearning/chapter02'
)

import neurons
import plot

df = pd.read_csv('iris.data', header=None)

# Select setosa and versicolor
y = df.iloc[0:150, 4].values
y = np.where(y == 'Iris-virginica', -1, 1)

# extract sepal length and petal length
X = df.iloc[0:150, [1, 3]].values

plot.plotSetosaVersicolor(X)

ppn = neurons.Perceptron(eta=0.1, n_iter=10)
ppn.fit(X, y)

plot.plotEpochUpdates(ppn)
# plot.plotDecisionRegions(X, y, ppn)

#ada = neurons.AdalineGD(eta=0.1, n_iter=10)
#ada.fit(X, y)
# plot.plotDecisionRegions(X, y, ppn)