+1 vote
in Python by
On  this customer_churn dataset:

1 Answer

0 votes
by
Build a keras sequential model to find out how many customers will churn out on the basis of tenure of customer?

Sol:

from keras.models import Sequential

from keras.layers import Dense

model = Sequential()

model.add(Dense(12, input_dim=1, activation=’relu’))

model.add(Dense(8, activation=’relu’))

model.add(Dense(1, activation=’sigmoid’))

model.compile(loss=’binary_crossentropy’, optimizer=’adam’, metrics=[‘accuracy’])

model.fit(x_train, y_train, epochs=150,validation_data=(x_test,y_test))

y_pred = model.predict_classes(x_test)

from sklearn.metrics import confusion_matrix

confusion_matrix(y_test,y_pred)

Code explanation:

We will start off by importing the required libraries:

from keras.models import Sequential

from keras.layers import Dense

Then, we go ahead and build the structure of the sequential model:

model = Sequential()

model.add(Dense(12, input_dim=1, activation=’relu’))

model.add(Dense(8, activation=’relu’))

model.add(Dense(1, activation=’sigmoid’))

Finally, we will go ahead and predict the values:

model.compile(loss=’binary_crossentropy’, optimizer=’adam’, metrics=[‘accuracy’])

model.fit(x_train, y_train, epochs=150,validation_data=(x_test,y_test))

y_pred = model.predict_classes(x_test)

from sklearn.metrics import confusion_matrix

confusion_matrix(y_test,y_pred)

Related questions

+2 votes
asked Jan 1, 2022 in Python by sharadyadav1986
0 votes
asked Jan 2, 2021 in Python by SakshiSharma
...