考虑以下示例:
如果我在这个点绘制
现在我正在使用
并且:
然后我们有:
现在,我想编程检测拟合的质量。 拟合既不应该太直 - 即保留特征,也不应该将噪音变化“过度检测”为特征。
我计划使用馈送到ANN的峰值计数器。
但是,此时我的问题是:
Scipy / numpy是否具有内置函数,可以将splrep的输出馈入其中,并在任何特定间隔处计算最小值或最大值及其密度?
注意: 我知道R ** 2值,我正在寻找另一种检测特征保存的方法。
import numpy as np
import math
import matplotlib.pyplot as plt
from scipy import interpolate
xs = np.linspace(1,10,500)
ys = [0.92 * x ** 2.3 + 0.0132 * x ** 4 + 0.0743 * (x - 9) ** 3 - 4 * (x -3) ** 2 + 80 * math.sin(math.sin(x)) + 10 * math.sin(x*5) + 1.2* np.random.normal(-4,4,1) for x in xs]
ys[200] = ys[200] + 130
ys[201] = ys[201] + 135
ys[202] = ys[202] + 129
ys[203] = ys[203] + 128
ys[204] = ys[204] + 131
ys[205] = ys[205] + 130
ys[206] = ys[206] + 129
ys[207] = ys[207] + 129
ys[208] = ys[208] + 128
ys[209] = ys[209] + 130
如果我在这个点绘制
xs
和ys
,它会产生一个漂亮的图表:![一个用于测试的嘈杂数据集](https://istack.dev59.com/0WugD.webp)
scipy.interpolate.splrep
将样本拟合成一条样条曲线。我已经使用了两种不同的样条来拟合数据的两个不同部分:tck = interpolate.splrep(xs[0:199], ys[0:199], s = 1000)
ynew2 = interpolate.splev(xs[0:199], tck, der = 0)
并且:
tck = interpolate.splrep(xs[210:500], ys[210:500], s = 9000)
ynew3 = interpolate.splev(xs[210:500], tck, der = 0)
然后我们有:
![相同数据的示例样条拟合](https://istack.dev59.com/hwqBx.webp)
我计划使用馈送到ANN的峰值计数器。
但是,此时我的问题是:
Scipy / numpy是否具有内置函数,可以将splrep的输出馈入其中,并在任何特定间隔处计算最小值或最大值及其密度?
注意: 我知道R ** 2值,我正在寻找另一种检测特征保存的方法。