Datalens.ai
← All algorithms

REGRESSION

Ridge

Linear least squares with l2 regularization.

Example of usage

Python API reference included; executable data demonstration pending review.

Usage / limitations

+Use when: Predict continuous measurements.

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

Mathematical formula

See method documentation: implementation and assumptions vary.
Sample dataShow
{
  "variable": "housing_data",
  "domain": "Residential property pricing",
  "feature_names": [
    "floor_area_m2",
    "building_age_years"
  ],
  "records": [
    {
      "floor_area_m2": 60.0,
      "building_age_years": 25.0
    },
    {
      "floor_area_m2": 72.0,
      "building_age_years": 24.0
    },
    {
      "floor_area_m2": 84.0,
      "building_age_years": 23.0
    },
    {
      "floor_area_m2": 96.0,
      "building_age_years": 22.0
    },
    {
      "floor_area_m2": 108.0,
      "building_age_years": 21.0
    },
    {
      "floor_area_m2": 120.0,
      "building_age_years": 20.0
    },
    {
      "floor_area_m2": 132.0,
      "building_age_years": 19.0
    },
    {
      "floor_area_m2": 144.0,
      "building_age_years": 18.0
    },
    {
      "floor_area_m2": 156.0,
      "building_age_years": 17.0
    },
    {
      "floor_area_m2": 168.0,
      "building_age_years": 16.0
    },
    {
      "floor_area_m2": 180.0,
      "building_age_years": 15.0
    },
    {
      "floor_area_m2": 192.0,
      "building_age_years": 14.0
    },
    {
      "floor_area_m2": 204.0,
      "building_age_years": 13.0
    },
    {
      "floor_area_m2": 216.0,
      "building_age_years": 12.0
    },
    {
      "floor_area_m2": 228.0,
      "building_age_years": 11.0
    },
    {
      "floor_area_m2": 240.0,
      "building_age_years": 10.0
    },
    {
      "floor_area_m2": 252.0,
      "building_age_years": 9.0
    },
    {
      "floor_area_m2": 264.0,
      "building_age_years": 8.0
    },
    {
      "floor_area_m2": 276.0,
      "building_age_years": 7.0
    },
    {
      "floor_area_m2": 288.0,
      "building_age_years": 6.0
    },
    {
      "floor_area_m2": 300.0,
      "building_age_years": 5.0
    },
    {
      "floor_area_m2": 312.0,
      "building_age_years": 4.0
    },
    {
      "floor_area_m2": 324.0,
      "building_age_years": 3.0
    },
    {
      "floor_area_m2": 336.0,
      "building_age_years": 2.0
    }
  ],
  "sale_price_thousands_gbp": [
    220.5,
    252.8,
    285.1,
    311.4,
    343.7,
    376.0,
    402.3,
    434.6,
    466.9,
    493.2,
    525.5,
    557.8,
    584.1,
    616.4,
    648.7,
    675.0,
    707.3,
    739.6,
    765.9,
    798.2,
    830.5,
    856.8,
    889.1,
    921.4
  ],
  "retained_customer": [
    1,
    0,
    1,
    0,
    1,
    0,
    1,
    0,
    1,
    0,
    1,
    0,
    1,
    0,
    1,
    0,
    1,
    0,
    1,
    0,
    1,
    0,
    1,
    0
  ]
}

Code example (Python)

# DataLens.ai example — Ridge
# Domain: residential property pricing, with named predictor fields.
# Copy input + code + test includes the sample housing_data assignment.
import numpy as np
from sklearn import linear_model, tree, neighbors, gaussian_process, kernel_ridge, svm, neural_network, naive_bayes
# Read floor area and building age as the numeric feature matrix.
X = np.array([[row[field] for field in housing_data['feature_names']] for row in housing_data['records']], dtype=float)
# Read historic transaction prices, in thousands of pounds.
y = np.array(housing_data['sale_price_thousands_gbp'], dtype=float)
# Penalise large coefficients to regularise the price model.
model = linear_model.Ridge(alpha=1.0).fit(X,y)
assert model.predict(X).shape == y.shape and np.mean(abs(model.predict(X)-y)) < 3
# Confirm the model-specific assertion without relying on printed numbers.
print("Expected output verified")