SHARE
TWEET

nn

a guest May 7th, 2020 75 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. from keras.models import Sequential
  5. from keras.layers import Dense
  6. from sklearn.model_selection import train_test_split
  7.  
  8. nn_0_data = pd.read_csv('nn_0.csv')
  9. plt.scatter(nn_0_data.loc[nn_0_data['class'] == -1]['X1'].values, nn_0_data.loc[nn_0_data['class'] == -1]['X2'].values, c='r')
  10. plt.scatter(nn_0_data.loc[nn_0_data['class'] == 1]['X1'].values, nn_0_data.loc[nn_0_data['class'] == 1]['X2'].values, c='b')
  11. plt.show()
  12.  
  13. y = nn_0_data.loc[:,'class':]
  14. y = y.values.ravel()
  15. X = nn_0_data.loc[:,'X1':'X2']
  16. X = X.values.tolist()
  17. y = [0 if i == -1 else 1 for i in y]
  18. X = np.array(X)
  19. y = np.array(y)
  20.  
  21. model = Sequential()
  22. model.add(Dense(1, input_dim=2))
  23. model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
  24. print(model.summary())
  25.  
  26. X_train, X_test, y_train, y_test = train_test_split(X, y, shuffle=True, test_size = 0.25, random_state=42)
  27. model.fit(X_train, y_train, epochs=10, batch_size=2)
  28.  
  29. print(X_test)
  30. model.evaluate(X_test, y_test)
  31. model.predict(X_test)
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