Predictions for Python Developers
After training a new model by leveraging the power of NextBrain, you can make brand-new predictions with Python in a few easy steps. In this tutorial, you will learn how to use NextBrain to make predictions on the Uplift modeling model on the Marketing and Sales workspace. First, upload the nextbrain module:
It would be best if you made sure that the set you will provide to nextbrain has the same number of columns as the training data. Moreover, it must have the same column names in the same order. We will now create a new dataframe from scratch and convert it into a csv format by using pandas:
This is how our predict_df dataframe looks like:
As nextbrain requires the data in the csv format, we are going to convert this dataframe into a csv file:
Our data is now ready! However, you are going to need the model_id and access token to successfully feed this model into nextbrain module. The model_id for the Uplift modelling dataset is '31d1e9f0', and you can get your access token on the Predict for developers section. Additionally, you need to import Any and List from typing so that NextBrain module can digest your data in the desired format. Let's make predictions now!
And finally, we got the following prediction results:
pip install nextbrain
It would be best if you made sure that the set you will provide to nextbrain has the same number of columns as the training data. Moreover, it must have the same column names in the same order. We will now create a new dataframe from scratch and convert it into a csv format by using pandas:
import pandas as pd
predict_table = [[10, 30, 1, 0, 'Suburban', 0, 'Phone', 'Buy One Get One'],
[3, 600, 0, 1, 'Urban', 0, 'Web', 'No offer'],
[12, 120, 1, 1, 'Rural', 1, 'Multichannel', 'Discount']
]
predict_df = pd.DataFrame(predict_table,
columns=['recency', 'history', 'used_discount', 'used_bogo',
'zip_code', 'is_referral', 'channel', 'offer'])
This is how our predict_df dataframe looks like:
As nextbrain requires the data in the csv format, we are going to convert this dataframe into a csv file:
predict_df.to_csv('uplift_predicted_table.csv')
Our data is now ready! However, you are going to need the model_id and access token to successfully feed this model into nextbrain module. The model_id for the Uplift modelling dataset is '31d1e9f0', and you can get your access token on the Predict for developers section. Additionally, you need to import Any and List from typing so that NextBrain module can digest your data in the desired format. Let's make predictions now!
from nextbrain import NextBrain
from typing import Any, List
model_id = '31d1e9f0'
nb = NextBrain(<YOUR_SPECIAL_ACCESS_TOKEN>)
predict_table: List[List[Any]] = nb.load_csv('uplift_predicted_table.csv')
response = nb.predict_model(model_id, predict_table)
print(response)
And finally, we got the following prediction results:
{'predictions': [[0.0, 90.48], [0.0, 84.53], [0.0, 89.78]], 'target': 'conversion', 'problem_type': 'binary', 'ok': True}
Updated on: 25/02/2023
Thank you!