Best fit from a set of curves to data points
Question: I have a set of curves `F={f1, f2, f3,..., fN}`, each of them defined through
a set of points, ie: I don't have the _explicit_ form of the functions. So I
have a set of `N` tables like so:

    
    
    #f1: x  y
    1.2  0.5
    0.6  5.6
    0.3  1.2
    ...
    
    #f2: x  y
    0.3  0.1
    1.2  4.1
    0.8  2.2
    ...
    
    #fN: x  y
    0.7  0.3
    0.3  1.1
    0.1  0.4
    ...
    

I also have a set of observed/measured data points `O=[p1, p2, p3,..., pM]`
where each point has `x, y` coordinates and a given weight between `[0, 1]` ,
so it looks like:

    
    
    #O: x  y  w
    0.2  1.6  0.5
    0.3  0.7  0.3
    0.1  0.9  0.8
    ...
    

Since `N ~ 10000` (I have a big number of functions) what I'm looking for is
an efficient (more precisely: **fast**) way to find the curve that best fits
my set of observed and _weighted_ points `O`.

I know how to find a best fit with `python` when I have the explicit form of
the functions
([scipy.optimize.curve_fit](http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html)),
but how do I do that when I have the functions defined as tables?


Answer: You need two elements in order to have a fit, the data(which you already have)
and a model space(Linear Models, Gaussian Process, Support Vector Regression).
In your case your model has the additional constrain that some data points
should be weighted differently than others. May be something like this works
from you:

    
    
    from scipy.interpolate import UnivariateSpline
    
    temp = np.asarray([10, 9.6, 9.3, 9.0, 8.7])
    height = np.asarray([129, 145, 167, 190, 213])
    f = UnivariateSpline(height, temp)
    

Now you can evaluate `f` wherever you want:

    
    
    test_points = np.arange(120, 213, 5)  
    plot(height, temp, 'o', regular_heights, f(test_points), 'x')
    

![enter image description here](http://i.stack.imgur.com/Zqc7Q.png)

