Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. def df_to_dataset(dataframe, labels, shuffle=True, batch_size=32):
  2. ds = tf.data.Dataset.from_tensor_slices((dict(dataframe), labels))
  3. if shuffle:
  4. ds = ds.shuffle(buffer_size=len(dataframe))
  5. ds = ds.batch(batch_size)
  6. return ds
  7. feature_columns = []
  8. # numeric cols
  9. for header in list(X_train):
  10. feature_columns.append(feature_column.numeric_column(header))
  11. feature_layer = tf.keras.layers.DenseFeatures(feature_columns)
  12. batch_size = 32
  13. train_ds = df_to_dataset(X_train, y_train, batch_size=batch_size)
  14. val_ds = df_to_dataset(X_val, y_val, shuffle=False, batch_size=batch_size)
  15. test_ds = df_to_dataset(X_test,y_test, shuffle=False,
  16. batch_size=batch_size)
  17. model = tf.keras.Sequential([
  18. feature_layer,
  19. layers.Dense(128, activation='relu'),
  20. layers.Dense(128, activation='relu'),
  21. layers.Dense(1, activation='sigmoid')
  22. ])
  23.  
  24. model.compile(optimizer='adam',
  25. loss='binary_crossentropy',
  26. metrics=['accuracy'],)
  27. #run_eagerly=True)
  28.  
  29. model.fit(train_ds,
  30. validation_data=val_ds,
  31. epochs=5)
  32. loss, accuracy = model.evaluate(test_ds)
  33. print("Accuracy", accuracy)
  34.  
  35. W0625 16:28:50.013361 140172694484864 deprecation.py:323] From
  36. /usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/nn_impl.py:180:
  37. add_dispatch_support.<locals>.wrapper (from tensorflow.python.ops.array_ops)
  38. is deprecated and will be removed in a future version.
  39. Instructions for updating:
  40. Use tf.where in 2.0, which has the same broadcast rule as np.where
  41. Epoch 1/5
  42. 2437/2437 [==============================] - 12s 5ms/step - loss:
  43. -368933040.3744 - acc: 0.0000e+00 - val_loss: -1374389959.0878 - val_acc:
  44. 0.0000e+00
  45. Epoch 2/5
  46. 2437/2437 [==============================] - 11s 4ms/step - loss:
  47. -4239125012.7993 - acc: 0.0000e+00 - val_loss: -8055676778.8942 - val_acc:
  48. 0.0000e+00
  49. Epoch 3/5
  50. 2437/2437 [==============================] - 11s 4ms/step - loss:
  51. -14449097654.0468 - acc: 0.0000e+00 - val_loss: -21844830544.8532 - val_acc:
  52. 0.0000e+00
  53. Epoch 4/5
  54. 2437/2437 [==============================] - 11s 4ms/step - loss:
  55. -32560744568.1740 - acc: 0.0000e+00 - val_loss: -44181551604.6596 - val_acc:
  56. 0.0000e+00
  57. Epoch 5/5
  58. 2437/2437 [==============================] - 11s 4ms/step - loss:
  59. -60235093753.8022 - acc: 0.0000e+00 - val_loss: -76823729189.8015 - val_acc:
  60. 0.0000e+00
  61. 1219/1219 [==============================] - 3s 2ms/step - loss:
  62. -78553874677.2896 - acc: 0.0000e+00
  63. Accuracy 0.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement