knn.var

来自「本程序是基于linux系统下c++代码」· VAR 代码 · 共 108 行

VAR
108
字号
knn.var               package:knnTree               R Documentation

_K-_N_e_a_r_e_s_t _N_e_i_g_h_b_o_r _C_l_a_s_s_i_f_i_c_a_t_i_o_n _W_i_t_h _V_a_r_i_a_b_l_e _S_e_l_e_c_t_i_o_n

_D_e_s_c_r_i_p_t_i_o_n:

     Construct or predict with k-nearest-neighbor classifiers, using
     cross-validation to select variables by forward or backward
     selection, to choose the best k and to choose scaling methods.

_U_s_a_g_e:

     knn.var (train, test, k.vec = seq (1, 31, by=2), 
     theyre.the.same=FALSE,
     return.all.rates=FALSE, scaling = 1, backward = FALSE, max.steps=-1, 
     save.call = FALSE, 
     verbose = 0, use.big=TRUE)

_A_r_g_u_m_e_n_t_s:

   train: 

    test: 

   k.vec: 

theyre.the.same: 

return.all.rates: 

 scaling: 

backward: 

max.steps: 

save.call: 

 verbose: 

 use.big: 

     {logical, TRUE if the C code should try to use a technique that
     uses more memory but runs faster.}

_D_e_t_a_i_l_s:

     R{knn.var} constructs a k-nearest-neighbor classifier using
     Euclidean metric.  Leave-one-out cross-validation together with
     stepwise (forward or backward, but not both) selection is used to
     find the best set of variables to include, the best choice of k,
     and whether the data should be scaled.

_V_a_l_u_e:

     Object of class knn.  This is a list with between six and eight of
     the following components:
      which: logical vector, one per input variable; the i-th element
     of which is TRUE if the i-th input variable is in the classifier
      rate: Smallest misclassification rate acheived by algorithm.  If 
     return.all.rates is TRUE this is a vector of error rates, one for
     each element of k.vec
      best.k: Number giving the optimal value of k, chosen from among
     the elements of k.vec.
      scaled: indicator of best scaling.  FALSE means no scaling was
     used; TRUE  means scaling was used. 
      n: the number of observations in the training set
      col.sds: Numeric vector of scaling factors, present only if
     scaled != 0.   If scaled = 1 these are column SD's; if scaled = 2
     they are MAD's.
      pure: logical, TRUE if every item in the training set had the
     same class.  If a training set is pure then all the elements of
     which are FALSE, best.k is taken to be the first element of k.vec
     and scaled is set to 0.
      call: a copy of the call used to create the object, if save.call
     was TRUE

_A_u_t_h_o_r(_s):

     Sam Buttrey buttrey@nps.navy.mil

_R_e_f_e_r_e_n_c_e_s:

     Buttrey and Karo, 2002

_S_e_e _A_l_s_o:

     'knnTree'

_E_x_a_m_p_l_e_s:

     data(iris)
     set.seed (3)
     samp <- sample (nrow(iris), size = 75, replace=FALSE)
     knn.var (iris[samp,c(5, 1:4)]) # Build classifier
     # Output produced by this-is-escaped-codenormal-bracket33bracket-normal
     ## Not run: This knn classifier is based on 75 observations.
     It uses 1 out of 4 variables without scaling.

     Training rate is 0.01333 , achieved at k = 1## End(Not run)
     iris.knn <- knn.var (iris[samp,c(5, 1:4)]) # Build and save, then predict
     predict (iris.knn, iris[-samp,c(5, 1:4)], iris[samp, c(5, 1:4)])
     ## Not run: 
     $rate
     [1] 0.08
     ## End(Not run)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?