You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Olá, comecei a estudar Machile Learning há alguns meses. Com isso comecei a estudar Redes Neurais. Tentei escrever um script para dá uma olhada no comportamento do Perceptron para entender melhor, no entanto, quando comecei a escrever o código e rodei o mesmo me deparei com o seguinte erro: AttributeError: 'Perceptron' object has no attribute 'fit'
#133
Closed
Gustavo-Ufersa opened this issue
Dec 10, 2022
· 3 comments
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap
from mlxtend.plotting import plot_decision_regions
Criação da classe perceptron:
class Perceptron:
def init(self, eta=0.01, n_iter=10):
self.eta = eta
self.n_iter = n_iter
Ola,
O Python é sensivel a identacao, que pode ser o problema do seu codigo. Pra ter certeza, melhor vc anexar o seu arquivo python .py com o codigo.
Tks
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap
from mlxtend.plotting import plot_decision_regions
Criação da classe perceptron:
class Perceptron:
def init(self, eta=0.01, n_iter=10):
self.eta = eta
self.n_iter = n_iter
Métodos da classe:
def fit(self, X, y):
self.w_ = np.zeros(1 + X.shape[1])
self.errors_ = []
def predict(self, X):
return np.where(self.net_input(X) >= 0.0, 1, -1)
def net_input(self, X):
return np.dot(X, self.w_[1:] + self.w_[0])
Criando o dataset
df = pd.read_csv('https://archive.ics.uci.edu/ml/''machine-learning-databases/iris/iris.data', header=None, encoding='utf-8')
df.tail()
y = df.iloc[0:100, 4].values
y = np.where(y == 'Iris-setosa', -1, 1)
X = df.iloc[0:100, [0, 2]].values
criando o plot
plt.scatter(X[:50, 0], X[:50, 1], color ='red', marker='o', label = 'setosa')
plt.scatter(X[50:100, 0], X[50:100, 1], color = 'blue', marker='o', label = 'versicolor')
plt.xlabel('pental lenght ')
plt.ylabel('sepal lenght ')
plt.legend(loc='upper left')
plt.show()
Treinamento do algoritmo
ppn = Perceptron(eta=0.1, n_iter=10)
ppn.fit(X, y)
The text was updated successfully, but these errors were encountered: