daily pastebin goal
8%
SHARE
TWEET

Untitled

a guest Mar 21st, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pandas as pd
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4.  
  5. class AdalineGB():
  6.     def __init__(self, rychlost_ucenia=0.01, pocet_iteracii=10):
  7.         self.rychlost_ucenia = rychlost_ucenia
  8.         self.pocet_iteracii = pocet_iteracii      
  9.    
  10.     def fit(self, X,y):
  11.         self.w = np.zeros(1+ X.shape[1])
  12.         self.costs= []
  13.        
  14.         for i in range(self.pocet_iteracii):
  15.             output = self.net_input(X)
  16.             errors = (y - output)
  17.            
  18.             self.w[1:] += self.rychlost_ucenia * X.T.dot(errors)
  19.             self.w[0] += self.rychlost_ucenia * errors.sum()
  20.  
  21.             cost=(errors ** 2).sum()/2.0
  22.             self.costs.append(cost)
  23.         return self
  24.  
  25.     def net_input(self, X):
  26.         return np.dot(X, self.w[1:])+ self.w[0]
  27.    
  28.     def linearna_aktivacia(self, X):
  29.         return self.net_input(X)
  30.  
  31.     def predikcia(self, X):
  32.         return np.where(self.linearna_aktivacia(X) >= 0.0, 1, -1)
  33.  
  34. kvetiny = pd.read_csv('kvetiny.csv', index_col = None)
  35.    
  36. x = kvetiny.iloc[0:100, [0,2]].values
  37. y = kvetiny.iloc[0:100, 4].values
  38.  
  39. y = np.where(y == 'Iris-setosa', -1, 1)
  40. ppn = AdalineGB()
  41. ppn.fit(x,y)
  42.  
  43. plt.plot(ppn.costs)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top