Skip to content

TensorFlow

Basics

from tensorflow.keras.models import Sequential, load_model
from tensorflow.keras.layers import Dense
from sklearn.metrics import accuracy_score
model = Sequential()
model.add(Dense(units=32, activation='relu', input_dim=len(X_train.columns)))
model.add(Dense(units=64, activation='relu'))
model.add(Dense(units=1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='sgd', metrics='accuracy')
model.fit(X_train, y_train, epochs=200, batch_size=32)
pred = model.predict(X_test)
pred = np.where(
  pred > 0.5,
  1,
  0
)
model.save('tfmodel')
del model
model = load_model('tfmodel')
Last Updated: 2024-01-24 ; Contributors: AhmedThahir, web-flow

Comments