Available data

Available to me is a set of points which can be represented as shown in image 1:

Original data

Also available to me is a non-continuous path derived from this data. It is not important how this non-continuous path is obtained. It is however important, that it roughly represents a curve I intent to approximate. This non-continuous path is shown in image 2:

Non-continuous path derived from original data


I want to approximate this data using a polynomial of either second or third degree. Examples of these approximations are shown in images 3, 4:

Fit curve to original data

Fit curve to non-continuous path

Problem / question

Now I am looking for a way to obtain the red curve. Some details confuse me, where my knowledge is likely to be simply lacking. For example, how to fit a polynomial, when technically what I require is not a function, at least not in this coordinate system, because there will be situations where an x value is being assigned two y values.

I thought of possibly using the ends of my path to define a new x-axis, but I consider this approach faulty. Another consideration are Splines.

How should I go about obtaining this red curve from the non-continuous path (preferred) or from original data? What sources should I look into?

Apologies if this is an already answered question which I suspect it might be. However I have been issuing search queries for this without success, hence my question.


1 Answer 1


You can try fitting a multi-dimensional polynomial regression. It seems that for your data, a two dimensional regression model should be fine: $$ (a)x^2 + (b)x + (c)y^2 + (d)y + (e)xy + (f) $$

In python for example, you can fit a proper model using:

import numpy as np
from sklearn.preprocessing import PolynomialFeatures

X = np.array([ [x0,y0], [x1,y1], ...  ])
poly = PolynomialFeatures(2)
poly = PolynomialFeatures(interaction_only=True)

  • $\begingroup$ Thank you, this offers me a nice starting point. $\endgroup$ Sep 19, 2019 at 7:46
  • $\begingroup$ I ended up implementing Curve Global Approximation to fit a spline to these points. $\endgroup$ Dec 1, 2019 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.