<jupyter_start><jupyter_text>***A propensity model*** is a model that predicts the likelihood that someone will do something. To give a few examples:- The likelihood that website visitors will register an account.- The likelihood that a registered user will pay and subscribe.- The likelihood that a user will refer another user.Propensity modeling allows us to allocate your resources more wisely, resulting in greater efficiencies while achieving better results. For instance, think of this: instead of sending an email advertisement where there’s a 0%-100% chance of a user clicking it, with propensity modeling, you can target users with a 50%+ chance of clicking it. Fewer emails, more conversions! To build up on the idea, here's a dataset from a commercial website on the parts of a website users interacted with, depicted in classes of 0 or 1, potential questions are:- Which of these interactions with the website effect a users likelihood to purchase a product?- Can we score visitors from yesterday who did not purchase, to see who are the most valuable prospects?<jupyter_code>import pandas as pd
import numpy as np
import os
import matplotlib.pylab as plt
from sklearn.model_selection  import train_test_split
import sklearn.metrics
train_full = pd.read_csv('/content/drive/MyDrive/Colab Notebooks/training_sample.csv')

train_full.head(8)
print(train_full.shape)
print(train_full.dtypes)
print(train_full.describe())

print(train_full.info())
train_full['UserID'].nunique()
import seaborn as sns
corr = train_full.corr()
plt.figure(figsize=(16, 14))
sns.heatmap(corr, vmax=0.5, center=0,
            square=True, linewidths=2, cmap='Blues')
plt.savefig("heatmap.png")
plt.show()
train_full.corr()['ordered']
# Droping columns with low correlation and UserID
predictors = train_full.drop(['UserID','device_mobile'], axis=1)

# seperating the X and y column
predictors = predictors.drop(['ordered'], axis=1)

# predictors = train[['checked_delivery_pdp', 'basket_icon_click', 'sign_in', 'saw_checkout']]
targets = train_full.ordered
predictors
print(predictors.columns)
predictors.shape
X_train, X_val, y_train, y_val  =   train_test_split(predictors, targets, test_size=.2)

print( "Predictor - Training : ", X_train.shape, "Predictor - Validation : ", X_val.shape )
from sklearn.naive_bayes import GaussianNB

classifier=GaussianNB()
classifier=classifier.fit(X_train,y_train)

predictions=classifier.predict(X_val)

#Analyze accuracy of predictions
sklearn.metrics.confusion_matrix(y_val,predictions)
sklearn.metrics.accuracy_score(y_val, predictions)
testing_full = pd.read_csv('/content/drive/MyDrive/Colab Notebooks/testing_sample.csv')
testing_full
testing_full.shape
print(testing_full.info())
testing_full.columns
userids = testing_full.UserID

testing_full = testing_full.drop(['ordered','UserID','device_mobile'], axis=1)

print(testing_full.head(10))
testing_full.shape
final_predictions = classifier.predict_proba(testing_full)[:,1]
final_predictions
testing_full['propensity_probability'] = final_predictions

print(testing_full.head())
pd.DataFrame(userids)
result_set = pd.concat([userids, testing_full], axis=1)
display(result_set)
result_set.to_csv('results.csv')
test_copy = pd.read_csv("/content/drive/MyDrive/Colab Notebooks/testing_sample.csv")
test_prediction_classes = test_copy.ordered
test_copy = test_copy.drop(['ordered','UserID','device_mobile'], axis=1)
predictions_classes = classifier.predict(test_copy)
sklearn.metrics.accuracy_score(test_prediction_classes, predictions_classes)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09848058525604952, 'fraction_numerical': 0.007315700619020821, 'mean_word_length': 6.917594654788418, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '660434', 'license': 'MIT', 'n_tokens_mistral': 1106, 'n_tokens_neox': 1053, 'n_words': 310, 'path': 'Customer_Propensity_Modelling_v1.ipynb', 'repo_name': 'TishaJhabak1014/customer-propensity-modelling', 'size': '3554'}