简体   繁体   English

如何在 Sci-kit 中对多输出回归器使用交叉验证?

[英]How to use Cross Validation for Multioutput Regressor in Sci-kit?

first my setup: X is my feature table.首先是我的设置:X 是我的功能表。 It has 150 000 features and 96 samples.它有 150 000 个特征和 96 个样本。 So 150 000 columns and 96 rows.所以 150 000 列和 96 行。

y is my target table. y 是我的目标表。 It has 4 labels and of course 96 samples.它有 4 个标签,当然还有 96 个样本。 So 4x96 (columns x rows).所以 4x96(列 x 行)。

After splitting into train and test data I'm using MLPRegressor.拆分成训练和测试数据后,我正在使用 MLPRegressor。 Based on the documentation of Sci-kit it is an native multioutput regressor.根据 Sci-kit 的文档,它是一个原生多输出回归器。 So I can use it to predict my four desired output values with a new sample of 150 000 features .所以我可以用它来预测我想要的四个输出值,其中包含 150 000 个特征的新样本。 My code:我的代码:

mlp = MLPRegressor(hidden_layer_sizes=(2000, 2000), solver= 'lbfgs', max_iter=100)
mlp.fit(X_train,y_train)

And then I'm using cross validation.然后我使用交叉验证。

cross_validation.cross_val_score(mlp, X, y, scoring='r2')

The output is a list with 3 entries (parameter cv=3).输出是一个包含 3 个条目的列表(参数 cv=3)。 I don't really get how my 4 labels get represented by these 3 values.我真的不明白我的 4 个标签是如何由这 3 个值表示的。 I expected something in a format like this: label 1: 3 entries, label 2: 3 entries and the same with label 3 and 4. So I'm getting the R^2-Value for all my labels three times for different splittings of test and train data.我期望的格式是这样的:标签 1:3 个条目,标签 2:3 个条目,标签 3 和 4 也是如此。因此,对于不同的拆分,我将所有标签的 R^2 值重复三次测试和训练数据。

Am I missing something?我错过了什么吗? Do I need to use Multioutputregressor?我需要使用 Multioutputregressor 吗? (See doc here) (请参阅此处的文档)

And Here the documentation of cross validation. 这里是交叉验证的文档。

Thanks.谢谢。

First thing is if you are actually using cross_validation.cross_val_score() , then you should replace that with model_selection.cross_val_score() .首先,如果您实际使用的是cross_validation.cross_val_score() ,那么您应该将其替换为model_selection.cross_val_score() Module cross_validation has been deprecated and removed from latest version of scikit.模块cross_validation已被弃用并从最新版本的 scikit 中删除。

Now coming to why you are only getting a single score for all your outputs and not individual entries is because thats how the default value of scorer is set.现在来谈谈为什么您只为所有输出而不是单个条目获得一个分数是因为这就是 scorer 的默认值的设置方式。

You have used scoring 'r2' which is documented here .您已使用此处记录的评分'r2' In that, there is an option to change the result if the input is multi-output (as your case) by using the在那里,如果输入是多输出(如您的情况),则可以选择通过使用

multioutput : Defines aggregating of multiple output scores. multioutput :定义多个输出分数的聚合。 Array-like value defines weights used to average scores.类似数组的值定义了用于平均分数的权重。 Default is “uniform_average”.默认为“uniform_average”。

'raw_values' : Returns a full set of scores in case of multioutput input. 'raw_values' :在多输出输入的情况下返回完整的分数集。

'uniform_average' : Scores of all outputs are averaged with uniform weight. 'uniform_average' :所有输出的分数以统一的权重进行平均。

'variance_weighted' : Scores of all outputs are averaged, weighted by the variances of each individual output. 'variance_weighted' :所有输出的分数被平均,由每个单独输出的方差加权。

You see that the default value is 'uniform_average' , which just averages all the outputs to get a single value, which is what you are getting.您会看到默认值是'uniform_average' ,它只是平均所有输出以获得单个值,这就是您得到的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM