我已将数据分割为 6 个分割的时间序列分割,我的设计的最佳得分是第 5 个分割。我想获得有关如何保存最佳分割图的帮助,换句话说,我可以保存分割 5 的结果。我正在尝试比较 SVR 预测和 RNN 预测的准确性。
下面是我的 SVR 设计的片段(也许这可以让任何人为我指明正确的方向)
timeseries_split = TimeSeriesSplit(n_splits=6)
for train_index, test_index in timeseries_split.split(X)
X_train, X_test = X[train_index], X[test_index]
y_train, y_test = y[train_index], y[test_index]
SVR=svm.SVR(kernel='rbf',C=1,gamma=80).fit(x_train,y_train)
rbf = SVR.predict(x_test)
plt.plot( rbf)
plt.show()
如果可能的话,请帮助将第五个分数保存在变量中,或者任何其他方法将不胜感激。
最佳答案
计算每次迭代中的分数
并保存最佳分数和最佳分割数据:
timeseries_split = TimeSeriesSplit(n_splits=6)
bestScore = -1.0
bestRbf = None
for train_index, test_index in timeseries_split.split(X)
X_train, X_test = X[train_index], X[test_index]
y_train, y_test = y[train_index], y[test_index]
SVR=svm.SVR(kernel='rbf',C=1,gamma=80).fit(x_train,y_train)
newScore = SVR.score(x_test)
if newScore > bestSoFar:
bestSoFar = newScore
bestRbf = SVR.predict(x_test)
plt.plot(bestRbf)
plt.show()
请注意,上面的解决方案比您请求的解决方案要好一些:这个会找到最佳的分割 - 因此它不需要像您的问题中那样对第五个解决方案进行硬编码。
关于python - 如何保存最佳验证分数结果,即保存 6 个分割中的第 5 个分割,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51851365/