I am trying to understand interpolation in pandas and I don't seem to understand if the method 'cubic' is a polynomial interpolation of order 3 or a spline. Does anybody know what pandas uses behind that method?
In interpolation methods, 'polynomial' generally means that you generate a polynomial with the same number of coefficients as you have data points. So, for 10 data points you would get an order 9 polynomial.
'cubic' generally means piecewise 3rd order polynomials. A sliding window of 4 data points is used to generate these cubic polynomials.
Related
I am trying to implement polynomial regression using the least squares method. There was a problem while plotting the 3rd graph, it is not displayed.
I think it's about the implementation of the formula y=ax+b.
But in my case, in first I got experimental data values using inline functions polyfit and polyval.
x=0:0.1:5;
y=3*x+2;
y1=y+randn(size(y));
k=1;#Polynom
X1=0:0.01:10
B=polyfit(x,y1,k);
Y1=polyval(B,X1);
And after all, I am already using a linear model to solve the polynomial regression using the method of least squares.
Y2=Y1'*x+B'; -----this problem formula
subplot(3,2,3);
plot(x,Y1,'-b',X1,y1,'LineWidth');
title('y1=ax+b');
xlabel('x');
ylabel('y');
grid on;
As a result, no graph is drawn.
check size of the vector: x and Y1 are not same length, same for X1 and y1.
You probably want to plot as:
plot(x,y1,'-b',X1,Y1,'LineWidth', 1);
I have a cumulative function (CDF) made of 6 points. I have to interpolate it so I used interp1d (from scipy.interpolate import interp1d), the results is the following:
the blue dots are the initial data and the red curve is after linear intepolation.
However, I am not really happy about it especially between the point 4 and 5 the assumption of linear relation is underestimating the real curve (if I think of this curve as a sigmoid or hyperbolic tangent). Therefore I tried to use always interp1d but with quadratic and cubic and the result is catastrofic
the output makes no sense and it completely wrong, so my question is
how to make my original linear fit a bit more smooth and similar to a real cumulative function?
Thanks, Luigi
Try monotone interpolants, akima/pchip
I want to make a model which can differentiate between general functions eg. If a given set of points fall on a line or a parabola etc.
I am not able to train a svc directly on arrays as it expects an array of 2d shape
Any suggestions?
Note: eventually i want to build it into classifying into periodic functions given a set of data points
Okay so your input is an array of points, each point has coordinates (x,y) and your label is the type of function.
In math, this task is called interpolation and this is where you get a set of points and you return the function that should be returned.
What you are describing seems more like non-linear regression (curve fitting) than it is about classification, you'll have too many classes to cover and it doesn't really make sense to do that anyway.
Here is a tutorial in python about non-linear regression that would be more useful. https://scipy-cookbook.readthedocs.io/items/robust_regression.html
I am calculating an dynamic resistance of a diode and I have a lot of measurements and I've created a graph from them. And the question is, how do I find from this graph an exact value of arguments, for example: I want to obtain f(x) value for x=5 where i have measurement for exact value fe. x=10 -> y=213, x=1 y->110, and got a graph curve, but how to find f(5) = ?
This is not trivial: it will depend on your interpolation scheme and Excel does not expose the scheme it uses when drawing a graph.
Unless you tell it otherwise, Excel (I think) uses a Bezier Curve with 2 control points to perform its graphing.
This interpolation scheme transforms, via some linear algebra, to a cubic spline interpolation.
But to use cubic spline interpolation, you need more than two data points.
Since you've only given us two points, the best thing you can do is to interpolate linearly but that will not be what Excel does.
An answer more detailed than this if anything will epitomise the rather broad nature of your question. Do Google any terms that I've used: armed with a bit of time and a good internet connection, you ought to be able to solve this problem adequately.
See https://en.wikipedia.org/wiki/Spline_interpolation, https://en.wikipedia.org/wiki/B%C3%A9zier_curve
I think that you can use a preinstalled add-on named Solver. You have to activate it as shown here.
Then you have to follow one of the tutorial you can find over the Internet (like this one) without finding min o max but finding the exact value you want.
I have a Cubic Bézier curve. But I have a problem when I need only one point. I have only value from the X-axis and want to find a value that coresponds to Y-axis to that point. Or find the t step, from it I can easely calculate the Y-axis.
Any clue how to do it? Or is there any formula to do this?
Any solution will have to deal with the fact that there may be multiple solutions if the curve is not X monotone. Consider the cubic bezier (0,0),(2,0),(-1,1),(1,1):
As you can see, there are 4 parameter values (and Y coordinates) at which X==1/2.
This means that if you use subdivision (which is probably your simplest solution), then you need to be careful that your initial bounding t values only surround the point you want.
You can also guess what this implies about the order of an algebraic solution.
A parametric curve extends to any dimension by adding coefficients for those dimensions. Are you sure you've got things straight? It seems like you are using the x-axis as the curve parameter t. The t parameter controls the computations of X- and Y-coordinates by having two cubic equations. Take a look at Wikipedia which provides some pretty neat explanations for the 2D case.
Edit:
Solve as a general third-degree polynomial. Beware that it might have 3 solutions, though.