Advertisement
lancernik

Untitled

May 28th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. Created on Tue May 28 15:38:30 2019
  5.  
  6. @author: student
  7. """
  8.  
  9. from sklearn import datasets
  10. from keras.models import Sequential
  11. from keras.layers import Dense
  12. import numpy as np
  13. from sklearn.model_selection import train_test_split
  14.  
  15.  
  16. iris = datasets.load_iris()
  17.  
  18. X = iris.data
  19.  
  20. y_dozmiany = iris.target
  21. y_dozmiany = np.where(y_dozmiany==0, 4, y_dozmiany)
  22. y_dozmiany = np.where(y_dozmiany==1, 0, y_dozmiany)
  23. y_dozmiany = np.where(y_dozmiany==2, 0, y_dozmiany)
  24. Y = np.where(y_dozmiany==4, 1, y_dozmiany)
  25.  
  26.  
  27. X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.33, random_state=42)
  28.  
  29.  
  30. model = Sequential()
  31. model.add(Dense(12,input_shape=(4,), activation='relu'))
  32. model.add(Dense(8, activation='relu'))
  33. model.add(Dense(1, activation='sigmoid'))
  34. model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
  35. model.fit(X_train, y_train, epochs=150, batch_size=10)
  36.  
  37.  
  38.  
  39.  
  40.  
  41. predictions = model.predict(X_test)
  42. # round predictions
  43. rounded = [round(x[0]) for x in predictions]
  44. print(rounded[0:10])
  45. print(y_test[0:10])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement