R Neural Network: Error in neurons[[i]] %*% weights[[i]] : requires numeric/complex matrix/vector arguments -
i trying fit neural network in r using neuralnet package binary classsification. here's code:
n<-names(train) f<-as.formula(paste("y~", paste(n[!n %in% c("y","id")], collapse = " + "))) nn.train<-train[,!colnames(train) %in% c("id")] #create nn model library(neuralnet) nn <- neuralnet(f, data=nn.train, linear.output=false, err.fct = "ce", threshold = 0.5, hidden = 5, stepmax = 1e6, rep=1)
this training dataset nn.train looks like:
'data.frame': 44115 obs. of 51 variables: $ v1 : num -0.00255 -0.00651 -0.00298 -0.00368 -0.00734 ... $ v2 : num 0.001711 0.000582 -0.001216 -0.002618 0.005182 ... $ v3 : num -0.000154 0.000225 0.000271 -0.000469 0.000228 ... $ v4 : num 0.000653 -0.000188 -0.002388 0.001877 -0.000513 ... $ v5 : num 0.000499 0.004389 0.000286 -0.005098 -0.002419 ... $ v6 : num 0.0025538 0.0013363 0.0004831 -0.0000491 0.0025626 ... $ v7 : num -0.000457 0.005012 0.004569 0.000953 0.001897 ... $ v8 : num -0.002214 -0.004218 -0.000477 -0.003886 0.007115 ... $ v9 : num -0.000179 0.0028142 0.0017912 -0.0013334 -0.0000217 ... $ v10: num 0.000595 -0.002748 0.000372 0.000181 -0.007722 ... $ v11: num 0.000031 0.002415 0.001556 -0.000771 0.002484 ... $ v12: num -0.00173 -0.00349 -0.00384 0.0015 -0.00545 ... $ v13: num -0.00609 0.0078 -0.00239 0.0054 0.00171 ... $ v14: num 0.000827 0.007988 0.003059 0.001085 0.014218 ... $ v15: num 0.00339 -0.00373 0.00238 0.00747 -0.00591 ... $ v16: num -0.000785 -0.003595 0.006264 0.000486 -0.015204 ... $ v17: num 0.00314 -0.00412 -0.00605 0.00385 -0.00396 ... $ v18: num -0.00023 0.00642 -0.0015 -0.00221 0.01579 ... $ v19: num 0.000627 -0.009451 -0.002939 0.005636 -0.006328 ... $ v20: num -0.001 0.00268 -0.00164 -0.00149 0.00484 ... $ v21: num 0.000374 -0.004883 -0.004358 0.003519 0.017265 ... $ v22: num -0.0000281 0.0072532 0.0002763 -0.0035641 -0.0000763 ... $ v23: num -0.001404 -0.004764 0.007284 -0.000317 -0.019807 ... $ v24: num 0.00228 -0.007045 0.001688 -0.000884 0.001551 ... $ v25: num -0.002273 -0.006216 0.000883 -0.001772 -0.001794 ... $ v26: num 0.000697 -0.001269 -0.001608 -0.000756 0.004126 ... $ v27: num 0.00325 0.01148 -0.00562 -0.002 -0.00474 ... $ v28: num 0.00105 -0.00983 0.00207 -0.00383 0.00317 ... $ v29: num 0.000501 0.005874 -0.008242 -0.002254 -0.003525 ... $ v30: num -0.000875 0.001314 -0.002309 0.000255 0.009615 ... $ v31: num 0.003109 -0.000797 -0.000386 0.003241 -0.002977 ... $ v32: num 0.00487 0.00458 -0.00676 -0.00189 -0.01085 ... $ v33: num 0.000265 -0.000254 0.018617 -0.001104 -0.004839 ... $ v34: num 0.0000765 0.005325 -0.0005011 -0.0045697 0.0020402 ... $ v35: num -0.00295 0.00838 0.00043 -0.00359 -0.00942 ... $ v36: num 0.00336 -0.0057 -0.01404 0.00186 -0.00528 ... $ v37: num -0.00321 -0.00268 -0.0026 -0.00674 -0.00399 ... $ v38: num 0.000084 -0.005826 0.001771 0.004715 0.008845 ... $ v39: num 0.002567 -0.001225 0.003515 -0.002223 0.000895 ... $ v40: num 0.00383 -0.00454 0.00152 -0.00243 -0.00931 ... $ v41: num 0.001465 0.007912 -0.000598 0.001808 -0.003645 ... $ v42: num 0.000379 0.002077 -0.008668 -0.000406 0.003503 ... $ v43: num -0.008015 -0.000934 0.004492 -0.002327 -0.003737 ... $ v44: num 0.00266 -0.005037 0.005414 0.000566 0.004254 ... $ v45: num -0.00446 0.00343 0.00574 0.00157 0.00301 ... $ v46: num 0.00276 0.00135 0.00119 -0.00228 -0.0017 ... $ v47: num 0.008141 -0.006811 0.003744 -0.000869 0.000467 ... $ v48: num -0.00477 0.00363 0.00326 -0.00227 0.00905 ... $ v49: num -0.00738 -0.001 -0.00622 -0.00039 0.00217 ... $ v50: num -0.00594 -0.006 0.0025 0.00364 0.00313 ... $ y : factor w/ 2 levels "0","1": 1 1 1 1 2 1 1 1 1 1 ...
this formula looks like:
y ~ v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9 + v10 + v11 + v12 + v13 + v14 + v15 + v16 + v17 + v18 + v19 + v20 + v21 + v22 + v23 + v24 + v25 + v26 + v27 + v28 + v29 + v30 + v31 + v32 + v33 + v34 + v35 + v36 + v37 + v38 + v39 + v40 + v41 + v42 + v43 + v44 + v45 + v46 + v47 + v48 + v49 + v50
i have consulted other questions regarding same error. have no na's. independent variables numeric. still getting error:
error in neurons[[i]] %*% weights[[i]] : requires numeric/complex matrix/vector arguments
i subset train data remove variables not in formula. tried converting training dataset matrix. still getting error. please help.
update: suggested, can use generate representative subset of dataset.
train<- structure(list(v1 = c(-0.0003, -0.00117, -0.00147, -0.00247), v2 = c(-0.00218, -0.00116, 0.00017, 0.00135), v3 = c(-0.00135, -0.0008, -0.00013, -0.00077), v4 = c(0.00028, 0.0012, 0.0012, 0.00437), v5 = c(-0.00263, 0.00085, 0.0006, 0.0006), v6 = c(0.00472, 0.00067, 0.00066, 0.0002), v7 = c(0.00348, -0.00161, -0.00043, 0.00172), v8 = c(0.00012, -0.00051, -0.00285, 0.00073), v9 = c(-0.00109, 0.00004, 0.00062, -0.00017), v10 = c(0.00268, -0.00039, 0.00034, -0.00124), v11 = c(0.00138, -0.00056, -0.00011, -0.00164), v12 = c(-0.00086, -0.00033, 0.00068, -0.00062), v13 = c(0.00021, 0.00049, -0.00007, 0.00302), v14 = c(-0.0005, 0.00111, 0.00008, -0.00258), v15 = c(0.00011, -0.00037, 0.00002, -0.00086), v16 = c(0.00213, -0.00053, -0.0008, -0.00677), v17 = c(-0.00038, 0.00082, 0.00041, 0.00269), v18 = c(-0.00043, -0.00034, 0.00008, -0.00629), v19 = c(0.00024, -0.00017, 0.00046, -0.00178), v20 = c(-0.00097, 0.00167, 0.00081, 0.00126), v21 = c(0.00033, 0.00208, 0.00178, -0.00361), v22 = c(0.00105, -0.00038, -0.00078, 0.00586), v23 = c(-0.00093, 0.00223, 0.00274, -0.00478), v24 = c(0.00044, 0.00217, 0.00147, 0.00279), v25 = c(0.00108, 0.00121, 0.00208, 0.00102), v26 = c(0.00125, 0.00065, 0.00081, -0.00647), v27 = c(0.00015, -0.00123, -0.00156, -0.001), v28 = c(-0.00031, 0.00083, 0.00103, 0.00314), v29 = c(-0.00042, -0.00021, 0.00003, -0.00247), v30 = c(-0.00064, -0.00055, -0.00022, -0.00027), v31 = c(0.00021, 0.00084, 0.00132, -0.00121 ), v32 = c(-0.00005, 0.00061, -0.00007, 0.00343), v33 = c(0.00042, -0.00197, -0.00085, -0.00322), v34 = c(-0.00014, -0.00192, -0.00141, -0.00052), v35 = c(0.00048, 0.00036, -0.00115, 0.00176), y = c(1, 0, 0, 0)), .names = c("v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", "v32", "v33", "v34", "v35", "y"), row.names = c(na, 4l), class = "data.frame")
Comments
Post a Comment