data-fitting

Fitting distribution with fixed parameters in SciPy

限于喜欢 提交于 2019-12-02 02:45:26
Is it possible to fix parameters while fitting distributions in SciPy? For example, this code: import scipy.stats as st xx = st.expon.rvs(size=100) print st.expon.fit(xx, loc=0) results in non-zero location ( loc ). When some parameter is provided to the fit function it is considered as an initial guess. And if it is provided to the constructor ( st.expon(loc=0) ) the distribution becomes "frozen" and can not be used for fitting. Warren Weckesser To fix loc , use the argument floc : print st.expon.fit(xx, floc=0) E.g. In [33]: import scipy.stats as st In [34]: xx = st.expon.rvs(size=100) In

How to do data fitting to find the distribution of given data

[亡魂溺海] 提交于 2019-12-01 12:56:38
问题 I need to do data fitting to find the distribution of a given data. I need to find the pdf function of the distribution. I can use data fitting functions in matlab and python. It looks like a truncated gamma. But, how to find the parameters of the distribution ? What if the data cannot fit the truncated gamma well ? The QQ-plot (qunatile-quantile) show that it is not a good fit for truncated gamma. How to find the distribution parameters such as alpha (shape), beta (scale) for the truncated

Fitting with constraints on derivative Python

蓝咒 提交于 2019-12-01 09:57:18
问题 While trying to create an optimization algorithm, I had to put constraints on the curve fitting of my set. Here is my problem, I have an array : Z = [10.3, 10, 10.2, ...] L = [0, 20, 40, ...] I need to find a function that fits Z with condition on slope which is the derivative of the function I'm looking for. Suppose f is my function, f should fit Z and have a condition on f its derivative, it shouldnt exceed a special value. Are there any libraries in python that can help me achieve this

How to find the best straight line separating two regions having points with 2 different properties

久未见 提交于 2019-12-01 06:51:49
问题 I have a bunch of points in a 2D plot. The red points indicate when my experiment is stable, the black when it is unstable. The two region are clearly separated by a line in this log-log plot, and I would like to find the best "separating line", i.e. the line that gives the criterion to separate the 2 regions and has the minimum error on this criterion. I did a search on various books and online but I could not find any approach to solve this problem. Are you aware of any tool? First of all

Why does scipy.optimize.curve_fit not fit correctly to the data?

倖福魔咒の 提交于 2019-12-01 05:32:35
问题 I've been trying to fit a function to some data for a while using scipy.optimize.curve_fit but I have real difficulty. I really can't see any reason why this wouldn't work. # encoding: utf-8 from __future__ import (print_function, division, unicode_literals, absolute_import, with_statement) import numpy as np from scipy.optimize import curve_fit import matplotlib.pyplot as mpl x, y, e_y = np.loadtxt('data.txt', unpack=True) def f(x, a, k): return (1/(np.sqrt(1 + a*((k-x)**2)))) popt, pcov =

Fit a 3D line to 3D point data in Java?

China☆狼群 提交于 2019-12-01 03:49:49
I've spent a decent amount of time trying to hunt down a simple way of doing this - ideally, a magical library exists out there somewhere that will take my set of 3D data points and return 2 points on the best fit line using either orthogonal regression or least squares and also return the error of the fitted line. Does such a thing exist, and if so, where? This is easy enough to do, but to write it yourself you will need an eigenvalue solver or a singular value decomposition. Create the nx3 matrix A, of your (x-xbar, y-ybar, z-zbar) data as columns. Save those column means for later, I'll

SciPy LeastSq Goodness of Fit Estimator

房东的猫 提交于 2019-11-30 08:50:42
I have a data surface that I'm fitting using SciPy's leastsq function. I would like to have some estimate of the quality of the fit after leastsq returns. I'd expected that this would be included as a return from the function, but, if so, it doesn't seem to be clearly documented. Is there such a return or, barring that, some function I can pass my data and the returned parameter values and fit function to that will give me an estimate of fit quality (R^2 or some such)? Thanks! unutbu If you call leastsq like this: import scipy.optimize p,cov,infodict,mesg,ier = optimize.leastsq( residuals,a

Fitting with constraints on derivative Python

佐手、 提交于 2019-11-29 12:51:17
While trying to create an optimization algorithm, I had to put constraints on the curve fitting of my set. Here is my problem, I have an array : Z = [10.3, 10, 10.2, ...] L = [0, 20, 40, ...] I need to find a function that fits Z with condition on slope which is the derivative of the function I'm looking for. Suppose f is my function, f should fit Z and have a condition on f its derivative, it shouldnt exceed a special value. Are there any libraries in python that can help me achieve this task ? The COBYLA minimzer can handle such problems. In the following example a polynomial of degree 3 is

Why does scipy.optimize.curve_fit not fit to the data?

二次信任 提交于 2019-11-28 18:21:05
I've been trying to fit an exponential to some data for a while using scipy.optimize.curve_fit but i'm having real difficulty. I really can't see any reason why this wouldn't work but it just produces a strait line, no idea why! Any help would be much appreciated from __future__ import division import numpy from scipy.optimize import curve_fit import matplotlib.pyplot as pyplot def func(x,a,b,c): return a*numpy.exp(-b*x)-c yData = numpy.load('yData.npy') xData = numpy.load('xData.npy') trialX = numpy.linspace(xData[0],xData[-1],1000) # Fit a polynomial fitted = numpy.polyfit(xData, yData, 10)[

How to find probability distribution and parameters for real data? (Python 3)

别等时光非礼了梦想. 提交于 2019-11-28 16:53:42
I have a dataset from sklearn and I plotted the distribution of the load_diabetes.target data (i.e. the values of the regression that the load_diabetes.data are used to predict). I used this because it has the fewest number of variables/attributes of the regression sklearn.datasets . Using Python 3, How can I get the distribution-type and parameters of the distribution this most closely resembles? All I know the target values are all positive and skewed (positve skew/right skew). . . Is there a way in Python to provide a few distributions and then get the best fit for the target data/vector?