Neural network 利用交叉验证选择apachespark多层感知器的网络结构
我正试图为ApacheSpark中的多层接收器确定最佳架构,我想知道是否可以使用交叉验证 一些代码:Neural network 利用交叉验证选择apachespark多层感知器的网络结构,neural-network,apache-spark-mllib,cross-validation,apache-spark-ml,Neural Network,Apache Spark Mllib,Cross Validation,Apache Spark Ml,我正试图为ApacheSpark中的多层接收器确定最佳架构,我想知道是否可以使用交叉验证 一些代码: // define layers int[] layers = new int[] {784, 78, 35, 10}; int[] layers2 = new int[] {784, 28, 28, 10}; int[] layers3 = new int[] {784, 84, 10}; int[] layers4 = new int[] {784, 392, 171, 78, 10};
// define layers
int[] layers = new int[] {784, 78, 35, 10};
int[] layers2 = new int[] {784, 28, 28, 10};
int[] layers3 = new int[] {784, 84, 10};
int[] layers4 = new int[] {784, 392, 171, 78, 10};
MultilayerPerceptronClassifier mlp = new MultilayerPerceptronClassifier()
.setMaxIter(25)
.setLayers(layers4);
ParamMap[] paramGrid = new ParamGridBuilder()
.addGrid(mlp.seed(), new long[] {895L, 12345L})
//.addGrid(mlp.layers(), new int[][] {layers, layers2, layers3})
.build();
CrossValidator cv = new CrossValidator()
.setEstimator(mlp)
.setEvaluator(new MulticlassClassificationEvaluator())
.setEstimatorParamMaps(paramGrid).setNumFolds(10);
CrossValidatorModel model = cv.fit(train);
如您所见,我在整数数组(layers-layers4)中定义了一些体系结构
实际上,我必须多次拟合模型,手动更改学习算法的layers参数
我想要的是在传递给CrossValidator(ParamMap中注释掉的行)的ParamMap中提供不同的体系结构
我怀疑这是可能的,因为ParamGridBuilder似乎知道layers()方法,但它不接受提供的参数
如果我在这个假设中是正确的,那么我做错了什么?我如何才能让它按预期工作?看看代码,它在语法上似乎是正确的。 它不工作可能是一个bug,也可能是有意的,因为它在计算上相当昂贵。所以我想不,你不能用简历 我最终使用了以下公式:
Number of units in hidden-layer = ceil((Number of inputs + outputs) * (2/3))
来源: