Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Mon Jan 21 09:29:51 2019
  4.  
  5. @author: sunny
  6. """
  7. import numpy as np
  8. from sklearn import datasets
  9. Iris = datasets.load_iris()
  10. x = Iris.data
  11. y=Iris.target
  12.  
  13. #df = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/Iris/Iris-data)
  14. from sklearn.model_selection import train_test_split
  15. x_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.2)
  16.  
  17. from sklearn.preprocessing import StandardScaler
  18. sc = StandardScaler()
  19. sc.fit(x_train)
  20. x_train_std = sc.transform(x_train)
  21. x_test_std = sc.transform(x_test)
  22.  
  23.  
  24. from sklearn.linear_model import Perceptron
  25. ppn = Perceptron(max_iter=40,eta0 = 0.1,random_state=0)
  26. ppn.fit(x_train_std,y_train)
  27.  
  28. y_pred = ppn.predict(x_test_std)
  29. print('Misclassified samples : %d '%(y_test !=y_pred).sum())
  30.  
  31. from sklearn.metrics import accuracy_score
  32. print('Accuracy: %.2f'%accuracy_score(y_test,y_pred))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement