GBDT LR Predictor (Python)

MD
S
Markdown

For a sample input, this passes it through the different models - GBDT+LR, Neural Network, Ensemble, and prints out the prediction from each model.

import numpy as np from sklearn.ensemble import GradientBoostingClassifier from sklearn.linear_model import LogisticRegression import tensorflow as tf

Sample input

input_data = {'user_id': 1, 'click': 0}

GBDT + Logistic Regression

gbdt = GradientBoostingClassifier() gbdt.fit(X, y)

lr = LogisticRegression() lr.fit(X, y)

gbdt_pred = gbdt.predict_proba([input_data])[0][1] lr_pred = lr.predict_proba([input_data])[0][1]

print("GBDT + LR Prediction:", (gbdt_pred + lr_pred)/2)

Neural network with feature interaction modules

Defining model architecture...

nn_model = # nn_model

nn_pred = nn_model.predict([input_data])[0][0]

print("Neural Network Prediction:", nn_pred)

Ensemble model

model_1 = # dcnn model model_2 = # transformer model

def ensemble_model(input): out1 = model_1(input) out2 = model_2(input)

return 0.6out1 + 0.4out2

ens_pred = ensemble_model([input_data]) print("Ensemble Prediction:", ens_pred)

Created on 2/24/2024