- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试将曲线拟合到一些生成的数据,这些数据在绘制时类似于指数函数。我正在使用 scipy.optimize.curve_fit
,因为它似乎是这项工作的最佳选择(也是最好的记录)。每次运行代码时,实际数据都是新生成的,但这里是一个示例集:
import pandas
import scipy.optimize as opt
x1 = [0.4145392937447818, 0.7807888116968482, 0.7903528929788539,
1.5081613036989836, -0.295895237606155, -0.0855307279546107,
1.0523973736479486, -0.6967509832843239, -0.30499200990688413,
1.1990545631966807, -1.270460772249312, 0.9531042718153095, 1.5747175535222993,
-0.6483709650867473, 0.47820180254528477, 1.14266851615097, 0.6237953640100202,
0.0664027559951128, 0.877280002485417, 0.9432317053343211, 1.0367424879878504,
-0.6410400513164749, 1.667835241401498, -0.20484029870424125,
2.887026948755316]
y1 = [0.718716626591187, 0.579938466590508, 0.722005637974309,
1.61842778379047, 0.331301712743162, 0.342649242449043, 1.14950611092907,
0.299221762023701, 0.345063839940754, 1.08398125906313, 0.315433168226251,
1.3343730617376, 1.32514210008176, 0.308702648499771, 0.495749985226691,
0.406025683910759, 0.445087968405107, 0.423578575247177, 0.816264419038205,
1.16110461165631, 1.81572974380867, 0.420890068255763, 0.821468286117842,
0.416275933630732, 4.7877353794036]
data = pandas.DataFrame({"Pi_values": x1,
"CO2_at_solubility": y1})
然后,我做曲线拟合业务...
##Define curve fitting
def func(x, m, c, c0):
return c0 + m**x * c
#draw the figure
fig, ax1 = plt.subplots()
plt.xlabel('Pi Parameter')
plt.ylabel('CO2 wt%')
#plot generated data
#tried converting pandas columns to np arrays based on an issue another user was having, but it does not help
x1 = data["Pi_values"].values
y1 = data["CO2_at_solubility"].values
# Curve fitting with scipy.optimize.curve_fit
popt, pcov = opt.curve_fit(func, x1, y1)
# Use the optimized parameters to plot the best fit
plt.plot(x1, y1, 'o', x1, func(x1, *popt))
这是非常奇怪的结果。无论我尝试什么形式的方程式,如果它能够拟合任何“曲线”,它看起来就像这样一团糟:
或者这个烂摊子...
知道这里会发生什么吗?我找不到任何其他类似的例子。我在 jupyter notebook 中运行 python3.5。
我尝试过但没有用的其他方法:等式的其他形式;其他方程;改变初始猜测值;在 y 值太小的情况下缩放值。
最佳答案
你只需要对 x
值进行排序
data.sort_values(by='Pi_values', ascending=True, inplace=True)
在 curve_fit
之前:
x1 = data["Pi_values"].values
y1 = data["CO2_at_solubility"].values
# Curve fitting with scipy.optimize.curve_fit
popt, pcov = opt.curve_fit(func, x1, y1)
# Use the optimized parameters to plot the best fit
plt.plot(x1, y1, 'o', x1, func(x1, *popt))
关于python - scipy.optimize.curve_fit 产生无意义的曲线拟合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52269680/
我在使用 cx_freeze 和 scipy 时无法编译 exe。特别是,我的脚本使用 from scipy.interpolate import griddata 构建过程似乎成功完成,但是当我尝试
是否可以通过函数在 scipy 中定义一个稀疏矩阵,而不是列出所有可能的值?在文档中,我看到可以通过以下方式创建稀疏矩阵 There are seven available sparse matrix
SciPy为非线性最小二乘问题提供了两种功能: optimize.leastsq()仅使用Levenberg-Marquardt算法。 optimize.least_squares()允许我们选择Le
SciPy 中的求解器能否处理复数值(即 x=x'+i*x")?我对使用 Nelder-Mead 类型的最小化函数特别感兴趣。我通常是 Matlab 用户,我知道 Matlab 没有复杂的求解器。如果
我有看起来像这样的数据集: position number_of_tag_at_this_position 3 4 8 6 13 25 23 12 我想对这个数据集应用三次样条插值来插值标签密度;为此
所以,我正在处理维基百科转储,以计算大约 5,700,000 个页面的页面排名。这些文件经过预处理,因此不是 XML 格式。 它们取自 http://haselgrove.id.au/wikipedi
Scipy 和 Numpy 返回归一化的特征向量。我正在尝试将这些向量用于物理应用程序,我需要它们不被标准化。 例如a = np.matrix('-3, 2; -1, 0') W,V = spl.ei
基于此处提供的解释 1 ,我正在尝试使用相同的想法来加速以下积分: import scipy.integrate as si from scipy.optimize import root, fsol
这很容易重新创建。 如果我的脚本 foo.py 是: import scipy 然后运行: python pyinstaller.py --onefile foo.py 当我启动 foo.exe 时,
我想在我的代码中使用 scipy.spatial.distance.cosine。如果我执行类似 import scipy.spatial 或 from scipy import spatial 的操
Numpy 有一个基本的 pxd,声明它的 c 接口(interface)到 cython。是否有用于 scipy 组件(尤其是 scipy.integrate.quadpack)的 pxd? 或者,
有人可以帮我处理 scipy.stats.chisquare 吗?我没有统计/数学背景,我正在使用来自 https://en.wikipedia.org/wiki/Chi-squared_test 的
我正在使用 scipy.odr 拟合数据与权重,但我不知道如何获得拟合优度或 R 平方的度量。有没有人对如何使用函数存储的输出获得此度量有建议? 最佳答案 res_var Output 的属性是所谓的
我刚刚下载了新的 python 3.8,我正在尝试使用以下方法安装 scipy 包: pip3.8 install scipy 但是构建失败并出现以下错误: **Failed to build sci
我有 my own triangulation algorithm它基于 Delaunay 条件和梯度创建三角剖分,使三角形与梯度对齐。 这是一个示例输出: 以上描述与问题无关,但对于上下文是必要的。
这是一个非常基本的问题,但我似乎找不到好的答案。 scipy 到底计算什么内容 scipy.stats.norm(50,10).pdf(45) 据我了解,平均值为 50、标准差为 10 的高斯中像 4
我正在使用 curve_fit 来拟合一阶动态系统的阶跃响应,以估计增益和时间常数。我使用两种方法。第一种方法是在时域中拟合从函数生成的曲线。 # define the first order dyn
让我们假设 x ~ Poisson(2.5);我想计算类似 E(x | x > 2) 的东西。 我认为这可以通过 .dist.expect 运算符来完成,即: D = stats.poisson(2.
我正在通过 OpenMDAO 使用 SLSQP 来解决优化问题。优化工作充分;最后的 SLSQP 输出如下: Optimization terminated successfully. (Exi
log( VA ) = gamma - (1/eta)log[alpha L ^(-eta) + 测试版 K ^(-eta)] 我试图用非线性最小二乘法估计上述函数。我为此使用了 3 个不同的包(Sc
我是一名优秀的程序员,十分优秀!