Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import numpy as np
- import matplotlib.pyplot as plt
- class AdalineGB():
- def __init__(self, rychlost_ucenia=0.01, pocet_iteracii=10):
- self.rychlost_ucenia = rychlost_ucenia
- self.pocet_iteracii = pocet_iteracii
- def fit(self, X,y):
- self.w = np.zeros(1+ X.shape[1])
- self.costs= []
- for i in range(self.pocet_iteracii):
- output = self.net_input(X)
- errors = (y - output)
- self.w[1:] += self.rychlost_ucenia * X.T.dot(errors)
- self.w[0] += self.rychlost_ucenia * errors.sum()
- cost=(errors ** 2).sum()/2.0
- self.costs.append(cost)
- return self
- def net_input(self, X):
- return np.dot(X, self.w[1:])+ self.w[0]
- def linearna_aktivacia(self, X):
- return self.net_input(X)
- def predikcia(self, X):
- return np.where(self.linearna_aktivacia(X) >= 0.0, 1, -1)
- kvetiny = pd.read_csv('kvetiny.csv', index_col = None)
- x = kvetiny.iloc[0:100, [0,2]].values
- y = kvetiny.iloc[0:100, 4].values
- y = np.where(y == 'Iris-setosa', -1, 1)
- ppn = AdalineGB()
- ppn.fit(x,y)
- plt.plot(ppn.costs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement