curve-fitting

Python: Use polyval to predict X passing Y

ぃ、小莉子 提交于 2021-01-29 07:31:46
问题 I have 2 sets of points (X, Y). I want to: Use polifit to fit the line Given a Y predict an X This is the dataset: X Y -0.00001 5.400000e-08 -0.00001 5.700000e-08 0.67187 1.730000e-07 1.99997 9.150000e-07 2.67242 1.582000e-06 4.00001 3.734000e-06 4.67193 5.414000e-06 5.99998 9.935000e-06 6.67223 1.311300e-05 8.00000 2.102900e-05 Which looks like this: I have seen numpy has the function polyval. But here you pass an X and get a y. How do i reverse it. 回答1: As I said in the comments, you can

Python scipy.optimise.curve_fit gives linear fit

…衆ロ難τιáo~ 提交于 2021-01-29 04:20:21
问题 I have come across a problem when playing with the parameters of the curve_fit from scipy. I have initially copied the code suggested by the docs. I then changed the equation slightly and it was fine, but having increased the np.linspace, the whole prediction ended up being a straight line. Any ideas? import numpy as np from scipy.optimize import curve_fit import matplotlib.pyplot as plt def f(x, a, b, c): # This works fine on smaller numbers return (a - c) * np.exp(-x / b) + c xdata = np

SciPy curve_fit not working when one of the parameters to fit is a power

不打扰是莪最后的温柔 提交于 2021-01-29 03:31:03
问题 I'm trying to fit my data to a user defined function using SciPy curve_fit, which works when fitting to a function with a fixed power (func1). But curve_fit does not work when the function contains a power as a parameter to fit to (func2). Curve_fit still does not work if I provide an initial guess for the parameters usins the keyword p0 . I can not use the bounds keyword as the version of SciPy which I have does not have it. This script illustrates the point: import scipy from scipy.optimize

SciPy curve_fit not working when one of the parameters to fit is a power

牧云@^-^@ 提交于 2021-01-29 03:30:51
问题 I'm trying to fit my data to a user defined function using SciPy curve_fit, which works when fitting to a function with a fixed power (func1). But curve_fit does not work when the function contains a power as a parameter to fit to (func2). Curve_fit still does not work if I provide an initial guess for the parameters usins the keyword p0 . I can not use the bounds keyword as the version of SciPy which I have does not have it. This script illustrates the point: import scipy from scipy.optimize

Fitting “multimodal” lognormal distributions to data using python

谁都会走 提交于 2021-01-28 18:42:46
问题 I have the following data measured using an instrument in the lab. Since the instrument collects particles of different sizes in bins based upon their diameter the measurements are essentially "binned": import numpy as np import matplotlib.pylab as plt from lmfit import models y = np.array([196, 486, 968, 2262, 3321, 4203, 15072, 46789, 95201, 303494, 421484, 327507, 138931, 27973]) bins = np.array([0.0150, 0.0306, 0.0548, 0.0944, 0.1540, 0.2560, 0.3830, 0.6050, 0.9510, 1.6400, 2.4800, 3.6700

Fitting “multimodal” lognormal distributions to data using python

十年热恋 提交于 2021-01-28 18:41:35
问题 I have the following data measured using an instrument in the lab. Since the instrument collects particles of different sizes in bins based upon their diameter the measurements are essentially "binned": import numpy as np import matplotlib.pylab as plt from lmfit import models y = np.array([196, 486, 968, 2262, 3321, 4203, 15072, 46789, 95201, 303494, 421484, 327507, 138931, 27973]) bins = np.array([0.0150, 0.0306, 0.0548, 0.0944, 0.1540, 0.2560, 0.3830, 0.6050, 0.9510, 1.6400, 2.4800, 3.6700

Fitting a linear combination of distributions

余生颓废 提交于 2021-01-28 14:03:42
问题 I have 5 arrays (columns of a pandas data frame) and I want calculate the best fit for a linear combination of the distributions to an exponential distribution. for example: a*(d1)+b*(d2)+c*(d3)+d*(d4)+e*(d5)=Y where Y has an exponential distribution (which i know) and a,b,c,d,e are the coefficients to fit. I tried using curve_fit or lmfit python libraries but didn't get how to do it effectively. 回答1: What you're describing is a linear model. Use the package scikit-learn: from sklearn.linear

(sigmoid) curve fitting glm in r

廉价感情. 提交于 2021-01-28 08:32:59
问题 I wish to visualize the relationship between my response variable, detection probability (P.det) and predictor variable (distance) for two categories (transmitter), show error bars and draw a (sigmoidal) curve through the averaged data points. The dataset is like this: df <- structure(list(distance = c(50L, 100L, 200L, 300L, 400L, 50L, 100L, 200L, 300L, 400L), Transmitter = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L), .Label = c("CT", "PT"), class = "factor"), P.det = c(0.918209097, 0

Fit differential equation with scipy

不问归期 提交于 2021-01-27 18:37:29
问题 how can I fit the differential function of the followint scipy tutorial Scipy Differential Equation Tutorial? In the end I want to fit some datapoints that follow a set of two differential equations with six parameters in total but I'd like to start with an easy example. So far I tried the functions scipy.optimize.curve_fit and scipy.optimize.leastsq but I did not get anywhere. So this is how far I came: import numpy as np import scipy.optimize as scopt import scipy.integrate as scint import

Python curve fitting on pandas dataframe then add coef to new columns

戏子无情 提交于 2021-01-27 18:11:25
问题 I have a dataframe that needs to be curve fitted per row (second order polynomial). There are four columns, each column name denotes the x value. Each row contains 4 y values corresponding to the x values in the column name. For example: Based on the code below, The fitting for the first row will take x = [2, 5, 8, 12] and y = [5.91, 28.06, 67.07, 145.20] import numpy as np import panda as pd df = pd.DataFrame({'id': [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5,