【发布时间】:2017-08-16 16:00:11
【问题描述】:
我有一个没有 NA 的数据框(由 na.omit() 删除),行数 = 1,450,683 ,同时将其转换为 model.matrix 以馈入 glmnet,最终矩阵的一些值是无限的。
str(train_again)
Classes 'tbl_df', 'tbl' and 'data.frame': 1450683 obs. of 24 variables:
$ vendor_id : Factor w/ 2 levels "1","2": 2 1 2 2 2 2 1 2 1 2 ...
$ passenger_count : int 1 1 1 1 1 6 4 1 1 1 ...
$ pickup_longitude : num -74 -74 -74 -74 -74 ...
$ pickup_latitude : num 40.8 40.7 40.8 40.7 40.8 ...
$ dropoff_longitude : num -74 -74 -74 -74 -74 ...
$ dropoff_latitude : num 40.8 40.7 40.7 40.7 40.8 ...
$ store_and_fwd_flag : Factor w/ 2 levels "N","Y": 1 1 1 1 1 1 1 1 1 1 ...
$ trip_duration : int 455 663 2124 429 435 443 341 1551 255 1274 ...
$ month : Factor w/ 6 levels "1","2","3","4",..: 3 6 1 4 3 1 6 5 5 5 ...
$ wday : Factor w/ 7 levels "Fri","Mon","Sat",..: 2 4 6 7 3 3 1 3 1 6 ...
$ hour : int 17 0 11 19 13 22 22 7 23 22 ...
$ work : Factor w/ 2 levels "FALSE","TRUE": 2 1 2 1 1 1 1 1 1 1 ...
$ jfk_trip : Factor w/ 2 levels "FALSE","TRUE": 1 1 1 1 1 1 1 1 1 1 ...
$ lg_trip : Factor w/ 2 levels "FALSE","TRUE": 1 1 1 1 1 1 1 1 1 1 ...
$ average.temperature: num 45.5 72.5 22 39 46.5 33.5 70.5 60 80 56.5 ...
$ rain : num 25 2 2 2 2 2 2 6 2 2 ...
$ s_fall : num 2 2 2 2 2 2 2 2 2 2 ...
$ s_depth : num 1 1 0.01 1 1 8 1 1 1 1 ...
$ total_distance : num 2009 2513 11061 1779 1615 ...
$ number_of_steps : int 5 6 16 4 5 5 5 17 2 6 ...
$ fastest_speed : num 43.9 27.3 51.9 27.2 41.5 ...
$ left_turns : int 1 2 5 2 2 1 1 4 0 2 ...
$ right_turns : int 1 2 7 1 2 3 3 9 1 2 ...
$ turns : int 1 2 9 1 3 3 2 6 0 3 ...
x = model.matrix(trip_duration~.,train_again) #here train_again is a data frame with no NA's
y = train_again$trip_duration
sum(is.infinite(x)) #gives output as 537
可能的原因是什么?我的原始数据集一定有问题吗?
【问题讨论】:
-
可重现的例子?
-
FWIW
na.omit()不会摆脱Inf值。summary(train_again)? -
@BenBolker 谢谢,明白了。变量fastest_speed 具有无限均值。 na.omit 不会删除 inf 值。