1. Piecewise Polynomials
- Piecewise polynomials fit low-degree polynomials over different regions of .
1.1 Knots
- Knots are the cut points that divide the range of into distinct regions.
Example (Piecewise cubic polynomial with one knot at ).
- More knots bring more flexibility.
- A piecewise constant Step Functions are polynomials of degree .

2. Constraints and Splines
-
To avoid overfitting, we can constrain the piecewise polynomials to be continuous and smooth at the knots.
-
Each additional constraint reduces one degree of freedom.
-
If we constrain the piecewise polynomials, e.g. cubic, to be:
- continuous at the knots;
- continuous for the first derivative at the knots;
- continuous for the second derivative at the knots;
then we call it a cubic spline.
Example (Cubic spline). In this case, each region has 4 parameters, thus 8 parameters in total. We have 3 constraints: continuity, continuity of the first derivative, and continuity of the second derivative. Thus 3 degrees of freedom are reduced.
In general, if we have knots, the degree of freedom is .
2.1 Degree- Spline
We define a degree- spline as:
- A piecewise polynomial of degree .
- Constrained to be continuous up to the th derivative at the knots.
3. The Spline Basis Representation
Spline basis representation helps with fitting the model under the constraints.
A cubic spline with knots can be represented as:
where are the basis functions.
3.1 Choice of Basis Functions
-
The most common choice is the cubic spline with truncated power basis function per knot.
-
The truncated power basis function per knot is defined as:
where is the knot.
-
It can be easily proved that the truncated power basis function per knot remains continuous up to the second derivative at the knot.
-
Thus to fit a data set with knots, we perform LSE with predictors, including the intercept: .

3.2 Natural Splines
- Splines have high variance at the outer range of the predictors.
- Natural Spline is a regression spline with additional constraints: the function is linear at the boundary, i.e. in the region where is smaller than the smallest knot, or larger than the largest knot, the function is linear.
- Natural splines generally produce more stable estimates at the boundaries, with smaller variance.
4. Choosing the Number and Locations of the Knots
The regression spline is most flexible in regions.
4.1 Locating Knots
- One option is to place more knots where we feel the function might vary most rapidly, and to place fewer knots where it seems more stable.
- Another option is to place knots in a uniform fashion, i.e. specify the desired degrees of freedom of the spline, and then have software automatically place the corresponding number of knots at uniform quantiles of the data.
4.2 Choosing the Number of Knots
- One option is to try out different numbers of knots, and then choose the model with the smallest RSS or the largest .
- Another option is to use cross-validation:
- Remove a portion of the data, say 10%.
- Fit a spline with a certain number of knots to the remaining data.
- Use the spline to make predictions for held-out portion.
- Repeat the above steps until each observation has been left out once.
- Compute the overall cross-validation error, e.g. MSE.
Note: Polynomial regression comparison
The source note has a heading for comparison with polynomial regression, but does not include the comparison content. It is left as a planned expansion.