【发布时间】:2019-08-01 19:17:00
【问题描述】:
出于可重复性的原因,我正在分享我正在使用的简单数据集here。
为了清楚我在做什么 - 从第 2 列开始,我正在读取当前行并将其与前一行的值进行比较。如果它更大,我会继续比较。如果当前值小于前一行的值,我想将当前值(较小)除以前一个值(较大)。因此,下面是我的源代码。
import numpy as np
import scipy.stats
import matplotlib.pyplot as plt
import seaborn as sns
from scipy.stats import beta
protocols = {}
types = {"data_v": "data_v.csv"}
for protname, fname in types.items():
col_time,col_window = np.loadtxt(fname,delimiter=',').T
trailing_window = col_window[:-1] # "past" values at a given index
leading_window = col_window[1:] # "current values at a given index
decreasing_inds = np.where(leading_window < trailing_window)[0]
quotient = leading_window[decreasing_inds]/trailing_window[decreasing_inds]
quotient_times = col_time[decreasing_inds]
protocols[protname] = {
"col_time": col_time,
"col_window": col_window,
"quotient_times": quotient_times,
"quotient": quotient,
}
plt.figure(); plt.clf()
plt.plot(quotient_times, quotient, ".", label=protname, color="blue")
plt.ylim(0, 1.0001)
plt.title(protname)
plt.xlabel("quotient_times")
plt.ylabel("quotient")
plt.legend()
plt.show()
sns.distplot(quotient, hist=False, label=protname)
这给出了以下图。
从图中我们可以看出
-
当
quotient_times小于 3 时,Data-V 的商为 0.8,如果quotient_times为 大于 3。
我还使用以下代码将其安装到 beta 发行版中
xt = plt.xticks()[0]
xmin, xmax = min(xt), max(xt)
lnspc = np.linspace(xmin, xmax, len(quotient))
alpha,beta,loc,scale = stats.beta.fit(quotient)
pdf_beta = stats.beta.pdf(lnspc, alpha, beta,loc, scale)
plt.plot(lnspc, pdf_beta, label="Data-V", color="darkblue", alpha=0.9)
plt.xlabel('$quotient$')
#plt.ylabel(r'$p(x|\alpha,\beta)$')
plt.title('Beta Distribution')
plt.legend(loc="best", frameon=False)
我们如何将quotient(如上定义)放入一个 sigmoid 函数中,以得到如下图?
【问题讨论】:
-
我向您推荐 lmfit 软件包。在那里你有一个简单的方法来实现你自己的拟合功能。 (希望我正确理解了您的问题)
-
lmfit用于 sigmoid 函数?我以前没有使用过它,但你可以尝试使用我共享的数据集吗,Richard?谢谢。 -
将数据集拟合到 sigmoid 与使用 sigmoid 分类器不同吗?您只需要提取参数。 Scikit learn 具有非常易于使用的 sigmoid 分类器。
-
我在 R 中做了一些非常相似的事情,如果我分享一下会有帮助吗?
-
@MedImage,谢谢,但我想要它在 Python 中。如果您可以分享您在 Python 中使用我分享的相同数据回答您的答案,那就太好了,我会将其标记为已接受的答案。
标签: python python-3.x numpy scikit-learn logistic-regression