Datalens.ai
← All algorithms

CLASSIFICATION

RidgeClassifier

Classifier using Ridge regression.

Example of usage

Linear regularised churn classification.

Usage / limitations

+Use when: Assign labels to observations.

−Limitations: Check input requirements, mathematical assumptions and version-specific behaviour before using.

Mathematical formula

See method documentation: implementation and assumptions vary.
Sample dataShow
{
  "variable": "customers",
  "domain": "Customer retention and churn risk",
  "feature_names": [
    "monthly_spend_gbp",
    "support_tickets",
    "months_active"
  ],
  "target_name": "churned",
  "records": [
    {
      "customer_id": "CUST-001",
      "monthly_spend_gbp": 24,
      "support_tickets": 4,
      "months_active": 2,
      "churned": 1
    },
    {
      "customer_id": "CUST-002",
      "monthly_spend_gbp": 29,
      "support_tickets": 5,
      "months_active": 3,
      "churned": 1
    },
    {
      "customer_id": "CUST-003",
      "monthly_spend_gbp": 34,
      "support_tickets": 6,
      "months_active": 4,
      "churned": 1
    },
    {
      "customer_id": "CUST-004",
      "monthly_spend_gbp": 39,
      "support_tickets": 7,
      "months_active": 5,
      "churned": 1
    },
    {
      "customer_id": "CUST-005",
      "monthly_spend_gbp": 44,
      "support_tickets": 4,
      "months_active": 6,
      "churned": 1
    },
    {
      "customer_id": "CUST-006",
      "monthly_spend_gbp": 49,
      "support_tickets": 5,
      "months_active": 7,
      "churned": 1
    },
    {
      "customer_id": "CUST-007",
      "monthly_spend_gbp": 26,
      "support_tickets": 6,
      "months_active": 8,
      "churned": 1
    },
    {
      "customer_id": "CUST-008",
      "monthly_spend_gbp": 31,
      "support_tickets": 7,
      "months_active": 2,
      "churned": 1
    },
    {
      "customer_id": "CUST-009",
      "monthly_spend_gbp": 36,
      "support_tickets": 4,
      "months_active": 3,
      "churned": 1
    },
    {
      "customer_id": "CUST-010",
      "monthly_spend_gbp": 41,
      "support_tickets": 5,
      "months_active": 4,
      "churned": 1
    },
    {
      "customer_id": "CUST-011",
      "monthly_spend_gbp": 46,
      "support_tickets": 6,
      "months_active": 5,
      "churned": 1
    },
    {
      "customer_id": "CUST-012",
      "monthly_spend_gbp": 51,
      "support_tickets": 7,
      "months_active": 6,
      "churned": 1
    },
    {
      "customer_id": "CUST-013",
      "monthly_spend_gbp": 110,
      "support_tickets": 0,
      "months_active": 21,
      "churned": 0
    },
    {
      "customer_id": "CUST-014",
      "monthly_spend_gbp": 115,
      "support_tickets": 1,
      "months_active": 22,
      "churned": 0
    },
    {
      "customer_id": "CUST-015",
      "monthly_spend_gbp": 120,
      "support_tickets": 2,
      "months_active": 16,
      "churned": 0
    },
    {
      "customer_id": "CUST-016",
      "monthly_spend_gbp": 125,
      "support_tickets": 3,
      "months_active": 17,
      "churned": 0
    },
    {
      "customer_id": "CUST-017",
      "monthly_spend_gbp": 130,
      "support_tickets": 0,
      "months_active": 18,
      "churned": 0
    },
    {
      "customer_id": "CUST-018",
      "monthly_spend_gbp": 135,
      "support_tickets": 1,
      "months_active": 19,
      "churned": 0
    },
    {
      "customer_id": "CUST-019",
      "monthly_spend_gbp": 112,
      "support_tickets": 2,
      "months_active": 20,
      "churned": 0
    },
    {
      "customer_id": "CUST-020",
      "monthly_spend_gbp": 117,
      "support_tickets": 3,
      "months_active": 21,
      "churned": 0
    },
    {
      "customer_id": "CUST-021",
      "monthly_spend_gbp": 122,
      "support_tickets": 0,
      "months_active": 22,
      "churned": 0
    },
    {
      "customer_id": "CUST-022",
      "monthly_spend_gbp": 127,
      "support_tickets": 1,
      "months_active": 16,
      "churned": 0
    },
    {
      "customer_id": "CUST-023",
      "monthly_spend_gbp": 132,
      "support_tickets": 2,
      "months_active": 17,
      "churned": 0
    },
    {
      "customer_id": "CUST-024",
      "monthly_spend_gbp": 137,
      "support_tickets": 3,
      "months_active": 18,
      "churned": 0
    }
  ]
}

Code example (Python)

# DataLens.ai example
# Domain: Customer retention and churn risk.
# Input: customers is supplied by Sample Data when you copy this example.

# Load numerical tools and the classifier.
import numpy as np
from sklearn.linear_model import RidgeClassifier

# Select human-readable customer features in a reproducible order.
feature_names = customers["feature_names"]
X = np.array([[row[feature] for feature in feature_names] for row in customers["records"]], dtype=float)
y = np.array([row["churned"] for row in customers["records"]], dtype=int)

# Apply the representation appropriate for this classifier.
features = X
# Train the named algorithm on this illustrative dataset.
model = RidgeClassifier()
model.fit(features, y)
# Evaluate reproducible training predictions, not a claim about real-world accuracy.
predicted = model.predict(features)
correct = int(np.count_nonzero(predicted == y))
print("correct_training_predictions:", correct)

# Expected output: assert this reproducible illustration's actual result.
assert correct == 24, ("unexpected predictions", correct)
print("Expected output verified")