curve-fitting

Equation of the parabola enclosing a scatter plot

只愿长相守 提交于 2019-12-20 02:33:07
问题 I have the x and y coordinates of the following graph as two different lists s and k. If I want to determine the equation of the parabola that best encloses these points, how do I do it? Thanks! I am not sure how to link to an external data set. What is the best way to add your dataset to a question? This was the best I could find. So, I am putting up a sample data set here. I will be removing this later, though. K S 0 9.500000e-01 -6.500000e-01 1 8.500000e-01 -6.000000e-01 2 9.000000e-01 -6

Plotting a histogram with overlaid PDF

不打扰是莪最后的温柔 提交于 2019-12-20 02:33:02
问题 This is a follow-up to my previous couple of questions. Here's the code I'm playing with: import pandas as pd import matplotlib.pyplot as plt import scipy.stats as stats import numpy as np dictOne = {'Name':['First', 'Second', 'Third', 'Fourth', 'Fifth', 'Sixth', 'Seventh', 'Eighth', 'Ninth'], "A":[1, 2, -3, 4, 5, np.nan, 7, np.nan, 9], "B":[4, 5, 6, 5, 3, np.nan, 2, 9, 5], "C":[7, np.nan, 10, 5, 8, 6, 8, 2, 4]} df2 = pd.DataFrame(dictOne) column = 'B' df2[df2[column] > -999].hist(column,

curve fitting with python

*爱你&永不变心* 提交于 2019-12-19 05:14:33
问题 I'm trying to fit some data and stuff, I know there is a simple command to do this with python/numpy/matplotlib, but I can't find it. I think it is something like popt,popc = numpy.curvefit(f,x) where popt is the paramters of f , popc is the fit quality and f is a predefined function of f. Does any of you know it? 回答1: Take a look at scipy.optimize.curve_fit: scipy.optimize.curve_fit(f, xdata, ydata, p0=None, sigma=None, **kw) Use non-linear least squares to fit a function, f, to data. 回答2:

Paraboloid (3D parabola) surface fitting python

天涯浪子 提交于 2019-12-19 03:43:51
问题 I am trying to fit this x data: [0.4,0.165,0.165,0.585,0.585], this y data: [.45, .22, .63, .22, .63], and this z data: [1, 0.99, 0.98,0.97,0.96] to a paraboloid. I am using scipy's curve_fit tool. Here is my code: doex = [0.4,0.165,0.165,0.585,0.585] doey = [.45, .22, .63, .22, .63] doez = np.array([1, .99, .98,.97,.96]) def paraBolEqn(data,a,b,c,d): if b < .16 or b > .58 or c < .22 or c >.63: return 1e6 else: return ((data[0,:]-b)**2/(a**2)+(data[1,:]-c)**2/(a**2)) data = np.vstack((doex

Interactive BSpline fitting in Python

柔情痞子 提交于 2019-12-19 03:15:50
问题 Using the following function, one can fit a cubic spline on input points P: def plotCurve(P): pts = np.vstack([P, P[0]]) x, y = pts.T i = np.arange(len(pts)) interp_i = np.linspace(0, i.max(), 100000 * i.max()) xi = interp1d(i, x, kind='cubic')(interp_i) yi = interp1d(i, y, kind='cubic')(interp_i) fig, ax = plt.subplots() fig,ax=plt.subplots() ax.plot(xi, yi) ax.plot(x, y, 'ko') #plt.show() return xi,yi The input points P can be of the following form: P=[(921,1181),(951,1230),(993,1243),(1035

Curve fitting in R using nls

百般思念 提交于 2019-12-19 02:09:53
问题 I'm trying to fit a curve over (the tail of) the following data: [1] 1 1 1 1 1 1 2 1 2 2 3 2 1 1 4 3 2 11 6 2 16 7 17 36 [25] 27 39 41 33 42 66 92 138 189 249 665 224 309 247 641 777 671 532 749 506 315 292 281 130 [49] 137 91 40 27 34 19 1 I'm using the following function in R to accomplish this: nls(y~a x exp(-b*x^2),start=list(a=1,b=1),trace=TRUE) However, I'm getting the following error: 3650202 : 1 1 Error in numericDeriv(form[[3L]], names(ind), env) : Missing value or an infinity

R smooth.spline(): smoothing spline is not smooth but overfitting my data

丶灬走出姿态 提交于 2019-12-18 16:54:29
问题 I have several data points which seem suitable for fitting a spline through them. When I do this, I get a rather bumpy fit, like overfitting, which is not what I understand as smoothing. Is there a special option / parameter for getting back the function of a really smooth spline like here. The usage of the penalty parameter for smooth.spline didn't have any visible effect. Maybe I did it wrong? Here are data and code: results <- structure( list( beta = c( 0.983790622281964, 0.645152464354322

scipy.optimize.curvefit: Asymmetric error in fit

。_饼干妹妹 提交于 2019-12-18 08:57:26
问题 I try to fit a function to my data using scipy.optimize.curvefit . Q=optimization.curve_fit(func,X,Y, x0,ERR) and it works well. However, now I am trying to use an asymmetric error and I have no idea how to do that - or even if it is possible. By asymmetric error I mean that the error is not for example: 3+-0.5 but 3 +0.6 -0.2 . So that ERR is an array with two columns. It would be great if somebody had an idea how to do that - or could me point to a different Python routine which might be

How to properly fit a beta distribution in python?

左心房为你撑大大i 提交于 2019-12-18 05:00:28
问题 I am trying to get a correct way of fitting a beta distribution. It's not a real world problem i am just testing the effects of a few different methods, and in doing this something is puzzling me. Here is the python code I am working on, in which I tested 3 different approaches: 1>: fit using moments (sample mean and variance). 2>: fit by minimizing the negative log-likelihood (by using scipy.optimize.fmin()). 3>: simply call scipy.stats.beta.fit() from scipy.optimize import fmin from scipy

Fit a curve to the boundary of a scatterplot

北城余情 提交于 2019-12-18 04:15:59
问题 I'm trying to fit a curve to the boundary of a scatterplot. See this image for reference. I have accomplished a fit already with the following (simplified) code. It slices the dataframe into little vertical strips, and then finds the minimum value in those strips of width width , ignoring nan s. (The function is monotonically decreasing.) def func(val): """ returns some function of 'val'""" return val * 2 for i in range(0, max_val, width)): _df = df[(df.val > i) & (df.val < i + width)] #