Getting error using neuralnet function at R - r

I am getting an error, while running the below code:
library(neuralnet)
library(datasets.load)
Neural_Net = neuralnet(formula = dist ~ mag , data = attenu, hidden = C(1,3) )
I get the below error:
Error in C(1, 3) : object not interpretable as a factor
I couldn't solve the problem. Where am I doing wrong?
I will be very glad for any help. Thanks a lot.

Related

Error for create_slope_cs function in the leastcostpath package

guys! I encountered an error when creating a cost surface based on DEM data.
Adm1 <-
rgeoboundaries::geoboundaries(
country = "Austria",
adm_lvl = "adm0")
r <- get_elev_raster(Adm1,z=4)
cs <- create_slope_cs(dem = r, cost_function = 'tobler', neighbours = 16)
The error is like
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'x' in selecting a method for function 'extent': ‘srs’ is not a slot in class “BasicRaster”
I can run this code on my other laptop. So I think there's nothing wrong with my code. But do you know how to fix this?

Error in xj[i] : invalid subscript type 'list' error in R random forest

I am using the airbnb dataset. After cleaning it, I tried to apply a random forest (I did a tree and a pruned tree and they worked). I don't have a lot of experience but here is my code :
split_index <- createDataPartition(airbnbcleanedfinal$logprice, p = 0.8, list = F)
#Use index to split data
training<-training <- airbnbcleanedfinal[split_index,]
training1 <- airbnbcleanedfinal[sample(nrow(airbnbcleanedfinal),100000,replace=TRUE),]
features_test <- airbnbcleanedfinal[-split_index, !(colnames(airbnbcleanedfinal) %in% c('logprice'))]
target_test <- airbnbcleanedfinal[-split_index, 'logprice']
library(randomForest)
rf_train <- randomForest(logprice ~ ., data = airbnbcleanedfinal,
subset=training,
mtry = 5)
But I always get the same error message :
Error in xj[i] : invalid subscript type 'list'
I also tried to delete subset=training and put directly data=training but it makes R run forever. I also tried using training1 that I created for that purpose but still got the same error message.
I tried unlist(training) but it did not work. My data is huge (85k-15 variables) too, maybe that is the problem? How can I force training to be a list?

I am receiving 'Error in !toroidal : invalid argument type'

I am trying to run a supervised SOM model based on cross-validated values.
The issue seems is in the sup.som line. I receive this error: Error in !toroidal : invalid argument type.
This code has worked fine in the past (within past few days) and I have tried restarting RStudio. There was a very similar question here (Error in !toroidal : invalid argument type in R with som package) but the issue seemed to have resolved itself for the other person. Any help is appreciated!
My code is:
require(kohonen)
set.seed(123)
fitControl <- trainControl(method = "cv",number = 10)
tg <- expand.grid(xdim=c(3:10), ydim=c(3:10), user.weights=seq(0.1,0.9,by=0.1), topo="hexagonal")
somFit1 <- train(train[,1:6], as.factor(train$CORR), method="xyf", trControl=fitControl, tuneLength=20, tuneGrid=tg)
'''sup.som <- xyf(training.sc, classvec2classmat(corrupt.train), grid = somgrid(xdim=somFit1$bestTune$xdim, ydim=somFit1$bestTune$ydim, topo="hexagonal"), user.weights=somFit1$bestTune$user.weights, keep.data=TRUE)
I ended up trying my code in the R console to see if I could get more detailed error messages, and I got the following:
require(class)
Loading required package: class
Attaching package: ‘class’
The following object is masked from ‘package:kohonen’:
somgrid
The solution was to specify kohonen::somgrid before my code as follows:
sup.som <- xyf(training.sc, classvec2classmat(corrupt.train), grid = kohonen::somgrid(xdim=somFit1$bestTune$xdim, ydim=somFit1$bestTune$ydim, topo="hexagonal"), user.weights=somFit1$bestTune$user.weights, keep.data=TRUE)
Hope this helps someone else

DEoptim - Error in get(as.character(FUN))

I ran into a problem with the DEoptim package. I am trying to minimize the function minF by optimizing vector optVector (see code).
##construct function
minF <- function(x, y, z){
return(mean((z-rowSums(t(x*t(y))))^2))
}
#random matrix and vector
testmrx <- matrix(rnorm(6),38,9)
vctr <- runif(38, min=0, max=50)
#Vector to be optimized and its bounds
optVector = c(20,20,50,30,30,10,3,5,5)
lowr = c(0,0,0,0,0,0,0,0,0)
uppr = c(50,50,200,100,100,50,20,20,20)
#Call of DEoptim
DEoptim(fn = minF(optVector, testmrx, vctr), lower=lowr, upper=uppr)
When I try to do this I get following error:
Error in get(as.character(FUN), mode = "function", envir = envir) :
object 'fn' of mode 'function' was not found
I found a similar error posted (link), but the proposed solution of changing variable names did not work. I have no idea what might be causing the problem here. Any help would be greatly appreciated!

invalid type (list) message in applying gmm method

The moment condition function is simply exp(-g/r)-1, where g is a known series of daily return on AAA-class bond index, and r is the rikiness measure to be derived through gmm. My codes are as follows:
View(Source)
library(gmm)
data(Source)
x <- Source[1:5200,"AAA"]
m <- function(r,x)
{m.1 <- exp(-x[,"AAA"]/r)-1}
summary(gmm(m,x,t0=1,method="BFGS",control=1e-12))
Which in term yields the following error message:
****Error in model.frame.default(formula = gmat ~ 1, drop.unused.levels = TRUE) :
invalid type (list) for variable 'gmat'****
Could anyone help me figure out what went wrong?
Thanks a lot!
For those kind people who would like to replicate the results, please find attached the source data as mentioned above.
The correct r is 1.590 , which can be solved through goal searching in excel, with target function :(average(exp(-g/r)-1) )^2 and target value: 0 (tolerance: 1e-12)
https://docs.google.com/spreadsheets/d/1AnTErQd2jm9ttKDZa7On3DLzEZUWaz5Km3nKaB7K18o/edit?usp=sharing

Resources