fork download
  1. import tensorflow as tf
  2. import numpy as np
  3. x_data=np.array([[0,0],[0,1],[1,0],[1,1]],dtype=np.float32)
  4. y_data=np.array([[0],[1],[1],[0]],dtype=np.float32)
  5. model=tf.keras.Sequential([tf.keras.layers.Dense(8,input_dim=2,activation='relu'),tf.keras.layers.Dense(8,activation='relu'),tf.keras.layers.Dense(1,activation='sigmoid')])
  6. model.compile(optimizer='adam',loss='binary_crossentropy',metrics=['accuracy'])
  7. model.fit(x_data,y_data,epochs=1000,verbose=0)
  8. predictions=model.predict(x_data)
  9. rounded_predictions=np.round(predictions)
  10. print("Predictions:",rounded_predictions)
Success #stdin #stdout #stderr 4.91s 229284KB
stdin
Standard input is empty
stdout
('Predictions:', array([[0.],
       [1.],
       [1.],
       [0.]], dtype=float32))
stderr
WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/resource_variable_ops.py:435: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.cast instead.