Logistic regression

Case 1. Logistic regression for customer churn


Implementation with RubixML

In real projects, people rarely implement logistic regression from scratch. It is much more convenient to use existing libraries. The very same churn case implemented with RubixML becomes noticeably shorter and closer to how it is often done in production:

 
<?php

use Rubix\ML\Datasets\Unlabeled;

include 
__DIR__ '/rubix-code.php';

// Describe a new user with the same feature structure as the training samples.
$newUser = [57120];

// Build an Unlabeled dataset from a single user example.
$dataset = new Unlabeled([$newUser]);

// Ask the classifier for class probabilities instead of hard labels.
$probabilities $classifier->proba($dataset);

// Take the first (and only) prediction row.
$probaRow $probabilities[0];

// Probability of churn (for class 'churn').
$churnProbability $probaRow['churn'];

echo 
'Churn probability (RubixML): ' number_format($churnProbability3) . PHP_EOL;

Result: Memory: 1.189 Mb Time running: 0.02 sec.
Churn probability (RubixML): 1.000