Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- Created on Tue May 28 15:38:30 2019
- @author: student
- """
- from sklearn import datasets
- from keras.models import Sequential
- from keras.layers import Dense
- import numpy as np
- from sklearn.model_selection import train_test_split
- iris = datasets.load_iris()
- X = iris.data
- y_dozmiany = iris.target
- y_dozmiany = np.where(y_dozmiany==0, 4, y_dozmiany)
- y_dozmiany = np.where(y_dozmiany==1, 0, y_dozmiany)
- y_dozmiany = np.where(y_dozmiany==2, 0, y_dozmiany)
- Y = np.where(y_dozmiany==4, 1, y_dozmiany)
- X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.33, random_state=42)
- model = Sequential()
- model.add(Dense(12,input_shape=(4,), activation='relu'))
- model.add(Dense(8, activation='relu'))
- model.add(Dense(1, activation='sigmoid'))
- model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
- model.fit(X_train, y_train, epochs=150, batch_size=10)
- predictions = model.predict(X_test)
- # round predictions
- rounded = [round(x[0]) for x in predictions]
- print(rounded[0:10])
- print(y_test[0:10])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement