teceai

Untitled

May 4th, 2021
561
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pandas as pd
  2. from tensorflow import keras
  3. from sklearn.metrics import accuracy_score
  4.  
  5.  
  6. df = pd.read_csv('/datasets/train_data_n.csv')
  7. df['target'] = (df['target'] > df['target'].median()).astype(int)
  8. features_train = df.drop('target', axis=1)
  9. target_train = df['target']
  10.  
  11. df_val = pd.read_csv('/datasets/test_data_n.csv')
  12. df_val['target'] = (df_val['target'] > df['target'].median()).astype(int)
  13. features_valid = df_val.drop('target', axis=1)
  14. target_valid = df_val['target']
  15.  
  16. model = keras.models.Sequential()
  17. model.add(keras.layers.Dense(units=1, input_dim=features_train.shape[1],
  18.                              activation='sigmoid'))
  19. model.compile(loss='binary_crossentropy', optimizer='sgd', metrics=['accuracy'])
  20. model.fit(features_train, target_train, epochs=5, verbose=0,
  21.           validation_data=(features_valid, target_valid))
  22.  
  23.  
  24. predictions = model.predict(features_valid) > 0.5
  25. score = model.evaluate(features_valid, predictions)
  26. print("Accuracy:", score)
RAW Paste Data