Learn R Programming

tensorBF (version 1.0.2)

predictTensorBF: Predict Missing Values using the Bayesian tensor factorization model

Description

predictTensorBF predicts the missing values in the data Y using the learned model res.

Usage

predictTensorBF(Y, res)

Arguments

Y

is a 3-mode tensor containing missing values as NA's. See function tensorBF for details.

res

the model object returned by the function tensorBF.

Value

A tensor of the same size as Y containing predicted values in place of NA's.

Details

If the original data Y contained missing values (NA's), this function predicts them using the model. The predictions are returned in the un-normalized space if res$pre contains appropriate preprocessing information.

Examples

Run this code
# NOT RUN {
#Data generation
# }
# NOT RUN {
K <- 2
# }
# NOT RUN {
X <- matrix(rnorm(20*K),20,K)
# }
# NOT RUN {
W <- matrix(rnorm(30*K),30,K)
# }
# NOT RUN {
U <- matrix(rnorm(3*K),3,K)
# }
# NOT RUN {
Y = 0
# }
# NOT RUN {
for(k in 1:K) Y <- Y + outer(outer(X[,k],W[,k]),U[,k])
# }
# NOT RUN {
 Y <- Y + array(rnorm(20*30*3,0,0.25),dim=c(20,30,3))
# }
# NOT RUN {
#insert missing values
# }
# NOT RUN {
m.inds = sample(prod(dim(Y)),100)
# }
# NOT RUN {
Yobs = Y[m.inds]
# }
# NOT RUN {
Y[m.inds] = NA
# }
# NOT RUN {
#Run the method with default options and predict missing values
# }
# NOT RUN {
res <- tensorBF(Y)
# }
# NOT RUN {
pred = predictTensorBF(Y=Y,res=res)
# }
# NOT RUN {
plot(Yobs,pred[m.inds],xlab="obs",ylab="pred",main=round(cor(Yobs,pred[m.inds]),2))
# }

Run the code above in your browser using DataLab