python - 如何保存最佳验证分数结果,即保存 6 个分割中的第 5 个分割

标签 python machine-learning train-test-split

我已将数据分割为 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/

相关文章:

python - 参数里面的冒号是什么意思?

python - Python如何调用C?

python - 如何记录 Python 交互式 shell session 中发生的一切?

machine-learning - 如果数据集具有多个特征,您如何知道它是否适合线性回归?

python - 在 Python 中将时间序列数据拆分为训练测试集和有效集

python - 用Python从字典中制作矩阵

opencv - 用于训练机器学习算法的矩阵未处理的异常

machine-learning - Keras:为什么观察到的批量大小与指定的批量大小不匹配?

python-3.x - 在 train_test_split sklearn python 上设置种子

python - 名称错误 : name 'skimage' is not defined