Matrix Completion 2

Sign in to test your solution.
X <- data.matrix(scale(USArrests)) nomit <- 20 set.seed(15) ina <- sample(seq(50), nomit) inb <- sample(1:4, nomit, replace = TRUE) Xna <- X index.na <- cbind(ina, inb) Xna[index.na] <- NA fit.svd <- function(X, M = 1) { svdob <- svd(X) with(svdob, u[, 1:M, drop = FALSE] %*% (d[1:M] * t(v[, 1:M, drop = FALSE])) ) } Xhat <- Xna xbar <- colMeans(Xna, na.rm = TRUE) Xhat[index.na] <- xbar[inb] thresh <- 1e-7 rel_err <- 1 iter <- 0 ismiss <- is.na(Xna) mssold <- mean((scale(Xna, xbar, FALSE)[!ismiss])^2) mss0 <- mean(Xna[!ismiss]^2) while(rel_err > thresh) { iter <- iter + 1 # Step 2(a) ... # Step 2(b) ... # Step 2(c) ... cat("Iter:", iter, "MSS:", mss, "Rel. Err:", rel_err, "\n") }
You can submit as many times as you like. Only your latest submission will be taken into account.
Sign in to test your solution.