Now that we have trained model, we are ready to deploy. In this section we will load new unseen data of customers into mongo db. Later we will use these data in the trained model to make predictions about the probability that those customers will leave the bank.
First, open a terminal and start the mongo db daemon:
mongod
Now open another terminal and go to the folder where the new json file is stored:
cd /home/fabio/Documents/data_science_project_1/data/
There is a json file called customers_deployment_data.json. Let’s have a look at the first 100 characters:
head -c 1000 customers_deployment_data.json
This will give something like this:
[{"CustomerId": "15625083", "Name": "Abramov", "CreditScore": 660, "Geography": "Germany", "Gender": "Female", "Age": 38, "Tenure": 5, "Balance": 146337.88, "NumOfProducts": 1, "HasCrCard": 1, "IsActiveMember": 1, "EstimatedIncome": 7674.34, "person": "natural"}, {"CustomerId": "E15683183", "Name": "E7090X", "CreditScore": 684, "Geography": "Spain", "Gender": "0", "Age": 75, "Tenure": 3, "Balance": 999.0, "NumOfProducts": 1, "HasCrCard": 0, "IsActiveMember": 1, "EstimatedIncome": 1165675.74, "person": "entity"}, {"CustomerId": "15712974", "Name": "Hogarth", "CreditScore": 761, "Geography": "France", "Gender": "Female", "Age": 33, "Tenure": 4, "Balance": 137480.88, "NumOfProducts": 1, "HasCrCard": 1, "IsActiveMember": 1, "EstimatedIncome": 53765.71, "person": "natural"}, {"CustomerId": "E15607817", "Name": "E8908X", "CreditScore": 812, "Geography": "Spain", "Gender": "0", "Age": 35, "Tenure": 1, "Balance": 87219.88, "NumOfProducts": 2, "HasCrCard": 1, "IsActiveMember": 1,
As we can see, it is an array where each pair of curly brackets contains a document that we will be loaded into mongo db.
We will load these data into a new collection of the mongo db database. So we first need to create a new collection. Open the mongo shell
mongo
Now create a new collection called deploy_data
#show the existing databases
show dbs
#switch to customers
use customers
#create the new collection
db.createCollection("deploy_data")
#show the existing collections
show collections
customers_data
deploy_data
legal_entity
natural_person
Now we are ready to load the data into the new collection. First exit the mongo shell:
exit
Now upload the json file by indicating that the json file is an array:
mongoimport --db customers --collection deploy_data --drop --file customers_deployment_data.json --jsonArray
A message should appear, like this:
1020 document(s) imported successfully. 0 document(s) failed to import.
Now we can prepare the data and make predictions with the tuned model.