In this article, we will learn Interpolation using the SciPy module in Python. First, we will discuss interpolation and its types with implementation. Show Interpolation and Its TypesInterpolation 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 :
Let’s discuss all the methods one by one and visualize the results. 1-D InterpolationTo 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.
Python
Output:
Spline InterpolationIn 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.
Python
Output: Univariate SplineIt 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.
Python
Output: Radial basis function for InterpolationThe 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. |