predict.nnet package:nnet R Documentation _P_r_e_d_i_c_t _N_e_w _E_x_a_m_p_l_e_s _b_y _a _T_r_a_i_n_e_d _N_e_u_r_a_l _N_e_t _D_e_s_c_r_i_p_t_i_o_n: Predict new examples by a trained neural net. _U_s_a_g_e: ## S3 method for class 'nnet': predict(object, newdata, type = c("raw","class"), ...) _A_r_g_u_m_e_n_t_s: object: an object of class 'nnet' as returned by 'nnet'. newdata: matrix or data frame of test examples. A vector is considered to be a row vector comprising a single case. type: Type of output ...: arguments passed to or from other methods. _D_e_t_a_i_l_s: This function is a method for the generic function 'predict()' for class '"nnet"'. It can be invoked by calling 'predict(x)' for an object 'x' of the appropriate class, or directly by calling 'predict.nnet(x)' regardless of the class of the object. _V_a_l_u_e: If 'type = "raw"', the matrix of values returned by the trained network; if 'type = "class"', the corresponding class (which is probably only useful if the net was generated by 'nnet.formula'). _R_e_f_e_r_e_n_c_e_s: Ripley, B. D. (1996) _Pattern Recognition and Neural Networks._ Cambridge. Venables, W. N. and Ripley, B. D. (2002) _Modern Applied Statistics with S._ Fourth edition. Springer. _S_e_e _A_l_s_o: 'nnet', 'which.is.max' _E_x_a_m_p_l_e_s: # use half the iris data ir <- rbind(iris3[,,1], iris3[,,2], iris3[,,3]) targets <- class.ind( c(rep("s", 50), rep("c", 50), rep("v", 50)) ) samp <- c(sample(1:50,25), sample(51:100,25), sample(101:150,25)) ir1 <- nnet(ir[samp,], targets[samp,],size = 2, rang = 0.1, decay = 5e-4, maxit = 200) test.cl <- function(true, pred){ true <- max.col(true) cres <- max.col(pred) table(true, cres) } test.cl(targets[-samp,], predict(ir1, ir[-samp,])) # or ird <- data.frame(rbind(iris3[,,1], iris3[,,2], iris3[,,3]), species=factor(c(rep("s",50), rep("c", 50), rep("v", 50)))) ir.nn2 <- nnet(species ~ ., data = ird, subset = samp, size = 2, rang = 0.1, decay = 5e-4, maxit = 200) table(ird$species[-samp], predict(ir.nn2, ird[-samp,], type = "class"))