REGRESSION
Lars
Least Angle Regression model a.k.a. LAR.
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)
housing_data = {'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]}
# DataLens.ai example — Lars
# Domain: residential property prices with named physical attributes.
# The Copy input + code + test action includes the housing_data assignment.
import numpy as np
from sklearn import linear_model, neighbors, svm, neural_network
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
# Extract named property features and corresponding transaction prices.
X = np.array([[row[field] for field in housing_data['feature_names']] for row in housing_data['records']], dtype=float)
y = np.array(housing_data['sale_price_thousands_gbp'], dtype=float)
# Standardise features for methods sensitive to feature scale.
Xs = StandardScaler().fit_transform(X)
# Produce a two-target dataset to demonstrate joint regression tasks.
Y = np.column_stack([y, 0.4*y + 0.7*X[:,0]])
# Split transactions into two relative price classes when a classifier is used.
labels = (y > np.median(y)).astype(int)
# Build the least-angle regression coefficient path.
model=linear_model.Lars(n_nonzero_coefs=2).fit(Xs,y)
assert model.coef_.shape==(2,) and np.all(np.isfinite(model.coef_))
# An assertion failure would stop execution before this confirmation.
print("Expected output verified")
# DataLens.ai example — Lars
# Domain: residential property prices with named physical attributes.
# The Copy input + code + test action includes the housing_data assignment.
import numpy as np
from sklearn import linear_model, neighbors, svm, neural_network
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
# Extract named property features and corresponding transaction prices.
X = np.array([[row[field] for field in housing_data['feature_names']] for row in housing_data['records']], dtype=float)
y = np.array(housing_data['sale_price_thousands_gbp'], dtype=float)
# Standardise features for methods sensitive to feature scale.
Xs = StandardScaler().fit_transform(X)
# Produce a two-target dataset to demonstrate joint regression tasks.
Y = np.column_stack([y, 0.4*y + 0.7*X[:,0]])
# Split transactions into two relative price classes when a classifier is used.
labels = (y > np.median(y)).astype(int)
# Build the least-angle regression coefficient path.
model=linear_model.Lars(n_nonzero_coefs=2).fit(Xs,y)
assert model.coef_.shape==(2,) and np.all(np.isfinite(model.coef_))
# An assertion failure would stop execution before this confirmation.
print("Expected output verified")