Polynomial Regression with Confidence and Prediction Intervals
This project demonstrates cubic polynomial regression including residual analysis, confidence intervals, and prediction intervals. It shows how to fit a polynomial model to synthetic data and evaluate its quality.
The goal of this project is to generate synthetic data, fit a cubic polynomial regression model, and assess its performance. The project also visualizes confidence and prediction intervals to better understand model uncertainty.
Key steps performed:
-
Data Generation
- Created a synthetic dataset with
Xuniformly distributed between 0 and 10. - Generated
Yusing a cubic polynomial relationship plus normal noise: [ Y = 1 + X - 0.3 X^2 + 0.05 X^3 + \epsilon ]
- Created a synthetic dataset with
-
Polynomial Regression (Degree 3)
- Estimated polynomial coefficients using Ordinary Least Squares (OLS).
- Plotted original data points and the regression curve.
-
Residual Analysis
- Calculated residuals (differences between observed and predicted values).
- Plotted:
- Residuals vs predicted values
- Histogram of residuals
-
Confidence and Prediction Intervals
- Computed 95% confidence intervals for the mean response.
- Computed 95% prediction intervals for new observations.
- Visualized both intervals along with the regression curve.
- Python 3
- NumPy (data generation and calculations)
- Matplotlib (plots and visualization)
- SciPy (t-distribution for interval estimation)