# Smooth a noisy numeric series with a cubic spline

Fit a cubic smoothing spline to noisy numeric data. Choose automatic GCV/CV smoothing, p, lambda, or target degrees of freedom and return JSON, CSV, or SVG.

## Run it

- **CLI:** `gizza tool spline-smoother "x,y
1,2.1
2,3.9
3,6.2
4,7.8
5,10.3
6,11.7"`
- **Web:** https://gizza.ai/tools/spline-smoother/
- **Agents:** machine-readable descriptor (parameters JSON Schema) at https://gizza.ai/tools/spline-smoother/tool.json

## Inputs

- `input` — Data _(field)_
- `mode` — Smoothing mode _(field)_
- `smoothing` — Smoothing p _(field)_
- `lambda` — Lambda _(field)_
- `df` — Target effective df _(field)_
- `criterion` — Auto criterion _(field)_
- `weights` — Weights (optional) _(field)_
- `predict_at` — Predict at x values (optional) _(field)_
- `resample` — Resampled curve points _(field)_
- `coefficients` — Include cubic coefficients _(field)_
- `output` — Output format _(field)_

## Output

- Spline fit (text)

## Query parameters

Open the tool pre-filled and auto-run via URL:

- `input` — Data
- `mode` — Smoothing mode
- `smoothing` — Smoothing p
- `lambda` — Lambda
- `df` — Target effective df
- `criterion` — Auto criterion
- `weights` — Weights (optional)
- `predict_at` — Predict at x values (optional)
- `resample` — Resampled curve points
- `coefficients` — Include cubic coefficients
- `output` — Output format

Example: `https://gizza.ai/tools/spline-smoother/?input=x%2Cy%0A1%2C2.1%0A2%2C3.9%0A3%2C6.2%0A4%2C7.8%0A5%2C10.3%0A6%2C11.7&mode=auto&smoothing=0.99&lambda=1&df=5&criterion=gcv&weights=1%2C%201%2C%202%2C%201%2C%201%2C%201&predict_at=1.5%2C%203.5%2C%205.5&resample=0&coefficients=true&output=json`

---

## About this tool

Spline Smoother fits a natural cubic smoothing spline to noisy numeric data. Paste one y value per row, x,y rows with an optional header, a one-line list of y values, or JSON arrays/objects. The tool sorts by x, merges exact duplicate x values by weighted mean, and reports fitted values, residuals, leverage, effective degrees of freedom, selected lambda, RMSE, and optional predictions.

Use `mode=auto` when you want the tool to pick a penalty by generalized cross-validation or leave-one-out CV. Use `mode=smoothing` for a scale-free p slider: `0` is the weighted least-squares straight line and `1` interpolates the distinct data points. Advanced workflows can provide a raw non-negative `lambda` or a target effective `df`.

### Worked example

Input:

```text
x,y
1,2.1
2,3.9
3,6.2
4,7.8
5,10.3
6,11.7
```

With `mode=auto`, `criterion=gcv`, and `output=json`, the result includes a JSON report with the chosen smoothing penalty, fitted values for every observation, residuals, and RMSE. Switch `output=svg` for a quick raw-versus-fit chart, or set `predict_at=1.5,3.5,5.5` to evaluate the fitted curve at custom x values.

### Limits and edge cases

- Requires at least 4 distinct numeric x values.
- Accepts up to 10,000 input points, 5,000 prediction x values, and 5,000 resampled curve points.
- Input text is capped at 2 MB.
- Date/time x axes are not parsed directly; convert dates to day indexes or epoch seconds before fitting.
- Exact duplicate x values are merged before fitting using a weighted mean.
- `smoothing=1` interpolates the distinct points; `smoothing=0` returns the straight-line least-squares limit.

## FAQ

<details>
<summary>What input formats can I paste?</summary>

You can paste one y value per row, two-column x,y rows separated by commas, spaces, tabs, or semicolons, a one-line list such as `10, 12, 11, 15`, a JSON array of numbers, a JSON array of `[x, y]` pairs, or JSON objects with `x` and `y` fields. A non-numeric first row is treated as a header.

</details>

<details>
<summary>How should I choose between auto, smoothing, lambda, and df?</summary>

Start with `auto` and `criterion=gcv` for an objective default. Use `smoothing` when you want a slider-style control where lower values are smoother and `1` interpolates. Use `lambda` if you need to reproduce a known penalized-spline setting, or `df` when you want the fitted curve to have a particular effective degrees of freedom.

</details>

<details>
<summary>What does the coefficients option return?</summary>

When `coefficients=true`, JSON and CSV output include one row per interval with `x_start`, `x_end`, and cubic coefficients `a`, `b`, `c`, `d`. On that interval the fitted curve is `a + b·(x-x_start) + c·(x-x_start)^2 + d·(x-x_start)^3`.

</details>

<details>
<summary>Does the tool handle irregular spacing and duplicate x values?</summary>

Yes. X values can be irregular and unsorted. The tool sorts them before fitting. Exact duplicate x values are merged into one distinct knot using the weighted mean of their y values, and the report states how many duplicates were merged.

</details>

## Related tools

- [Regression model trainer](https://gizza.ai/tools/regression-model-trainer/): Fit linear, ridge, or bounded random-forest regression from a pasted numeric table and report R², RMSE, MAE, coefficients, or feature importance.
- [Time series generator](https://gizza.ai/tools/time-series-generator/): Generate deterministic synthetic time-series CSV, TSV, JSON or NDJSON with configurable trend, seasonality, noise, missing values and outliers.
- [Moving Average Calculator](https://gizza.ai/tools/moving-average/): Calculate simple, exponential and weighted moving averages (SMA, EMA, WMA) over any number series with your chosen window. Free, private, in-browser.
- [ARFF Converter](https://gizza.ai/tools/arff-converter/): Convert Weka ARFF datasets to CSV and CSV tables back to ARFF locally — nominal attributes, numeric types, dates, sparse rows, missing values, and type rows.
- [Beancount to CSV Converter](https://gizza.ai/tools/beancount-to-csv/): Flatten Beancount or Ledger journal postings into spreadsheet-ready CSV, then rebuild a simple journal from that flat CSV schema.
