Phi <- as.matrix(cbind(1, train.data)) # add a column of 1 as phi_0
train.len <- 75
eta <- 0.01 # Learning rate
epsilon <- 0.001 #
tau.max <- 75 # Maximum number of iterations
T <- ifelse(train.label == c0, eval(parse(text=c0)),eval(parse(text=c1))) labels
W <- matrix(,nrow=tau.max, ncol=ncol(Phi)) # Empty Weight vector
W[1,] <- runif(ncol(Phi)) # Random initial values for weight vector
error.trace <- matrix(0,nrow=tau.max, ncol=1) # Placeholder for errors
error.trace[1] <- sum((Phi%*%W[1,])*T<0)/train.len*100
train.data
looks like:
x1 x2 x3 x4 y
5.1 3.5 1.4 0.2 C1
4.7 3.2 1.3 0.2 C1
35.0 3.6 1.4 0.2 C1
The problem happens in the last line. I checked some other posts (Matrix expression causes error "requires numeric/complex matrix/vector arguments"?) . they say to ensure that the data is in matrix format and I also checked they are both numeric (Phi
and W
).
The error I get is
Error in Phi %*% W[1, ] : requires numeric/complex matrix/vector arguments
y
column intrain.data
during matrix multiplication? – Carl