If you build for WooCommerce, the most useful sentence in a recent credit scoring walkthrough is the boring one near the end. After comparing candidate models, the author saves the winner in pickle format for future use. That is where store work starts, because a pickle file does nothing at checkout, and a WooCommerce risk score has to produce a number during the same request that creates the order.
The piece is Towards Data Science’s walkthrough of training a scoring model with AI assistance, where Junior Jumbong fits logistic regressions over combinations of six categorical variables on a Kaggle credit dataset of 32,581 loans, prunes candidates with statistical tests, and settles on a four-variable model picked by a penalized Gini. Read it for the selection discipline, which is the part most teams skip.
What the article gets right
The author argues that a scoring model is not the candidate with the highest training performance. He filters candidates on global and individual significance at the five percent level, checks that coefficient signs match business expectations, requires a VIF under 10, and only then compares Gini across the train, test, and out-of-time samples. I buy that whole stack, and I would apply nearly all of it to order risk scoring on a store, because the consumers of the score are a merchant’s support queue and a plugin settings screen, and both need to see why a number is high.
The part I would copy nearly verbatim is the penalized Gini: average fold performance minus the absolute gap between train and test, minus the gap between train and out-of-time. It is a cheap way to make a comparison table punish exactly the model that looks great in a notebook and falls apart a season later. And with the order volumes most stores have, you are usually in small data machine learning territory anyway, where overfitting is the default outcome.
Why the WooCommerce risk score should not call Python
My position on deployment: for a WordPress store, the model ships as coefficients inside PHP, with no Python in the request path. Three reasons. Managed WordPress hosts generally do not run Python, so you are signing up for an external scoring service. An external call adds a second thing that can fail during checkout, the worst possible place for a timeout. And the score is most useful stored on the order itself, where a support agent can see it two months later.
The other side has a real point here. If the model gets retrained weekly, or it is gradient boosting rather than logistic regression, hand-porting coefficients is busywork and a small internal scoring service is the honest answer. The middle path I prefer is scoring asynchronously after the order exists, through Action Scheduler, so checkout never waits on the model. And when the model is logistic, the port is trivial, because scikit-learn’s predict_proba is the expit of the linear predictor, 1 / (1 + exp(-(Xw + w0))). The values in coef_ and intercept_ are floats, and floats run in PHP.
Porting the model into PHP
Export the coefficients, rebuild each dummy variable in PHP exactly the way training built it, and write the mapping down, because the reference category choice has to match or every score is quietly wrong. Then store the score and its inputs on the order. The numbers below are toy placeholders standing in for real fitted values:
<?php
add_action( 'woocommerce_checkout_create_order', 'bbioon_score_order_risk', 10, 2 );
function bbioon_score_order_risk( WC_Order $order, array $data ) {
// Coefficients ported from the trained model (toy values here).
$coef = array(
'intercept' => -2.30,
'guest_checkout' => 0.55,
'prior_refunds' => 0.72,
'address_mismatch' => 0.40,
);
$refunds = 0;
if ( $order->get_customer_id() ) {
// Maintained by our refund tracking, not by this function.
$refunds = (int) get_user_meta( $order->get_customer_id(), '_bbioon_refund_count', true );
}
$shipping = $order->get_shipping_country();
$x = array(
'guest_checkout' => $order->get_customer_id() ? 0 : 1,
'prior_refunds' => min( $refunds, 2 ),
'address_mismatch' => ( $shipping && $shipping !== $order->get_billing_country() ) ? 1 : 0,
);
$logit = $coef['intercept'];
foreach ( $x as $key => $value ) {
$logit += $coef[ $key ] * $value;
}
$score = 1 / ( 1 + exp( - $logit ) );
$order->update_meta_data( '_bbioon_risk_score', round( $score, 4 ) );
$order->update_meta_data( '_bbioon_risk_inputs', wp_json_encode( $x ) );
}
Two details in there matter more than the math. Saving through update_meta_data instead of update_post_meta keeps the plugin working on stores that moved orders to the dedicated HPOS tables, which is the documented pattern for order meta. And persisting the raw inputs next to the score is what makes drift debugging possible later; a score of 0.81 with no inputs tells you nothing.
This gap between a finished notebook and a working store integration is regular work for me, so if you have a model sitting in Python and a WooCommerce build that needs it in PHP, send it over and I can scope the port.
Keep the stability checks after launch
The out-of-time sample in the source exists because a model can hold up on test data and still decay on a later period. A store gets the same problem with a shorter fuse: checkout methods change, a new market ships, a fraud pattern shifts. The cheap version of that check is to snapshot the score distribution in the month you calibrate, then compare the share of orders above your review threshold each month. If that share moves a lot while your traffic mix has not, an input has drifted and the score needs a look.
Label delay works the same way. Defaults take months to show up, and so do chargebacks, which means a loop retrained on last month’s outcomes is trained on stale labels. I wrote about the related problem of catching drift when labels arrive late, and the practical answer is mostly the same: watch the inputs and the score distribution, since that is what you can see now.
The label question I can’t close
There is one part I have not seen a clean answer to, on either side of the fence. In credit, the moment you decline an application you stop observing the outcome, and lenders compensate with reject inference. A store has it worse: you act on the score, you cancel or hold the flagged orders, and those outcomes never exist. Retrain on that data and the model slowly learns your own past decisions instead of the risk it was meant to rank. One honest option is to hold out a small random slice of flagged orders and let them run, which trades a little fraud loss for unbiased labels. So the open question is where the label comes from once you start intervening on the score.