Curve fitting in Python using a data sets
Question: I am really new in Python, hence I am asking a simple question:

I have a sets of data (x1, x2, x3, x4, x5) and corresponding (y1, y2, y3, y4,
y5). Now, how can I use Python to find a y value for a given x value? (x lies
in between x1 to x5)

As an example: Let say, I want to find a value of Y for X = 0.9 for the
following sets of data.

    
    
    X        Y
    0.5     12
    1.2     17 
    1.3     23
    1.6     29
    2.1     33
    

Thanks in advance!!


Answer: You can use a `polyfit`.

    
    
    from numpy import polyfit
    
    
    print polyfit([0.5, 1.2, 1.3, 1.6, 2.1],
                  [12, 17, 23, 29, 33],
                  1)  # Replace this number for the degree of the polinomium
    
    Output degree 1 -> [ 14.02332362   4.00874636]
    Output degree 2 -> [  1.17847672  10.98436544   5.64150351]
    

What you obtain are the coeficients for the curves:

  * Grade 1: _y = 14.02332362x + 4.00874636_
  * Grade 2: _y = 1.17847672x 2 \+ 10.98436544x + 5.64150351_

