R NeuroNet:“不一致的参数". [英] R neuralNet: "non-conformable arguments"

查看:132
本文介绍了R NeuroNet:“不一致的参数".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

啊!尝试使用神经网络compute时,始终出现以下错误:

Argh! I keep getting the following error when attempting to compute with my neural network:

> net.compute <- compute(net, matrix.train2)
Error in neurons[[i]] %*% weights[[i]] : non-conformable arguments

我不知道是什么问题.下面,我将为您提供示例数据和矩阵格式的示例,然后向您展示我尝试运行的代码.

I can't figure out what the problem is. Below I'll provide you with an example data and formatting from my matrices and then I'll show you the code I'm attempting to run.

  • matrix.train1用于训练网络

> matrix.train1
    (Intercept) survived pclass sexmale    age sibsp parch     fare embarkedC embarkedQ embarkedS
1             1        0      3       1  22.00     1     0   7.2500         0         0             1
2             1        1      1       0  38.00     1     0  71.2833         1         0         0
3             1        1      3       0  26.00     0     0   7.9250         0         0         1
4             1        1      1       0  35.00     1     0  53.1000         0         0         1
5             1        0      3       1  35.00     0     0   8.0500         0         0         1
6             1        0      3       1 999.00     0     0   8.4583         0         1         0
7             1        0      1       1  54.00     0     0  51.8625         0         0         1
8             1        0      3       1   2.00     3     1  21.0750         0         0         1
9             1        1      3       0  27.00     0     2  11.1333         0         0         1
10            1        1      2       0  14.00     1     0  30.0708         1         0         0
11            1        1      3       0   4.00     1     1  16.7000         0         0         1

  • matrix.train2是用于测试模型的训练数据的一部分

  • matrix.train2 is a slice of the training data used for testing the model

    > matrix.train2
        (Intercept) pclass sexmale    age sibsp parch     fare embarkedC embarkedQ embarkedS
    1             1      1       1  49.00     1     1 110.8833         1         0         0
    2             1      3       1  42.00     0     0   7.6500         0         0         1
    3             1      1       0  18.00     1     0 227.5250         1         0         0
    4             1      1       1  35.00     0     0  26.2875         0         0         1
    5             1      3       0  18.00     0     1  14.4542         1         0         0
    6             1      3       1  25.00     0     0   7.7417         0         1         0
    7             1      3       1  26.00     1     0   7.8542         0         0         1
    8             1      2       1  39.00     0     0  26.0000         0         0         1
    9             1      2       0  45.00     0     0  13.5000         0         0         1
    10            1      1       1  42.00     0     0  26.2875         0         0         1
    11            1      1       0  22.00     0     0 151.5500         0         0         1
    

  • 两个矩阵之间唯一的真正区别是matrix.train2不包含survived列.

    The only real difference between the two matrices is that matrix.train2 doesn't contain the survived column.

    这是我正在尝试运行的R代码:

    Here's the R code I'm attempting to run:

    #Build a matrix from training data 
    matrix.train1 <- model.matrix(
      ~ survived + pclass + sex + age + sibsp + parch + fare + embarked, 
      data=train1
    )
    
    library(neuralnet)
    
    #Train the neural net
    net <- neuralnet(
      survived ~ pclass + sexmale + age + sibsp + parch + fare + embarkedC + 
      embarkedQ + embarkedS, data=matrix.train1, hidden=10, threshold=0.01
    )
    
    #Build a matrix from test data
    matrix.train2 <- model.matrix(
      ~ pclass + sex + age + sibsp + parch + fare + embarked, 
      data=train2
    )
    
    #Apply neural net to test matrix 
    net.results <- compute(
      net, matrix.train2
    )
    
    Error in neurons[[i]] %*% weights[[i]] : non-conformable arguments
    

    有人可以告诉我我在做什么错吗?

    Can anyone tell me what I'm doing wrong here?

    谢谢!

    根据到目前为止的评论进行更新:

    Updates based on comments so far:

    1. 使用来自"> 新的预测类的解决方案使用Neuronet 的数据似乎无效.

    1. Using the solution from "Predicting class for new data using neuralnet" doesn't seem to work.

    > net.compute <- compute(net, matrix.train2[,1:10])
    Error in neurons[[i]] %*% weights[[i]] : non-conformable arguments
    

  • 我正在通过model.matrix手动将train1train2数据帧放入矩阵,因为如果没有,则会出现以下错误:

  • I'm manually putting my train1 and train2 data frames into matrices via model.matrix because if I don't I get the following error:

    > Error in neurons[[i]] %*% weights[[i]] : 
    requires numeric/complex matrix/vector arguments
    

  • 注意:有关为什么使用model.matrix的更多详细信息,请参见以下线程:" ".

    Note: see the following thread for more details on why I'm using model.matrix: "Working with neuralnet in R for the first time: get "requires numeric/complex matrix/vector arguments" but don't know how to correct".

    推荐答案

    您似乎需要删除预测变量.试试这个:

    It looks like you need to remove the predictor variable. Try this:

    nn_pred<-compute(nn,test[,3:11])
    

    这篇关于R NeuroNet:“不一致的参数".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