绘制/计算指数曲线的问题(python、matplotlib、pandas)

Posted

技术标签:

【中文标题】绘制/计算指数曲线的问题(python、matplotlib、pandas)【英文标题】:Problem with plotting/calculating exponential curve (python, matplotlib, pandas) 【发布时间】:2022-01-20 08:36:25 【问题描述】:

我有一些形成指数曲线的数据,我正在尝试将该曲线拟合到数据中。

不幸的是,我尝试的所有方法都不起作用(我不会让你对代码感到疯狂)。

问题是,当我将a*x**2 +b*x + ca*x**3 + b*x**2 +c*x + d 与我在互联网上找到的内容一起使用时(使用from scipy.optimize import curve_fit 的实现),它可以工作。再说一次,我会省去我对 exp 函数的迭代。

这是数据:

x,y
0.48995590396864286,8.109516054921031e-09
0.48995590396864286,8.09818090049968e-09
0.48995590396864286,8.103734197035667e-09
0.48995590396864286,8.110736963480639e-09
0.48995590396864286,8.09118823654877e-09
0.48995590396864286,8.12135991705394e-09
0.48995590396864286,8.122079043957364e-09
0.48995590396864286,8.128376050930522e-09
0.48995590396864286,8.157919899241163e-09
0.48661800486618,8.198100087712926e-09
0.48426150121065376,8.22138382076506e-09
0.48192771084337344,8.281557310731435e-09
0.4793863854266539,8.27420119872003e-09
0.47709923664122134,8.321514715516415e-09
0.47483380816714155,8.3552316463302e-09
0.47483380816714155,8.378564235036926e-09
0.47192071731949026,8.401917724613532e-09
0.4703668861712136,8.425994519752875e-09
0.4681647940074906,8.45965504646707e-09
0.4659832246039143,8.496218480906607e-09
0.46382189239332094,8.551849768778838e-09
0.46168051708217916,8.54285497435508e-09
0.46168051708217916,8.583748312156053e-09
0.46168051708217916,8.646661429014719e-09
0.4568296025582458,8.733501981255873e-09
0.45475216007276037,8.765708849715661e-09
0.45004500450045004,8.8589473576661e-09
0.44385264092321347,8.991513675928626e-09
0.4397537379067722,9.130861147033911e-09
0.43308791684711995,9.301055589581911e-09
0.4269854824935952,9.533957982742729e-09
0.42052144659377627,9.741467401775447e-09
0.41476565740356697,9.942960683024683e-09
0.4088307440719542,1.0205883938061429e-08
0.40176777822418647,1.0447121052453653e-08
0.3947887879984209,1.0747232046538825e-08
0.3895597974289053,1.1089181777589068e-08
0.3829950210647261,1.1466586145307001e-08
0.37664783427495296,1.1898726912256124e-08
0.3707823507601038,1.2248924384552248e-08
0.362844702467344,1.2806614625543388e-08
0.35676061362825545,1.3206507000963428e-08
0.35385704175513094,1.3625333143433576e-08
0.3460207612456747,1.4205592733074004e-08
0.34002040122407345,1.4793868231688043e-08
0.3348961821835231,1.545475512236522e-08
0.3287310979618672,1.6141630273450685e-08
0.32185387833923396,1.698004473312357e-08
0.3162555344718533,1.7677811603552503e-08
0.3111387678904792,1.858017339865837e-08
0.3037667071688943,1.9505998651376402e-08
0.29886431560071725,2.022694254385094e-08
0.2910360884749709,2.1353523243307723e-08
0.28457598178713717,2.2277591448622187e-08
0.2770083102493075,2.302804705798657e-08
0.2727024815925825,2.299784512552745e-08

【问题讨论】:

【参考方案1】:

如果您认为这是指数曲线,我会发现数据对数的线性拟合。

# your data in a Dataframe
import pandas as pd
import numpy as np
df = pd.read_csv("data.csv", sep=",")

# get log of your data
log_y = np.log(df["y"])

# linear fit of your log (as exp(ln(ax + b)) = ax + b)
a, b = np.polyfit(df.x, log_y, 1)

# plot the fit
import matplotlib.pyplot as plt

plt.scatter(df.x, df.y, label="raw_data")
plt.plot(df.x, np.exp(a*df.x + b), label="fit")
plt.legend()

【讨论】:

它回答你的问题了吗?

以上是关于绘制/计算指数曲线的问题(python、matplotlib、pandas)的主要内容,如果未能解决你的问题,请参考以下文章

Python绘制概率曲线二

Python计算PR曲线绘制:二分类PR曲线绘制多分类PR曲线绘制平均PR值计算

python编写自定义函数计算约登值(约登指数Youden Index)寻找最佳阈值(thresholdcutoff)可视化ROC曲线并在曲线中标记最佳阈值及其数值标签

Python计算分类评估KS值最佳阈值及绘制KS曲线

python编写自定义函数计算约登值(约登指数Youden Index)寻找最佳阈值(thresholdcutoff)以及最佳阈值对应的ROC曲线中的坐标点

如何在 Python 中绘制 ROC 曲线