问题标签 [train-test-split]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
395 浏览

dataset - 在主题独立的 10 倍交叉验证中训练、验证和测试中的数据拆分?

我正在做情绪分析。该领域的最新论文执行独立于主题的 k 折交叉验证。但我还没有看到任何使用验证集的论文。他们只提到训练集和测试集。例如,在 10 次交叉验证中,整个数据集分为 10 个主题独立集(sub1 将只出现在一个集中而不出现在另一个集中)。如果我们只在训练和测试中划分数据集,那么超参数将如何调整。由于我的 val 准确度在变化(1%-4%),而训练准确度达到 99.99%,最终准确度是多少。

0 投票
1 回答
110 浏览

python - 为什么在加载大数据并且 RAM 内存不足时使用数据库(redis、SQL)会有所帮助?

我需要从一个目录中获取 100 000 张图像,将它们全部放在一个大字典中,其中键是图片的 id,值是图像像素的 numpy 数组。创建这个字典需要 19 GB 的 RAM,我总共有 24 GB。然后我需要根据键对字典进行排序,最后只取这个有序字典的值并将其保存为一个大的 numpy 数组。我需要这个大的 numpy 数组,因为我想将它发送到 train_test_split sklearn 函数并将整个数据拆分为针对其标签的训练和测试集。我发现了这个问题,他们在创建 19GB 字典后尝试对字典进行排序的步骤中遇到 RAM 用完的问题:如何对 LARGE 字典进行排序,人们建议使用数据库。

使用 np.stack 时,我将每个 numpy 数组堆叠在新数组中,这就是我用完 RAM 的地方。我买不起更多的内存。我以为我可以在 docker 容器中使用 redis,但我不明白为什么以及如何使用数据库来解决我的问题?

0 投票
2 回答
518 浏览

machine-learning - Order between using validation, training and test sets

I am trying to understand the process of model evaluation and validation in machine learning. Specifically, in which order and how the training, validation and test sets must be used.

Let's say I have a dataset and I want to use linear regression. I am hesitating among various polynomial degrees (hyper-parameters).

In this wikipedia article, it seems to imply that the sequence should be:

  1. Split data into training set, validation set and test set
  2. Use the training set to fit the model (find the best parameters: coefficients of the polynomial).
  3. Afterwards, use the validation set to find the best hyper-parameters (in this case, polynomial degree) (wikipedia article says: "Successively, the fitted model is used to predict the responses for the observations in a second dataset called the validation dataset")
  4. Finally, use the test set to score the model fitted with the training set.

However, this seems strange to me: how can you fit your model with the training set if you haven't chosen yet your hyper-parameters (polynomial degree in this case)?

I see three alternative approachs, I am not sure if they would be correct.

First approach

  1. Split data into training set, validation set and test set
  2. For each polynomial degree, fit the model with the training set and give it a score using the validation set.
  3. For the polynomial degree with the best score, fit the model with the training set.
  4. Evaluate with the test set

Second approach

  1. Split data into training set, validation set and test set
  2. For each polynomial degree, use cross-validation only on the validation set to fit and score the model
  3. For the polynomial degree with the best score, fit the model with the training set.
  4. Evaluate with the test set

Third approach

  1. Split data into only two sets: the training/validation set and the test set
  2. For each polynomial degree, use cross-validation only on the training/validation set to fit and score the model
  3. For the polynomial degree with the best score, fit the model with the training/validation set.
  4. Evaluate with the test set

So the question is:

  • Is the wikipedia article wrong or am I missing something?
  • Are the three approaches I envisage correct? Which one would be preferrable? Would there be another approach better than these three?
0 投票
1 回答
416 浏览

python - 如何提高 scikit-learn 中预测的准确性

我想根据3 个 features1 个 target预测一个参数。这是我的输入文件(data.csv):

这是我的代码:

根据趋势,如果我将 0.375 作为所有特征的输入,我预计会得到 0.1875 左右的值。然而,代码预测了这一点:

这是不正确的。我不知道问题出在哪里。有人知道我该如何解决吗?

谢谢

0 投票
1 回答
152 浏览

pandas - scikit learn 的训练-测试拆分导致训练数据中只有一个唯一值的特征

