In this article, we will learn Interpolation using the SciPy module in Python. First, we will discuss interpolation and its types with implementation.
Interpolation and Its Types
Interpolation is a technique of constructing data points between given data points. The scipy.interpolate is a module in Python SciPy consisting of classes, spline functions, and univariate and multivariate interpolation classes. Interpolation is done in many ways some of them are :
- 1-D Interpolation
- Spline Interpolation
- Univariate Spline Interpolation
- RBF Interpolation
Let’s discuss all the methods one by one and visualize the results.
To create a function based on fixed data points, scipy.interpolate.interp1d is used. It takes data points x and y and returns a function that can be called with new x and returns the corresponding y point.
Syntax: scipy.interpolate.interp1d(x , y , kind , axis , copy , bounds_error , fill_value , assume_sorted)
In spline interpolation, a spline representation of the curve is computed, and then the spline is computed at the desired points. The function splrep is used to find the spline representation of a curve in a two-dimensional plane.
- To find the B-spline representation of a 1-D curve, scipy.interpolate.splrep is used.
Syntax: scipy.interpolate.splrep(x, y, w, xb, xe, k, task, s, t, full_output, per, quiet)
- To compute a B-spline or its derivatives, scipy.interpolate.splev is used.
Syntax: scipy.interpolate.splev(x , tck , der , ext)
It is a 1-D smoothing spline that fits a given group of data points. The scipy.interpolate.UnivariateSpline is used to fit a spline y = spl(x) of degree k to the provided x, y data. s specifies the number of knots by specifying a smoothing condition. The scipy.interpolate.UnivariateSpline. set_smoothing_factor: Spline computation with the given smoothing factor s and with the knots found at the last call.
Syntax: scipy.interpolate.UnivariateSpline( x, y, w, bbox, k, s, ext)
Radial basis function for Interpolation
The scipy.interpolate.Rbf is used for interpolating scattered data in n-dimensions. The radial basis function is defined as corresponding to a fixed reference data point. The scipy.interpolate.Rbf is a class for radial basis function interpolation of functions from N-D scattered data to an M-D domain.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course