# Linear Regression API
> Linear least-squares regression as an API, computed locally and deterministically. The linear endpoint fits the best straight line y = a + b·x through a set of x/y data points by ordinary least squares, returning the slope b = Σ((x−x̄)(y−ȳ))/Σ(x−x̄)², the intercept a = ȳ − b·x̄, the ready-to-use equation, the Pearson correlation r and the coefficient of determination R² (the fraction of variance the line explains), and the residual and slope standard errors — the points (1,2),(2,4),(3,5),(4,4),(5,5) fit to y = 2.2 + 0.6·x with R² = 0.6, and a perfectly linear set returns R² = 1. Pass a predict_x and it also extrapolates the fitted value at that point. The predict endpoint evaluates y = intercept + slope·x for a known line. The x and y lists may be given as comma-separated values (x=1,2,3&y=2,4,5) or as JSON arrays in a POST body and must be equal length. Everything is computed locally and deterministically, so it is instant and private. Ideal for data-science, analytics, BI, forecasting, machine-learning-preprocessing and statistics-education app developers, trend-line and best-fit tools, and dashboards. Pure local computation — no key, no third-party service, instant. Live, nothing stored. 2 endpoints. This is the regression line; for the Pearson correlation alone or descriptive statistics use a statistics API and for probability distributions a probability API.

## Authentication
All requests require your oanor API key in the `x-oanor-key` header. Get one at https://www.oanor.com/developer/keys.

```bash
curl -H "x-oanor-key: oanor_live_…" "https://api.oanor.com/regression-api/..."
```

## Pricing
- **Free** (Free) — 5,600 calls/Mo, 2 req/s
- **Starter** ($6/Mo) — 56,000 calls/Mo, 6 req/s
- **Pro** ($17/Mo) — 260,000 calls/Mo, 15 req/s
- **Mega** ($53/Mo) — 1,480,000 calls/Mo, 40 req/s

## Endpoints

### Regression

#### `GET /v1/linear` — Fit a regression line

**Parameters:**
- `x` (query, required, string) — x values (comma-separated or array) Example: `1,2,3,4,5`
- `y` (query, required, string) — y values Example: `2,4,5,4,5`
- `predict_x` (query, optional, string) — Optional x to predict Example: `6`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/regression-api/v1/linear?x=1%2C2%2C3%2C4%2C5&y=2%2C4%2C5%2C4%2C5&predict_x=6"
```

**Response:**
```json
{
    "data": {
        "r": 0.77459667,
        "note": "Ordinary least-squares fit y = a + b·x. b = Σ((x−x̄)(y−ȳ))/Σ(x−x̄)², a = ȳ − b·x̄, R² is the fraction of variance explained.",
        "slope": 0.6,
        "inputs": {
            "n": 5
        },
        "equation": "y = 2.2 + 0.6·x",
        "intercept": 2.2,
        "r_squared": 0.6,
        "prediction": {
            "x": 6,
            "y": 5.8
        },
        "slope_std_error": 0.28284271,
        "residual_std_error": 0.89442719
    },
    "meta": {
        "timestamp": "2026-06-05T19:50:22.616Z",
        "request_id": "8b93fb5f-c609-4e80-9684-6a614553fc76"
    },
    "status": "ok",
    "message": "Linear regression",
    "success": true
}
```

#### `GET /v1/predict` — Predict from a line

**Parameters:**
- `slope` (query, required, string) — Slope b Example: `0.6`
- `intercept` (query, required, string) — Intercept a Example: `2.2`
- `x` (query, required, string) — x value Example: `6`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/regression-api/v1/predict?slope=0.6&intercept=2.2&x=6"
```

**Response:**
```json
{
    "data": {
        "y": 5.8,
        "note": "y = intercept + slope·x.",
        "inputs": {
            "x": 6,
            "slope": 0.6,
            "intercept": 2.2
        }
    },
    "meta": {
        "timestamp": "2026-06-05T19:50:22.725Z",
        "request_id": "9c451dac-5225-4771-8f61-d358f3c85930"
    },
    "status": "ok",
    "message": "Predict from line",
    "success": true
}
```

### Meta

#### `GET /v1/meta` — Spec

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/regression-api/v1/meta"
```

**Response:**
```json
{
    "data": {
        "notes": "Pass x and y as comma-separated lists (x=1,2,3&y=2,4,5) or JSON arrays in a POST body; they must be equal length. This is the regression line; for the Pearson correlation alone or descriptive stats use a statistics API.",
        "service": "regression-api",
        "endpoints": {
            "GET /v1/meta": "This document.",
            "GET /v1/linear": "Fit a line through x/y data; returns slope, intercept, R² and (optionally) a prediction.",
            "GET /v1/predict": "Predict y from a slope, intercept and x."
        },
        "description": "Linear least-squares regression: fit y = a + b·x, goodness of fit (R², standard errors), and prediction."
    },
    "meta": {
        "timestamp": "2026-06-05T19:50:22.832Z",
        "request_id": "dbd468bb-5076-40d1-85e8-ed08b9d4ded0"
    },
    "status": "ok",
    "message": "Meta",
    "success": true
}
```


---
Marketplace page: https://www.oanor.com/api/regression-api
OpenAPI spec: https://www.oanor.com/api/regression-api/openapi.json
