<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Keras Toy 2D binary classification
Install Keras
https
Step1:  Make the dataset
Step2:  Make the classifier
Step3:  Bonnus
<ASSISTANT_TASK:>
Python Code:
import tensorflow as tf
tf.__version__
import keras
keras.__version__
import h5py
h5py.__version__
import pydot
pydot.__version__
Explanation: Keras Toy 2D binary classification
Install Keras
https://keras.io/#installation
Install dependencies
Install TensorFlow backend: https://www.tensorflow.org/install/
pip install tensorflow
Insall h5py (required if you plan on saving Keras models to disk): http://docs.h5py.org/en/latest/build.html#wheels
pip install h5py
Install pydot (used by visualization utilities to plot model graphs): https://github.com/pydot/pydot#installation
pip install pydot
Install Keras
pip install keras
Import packages and check versions
End of explanation
df_train = gen_2d_samples(n_samples=200)
x_train = df_train[['x1', 'x2']].values
y_train = df_train.y.values
ax = df_train.loc[df_train.y == 0].plot.scatter(x='x1', y='x2', color="r")
df_train.loc[df_train.y == 1].plot.scatter(x='x1', y='x2', ax=ax);
df_test = gen_2d_samples(n_samples=200)
x_test = df_test[['x1', 'x2']].values
y_test = df_test.y.values
ax = df_test.loc[df_test.y == 0].plot.scatter(x='x1', y='x2', color="r")
df_test.loc[df_test.y == 1].plot.scatter(x='x1', y='x2', ax=ax);
Explanation: Make the dataset
End of explanation
model = keras.models.Sequential()
model.add(keras.layers.Dense(units=2, activation='relu', input_dim=2))
model.add(keras.layers.Dense(units=1, activation='sigmoid'))
model.compile(loss='binary_crossentropy',
              optimizer='rmsprop',
              metrics=['accuracy'])
model.summary()
print(model.get_config())
hist = model.fit(x_train, y_train, batch_size=100, epochs=10, verbose=False)
plt.plot(hist.history['loss']);
model.evaluate(x_test, y_test)
y_predicted = model.predict(x_test)
predicted_data = np.concatenate([x_test, y_predicted], axis=1)
predicted_df = pd.DataFrame(predicted_data, columns=['x1', 'x2', 'y'])
ax = predicted_df.loc[predicted_df.y <= 0.5].plot.scatter(x='x1', y='x2', color="r")
predicted_df.loc[predicted_df.y > 0.5].plot.scatter(x='x1', y='x2', ax=ax);
Explanation: Make the classifier
End of explanation
from keras.utils import plot_model
plot_model(model, show_shapes=True, to_file="model.png")
Explanation: Bonnus: plot the regressor
End of explanation
<END_TASK>