我正在尝试训练多元线性回归模型。我有一个名为“main”的数据集。该数据集中的分类变量很少。我对分类变量进行了虚拟化。假设虚拟化后得到的列是A、B、C、D等。现在,当我尝试在这个主数据集上运行训练测试拆分时,由此获得的训练数据集在这些列之一中只有值 0。我该如何克服这个问题。

我正在使用的代码是:

对于训练测试拆分:

在运行以下代码时:

结果是:Index([], dtype='object')

并且在为火车数据运行以下代码时:

结果是:Index(['A', 'D', 'S'], dtype='object')

我希望生成的火车集包含具有所有值组合的特征。但是,这种拆分在某些功能中只给了我一个值

编辑:我检查了这些列中的唯一值,这些列高度不平衡,只有一个值出现在正例中。我尝试分层,它至少需要两排正类。许多列都是这种情况。所以我不能在训练数据集中单独包含这些列,因为它需要为所有列编写代码。我希望这能自动完成。

0 投票
1 回答
32 浏览

machine-learning - 用于提前一天的基础预测模型评估。对于我的火车测试拆分,我是进行 80:20 拆分还是进行(其余时间:最后一天)拆分?

我有 3 个月的时间序列数据,间隔 15 分钟。(一天有 96 个时间段)我有温度栏 [Temp] 和太阳辐照度 [SI](太阳强度)栏。我的模型必须在“前一天”的基础上预测一整天的温度。即我必须根据前一天的数据预测 96 个时隙。当我“自己”评估我的模型并将我的数据分成训练集和测试集时。我如何拆分它们?我会做 80:20 的拆分吗?但是我的测试数据会有超过一天的读数。还是我做一个(3个月 - 1天)->作为火车,只在最后一天测试?

0 投票
1 回答
11244 浏览

python-3.x - 如何根据组 id 生成训练测试拆分?

我有以下数据:

我需要根据“Group_ID”将数据集拆分为训练和测试集,以便 80% 的数据进入训练集,20% 进入测试集。

也就是说,我需要我的训练集看起来像:

和测试集:

最简单的方法是什么?据我所知,sklearn 中的标准 test_train_split 函数不支持按组拆分,我还可以指示拆分的大小(例如 80/20)。

0 投票
2 回答
3865 浏览

dataset - 预言家预测的诊断问题

我正在研究芝加哥的犯罪数据集,并专门研究芝加哥犯罪率的未来预测(从 2012 年到 2016 年,我有数据)。我使用 facebook 的先知包生成了预测。它工作得很好,一切都完成了。现在我想训练和测试我的模型。因此,我将数据集分成 70% 的训练和 30% 的测试。我训练了模型并对其进行了测试,最后我得到了一个不错的情节。我对诊断部分更感兴趣。Prophet 提供了一个cross_validation()我使用的函数:df.cv<- cross_validation(m, initial = nrow(trainData), period = 365, horizon = nrow(testData), units = 'days') . 问题就在这里,我总是收到这个错误并从昨天开始尝试修复它,但没有成功:

有人知道如何修复此错误并提供诊断列表吗?

我的火车/测试图看起来是这样的:

训练/测试图

我的火车数据集可以在这里下载:https ://ufile.io/4e38c 我的测试数据集在这里:https ://ufile.io/ds65p

我希望有人能帮助我!这将是非常棒的,我将非常感激。提前致谢!

0 投票
2 回答
2007 浏览

python - sklearn.model_selection.train_test_split 中分层方法的(无效参数)错误

我正在尝试在sklearn.model_selection.train_test_split. 这是我的代码:

但我得到这个错误

我在寻找这个答案,他们提到这stratify splitting是 0.17 版中的新内容,我必须更新我的sklearn. 我找了我的版本。这是0.20.2

所以请任何人都可以帮助我。

0 投票
1 回答
1395 浏览

apache-spark - 如何在 Pyspark Dataframe 中训练测试拆分时间序列数据

我想根据时间对排序的 Pyspark 数据帧进行训练测试拆分。假设前 300 行将在训练集中,接下来的 200 行将在测试拆分中。

我可以选择前 300 行 -

但是如何从 Pyspark 数据框中选择最后 200 行?