Building a model using TensorFlow.
To build a model using TensorFlow, you first need to install the TensorFlow library. Then, you can follow these steps to construct the model:
- Import the necessary libraries and modules:
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
- Create a Sequential model.
model = Sequential()
- Add layers to the model.
model.add(Dense(units=64, activation='relu', input_shape=(10,)))
model.add(Dense(units=64, activation='relu'))
model.add(Dense(units=1, activation='sigmoid'))
- Compile model:
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
- training model
model.fit(X_train, y_train, epochs=10, batch_size=32)
X_train represents the features of the training data, while y_train represents the labels of the training data.
- Evaluate the model.
loss, accuracy = model.evaluate(X_test, y_test)
print('Test accuracy:', accuracy)
By following these steps, you can build and train a deep learning model using TensorFlow.