svd(x,nu = 0)中的错误:'x'中的无限或缺失值(选中不存在负值)

时间:2016-11-27 08:32:14

标签: r machine-learning pca

我知道这是PCA的一个常见错误,但我查看了所提供的解决方案并且无法正常工作。

我跟着: Error in svd(x, nu = 0) : 0 extent dimensions

以下是我的代码摘录:

require(class)
set.seed(2095)
# dataset source:https://kdd.ics.uci.edu/databases/kddcup99/kddcup99.html
normalize<-function(x) {
  return ((x - min(x)) / (max(x) - min(x)))
}
dataset <- read.csv("data/kdd_data_10pc.csv", header = FALSE, sep = ",")
names   <- read.csv("data/kdd_names.csv", header = FALSE , sep = ";")
names(dataset) <- sapply((1:nrow(names)),function(i) toString(names[i, 1]))

# extracting relevant features
dataset_extracted <- dataset[, c("src_bytes", "dest_bytes", "count", "dst_host_count", "dst_host_same_srv_rate", "dst_host_serror_rate", "label")]

head(dataset_extracted, 3)

log.kdd   <-log(dataset_extracted[, 1:6])
kdd.label <- dataset_extracted[, 7]

kdd.pca <-prcomp(log.kdd,
             center = TRUE,
             scale. = TRUE)

摘要(数据集)输出如下:

 summary(dataset_extracted)
   src_bytes           dest_bytes          count       dst_host_count  dst_host_same_srv_rate dst_host_serror_rate      label       
 Min.   :        0   Min.   :      0   Min.   :  0.0   Min.   :  0.0   Min.   :0.0000         Min.   :0.0000       smurf.  :280790  
 1st Qu.:       45   1st Qu.:      0   1st Qu.:117.0   1st Qu.:255.0   1st Qu.:0.4100         1st Qu.:0.0000       neptune.:107201  
 Median :      520   Median :      0   Median :510.0   Median :255.0   Median :1.0000         Median :0.0000       normal. : 97278  
 Mean   :     3026   Mean   :    869   Mean   :332.3   Mean   :232.5   Mean   :0.7538         Mean   :0.1768       back.   :  2203  
 3rd Qu.:     1032   3rd Qu.:      0   3rd Qu.:511.0   3rd Qu.:255.0   3rd Qu.:1.0000         3rd Qu.:0.0000       satan.  :  1589  
 Max.   :693375640   Max.   :5155468   Max.   :511.0   Max.   :255.0   Max.   :1.0000         Max.   :1.0000       ipsweep.:  1247  
                                                                                                                   (Other) :  3713  

根据摘要,没有提取的列最小值为任何负值。

我是机器学习的新手。感谢所提供的任何帮助。显示的确切错误是

Error in svd(x, nu = 0) : infinite or missing values in 'x'

1 个答案:

答案 0 :(得分:1)

将日志转换应用于包含零值的对象(SELECT * FROM Attendance WHERE MONTH(Date) = 12 AND YEAR(Date) = 2016)。这将产生负无穷大的元素。请尝试使用dataset

另外,请不要忘记在函数log1p()中应用您编码的标准化。

另外,鉴于某些异常值的大小,我不确定对数转换是否足够 - 您可能需要考虑排除某些观察结果。