-
Notifications
You must be signed in to change notification settings - Fork 0
/
class6Perceptron.py
39 lines (31 loc) · 1.23 KB
/
class6Perceptron.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# -*- coding: utf-8 -*-
import pandas as pd
from SpecialTopicsinLearning.Perceptron import Perceptron
import numpy as np
from sklearn import datasets
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
def main():
'''Instanciando a classe do método'''
p = Perceptron(4)
iris = datasets.load_iris()
df = pd.DataFrame(data=iris.data, columns=['A', 'B', 'C', 'D'])
df['target'] = iris.target
train, test = train_test_split(df[df['target'] != 2], test_size=0.2)
# p.fit(X=np.array([[0,0],[0,1],[1,0],[1,1]]), Y=np.array([0,1,1,0]))
p.fit(X=train.iloc[:,0:4].values, Y=train.iloc[:,4:].values)
for x in range(len(test)):
print("\n\t" + "#"*10 + " Predicted " + "#"*9)
print("\t" + "#"*30)
input = test.iloc[x,0:4].values
# input = np.array([[0,x]])
print("\tInputs: {}".format(input))
print("\tPredicted Class: {}".format(p.predict(input)))
print("\tY: {}".format(test.iloc[x,4:].values))
# print("\tY: {}".format(x))
print("\tWeights: {}".format(p.weights))
print("\t" + "#"*30 + "\n")
# plt.scatter(train.iloc[:,0].values,train.iloc[:,1].values)
# plt.show()
if __name__ == '__main__':
main()