TensorFlow is a Flexible, Open Source Library for deep learning written originally by Google Brain Team. It makes building models easier, faster, and more reproducible.
- Building a TensorFlow Churn Model
- Training and Predicting
- Saving Your Model and Reloading
Import Data
import pandas as pd
from sklearn.model_selection import train_test_split
df = pd.read_csv('Churn.csv')
X = pd.get_dummies(df.drop(['Churn', 'Customer ID'], axis=1))
y = df['Churn'].apply(lambda x: 1 if x=='Yes' else 0)X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.2)
get_dummies() is used for data manipulation. It converts categorical data into dummy or indicator variables.
get_dummies() allows you to easily one-hot encode your categorical data.
Importing The Dependencies
from tensorflow.keras.models import Sequential, load_model
from tensorflow.keras.layers import Dense
from sklearn.metrics import accuracy_score
Building the Model And Compiling It.
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'))#Compilation
model.fit(X_train, y_train, epochs=200, batch_size=32)
The Sequential model is a linear stack of layers.

Machine learning models that input or output data sequences are known as sequence models. Text streams, audio clips, video clips, time-series data, and other types of sequential data are examples of sequential data.
Applications Of The Sequence Models:
- Speech Recognition.
- Sentiment Classification.
- Video Activity Recognition. ETC…..
Fix, Predict and Evaluate
( Run with More epochs for getting a better Accuracy Model)
#Fixingmodel.fit(X_train, y_train, epochs=200, batch_size=32)# Prediction y_hat = model.predict(X_test)
y_hat = [0 if val < 0.5 else 1 for val in y_hat
Saving The Model
model = load_model('tfmodel')