GRADIO APP FOR PREDICTING TELCO CUSTOMER CHURN

GRADIO APP FOR PREDICTING TELCO CUSTOMER CHURN

GRADIO APP FOR PREDICTING TELCO CUSTOMER CHURN

Customer churn is a significant issue for many companies, particularly in the telecommunications sector. Businesses need to be able to identify which customers are most likely to quit in order to keep them as clients and lower their churn rate. In this article, we’ll show you how to create a Gradio app that uses a machine learning model to forecast client turnover in the telecom sector.


No alt text provided for this image

1.Install Gradio first, then import the required libraries.

Installing Gradio and importing the required libraries should be done first. A Python package called Gradio makes it simple to create and implement user-friendly machine learning models.


Run the following command in your terminal, Google Colab, Visual Studio Code (I used Visual Studio Code), or Jupyter Notebook to install Gradio:


No alt text provided for this image
!pip install gradio        

Gradio must import the following libraries after installation:

Import gradio as gr
Import pandas as Pd
Import numpy as np
import pickle
from sklearn.preprocessing import LabelEncoder, StandardScaler        


2: Load the Model and Data

The machine learning model that will be used to forecast client turnover has to be loaded. Additionally, we must load the data that will be used to create our Gradio app.


Run the following code to load the model:

model = pickle.load(open("/content/drive/MyDrive/model (1).pkl", "rb"))        

Execute the following code to load the data:

data = pd.read_csv('/content/drive/MyDrive/df_churn.csv')        


No alt text provided for this image

3: Specify the Gradio App’s Input and Output Interfaces.

For our Gradio application, we must provide the input and output interfaces. Users can enter client data into the input interfaces, and the output interface displays the forecast outcome.


A function called “create_gradio_inputs” that accepts the data as input and produces a list of Gradio components will be developed to specify the input interfaces. Each column in our data will be looped through by the function, which will then generate a Gradio component based on the column’s data type.

The “create_gradio_inputs” function’s code is provided here.

We will make a Gradio Label component that shows the prediction result in order to specify the output interface:


output_components = [
    gr. Label(label="Churn Prediction"),
]
        


No alt text provided for this image

4: Define the Prediction Function

A function that receives user inputs, encodes categorical features, scales numerical features, and then uses a trained model to forecast the future must be defined.


The code to define the prediction function is available?here.

Using the encoder object that we imported before, we loop over each feature in this function after first creating a list of the categorized features. The numerical features are then compiled into a list, scaled using the scaler object, and added to the encoded data dataframe. Finally, we use the model object to make a forecast and then return the prediction as a string. We return “Not Likely to Churn” if the prediction is 0, and “Likely to Churn” if it is 1.


No alt text provided for this image

5: Launch the Gradio App

We can now run the Gradio app using the code below after defining the input and output interfaces as well as the prediction function:


# Launch the Gradio app
iface = gr.Interface(predict_churn, inputs=input_components, outputs=output_components,
                     description="Enter the customer's demographic and service usage information to predict whether they are likely to churn or not.")
iface.launch(inbrowser=True, show_error=True, share=True)        

This will open the Gradio app in your web browser in a new window or tab. The app will show the input elements (dropdowns, sliders, etc.) that we previously created, and the user can enter values for each feature to get an estimation of their likelihood of churning or not. Below the input components, a label representing the result will be shown.

Using the code provided above, you can create a Gradio app for telco customer churn prediction by following these instructions. Using this app’s demographic and service usage data, you can quickly and simply determine whether a customer is likely to leave your business.

Note: You can find more details about this project on my?GitHub?repository or visit my?medium?account if you’re interested in doing so.








要查看或添加评论,请登录

Jabo Justin的更多文章

社区洞察

其他会员也浏览了