简体   繁体   English

如何使用randomForest处理超过53个因子水平的分类值?

[英]How to handle with categorical values over 53 factor levels using randomForest?

I have a training dataset as you can see below: 我有一个训练数据集,如下所示:

'data.frame':   229907 obs. of  19 variables:
$ categories             : Factor w/ 2061 levels  "","Accessories,Fashion,Shopping,Cosmetics & Beauty Supply,Beauty & Spas",..: 253 1541 1720 1647 38 396 522 1727 482 641 ...
$ city                   : Factor w/ 61 levels "Ahwatukee","Anthem",..: 18 38 38 38 38 38 38 51 31 43 ...
$ latitude               : num  33.3 33.5 33.5 33.5 33.5 ...
$ longitude              : num  -112 -112 -112 -112 -112 ...
$ open                   : Factor w/ 2 levels "False","True": 2 2 2 2 2 2 2 2 2 2 ...
$ review_count.x         : int  26 127 130 26 8 229 453 24 3 126 ...
$ stars.x                : num  4.5 3.5 4 4 4.5 3.5 4 4 2.5 3.5 ...
$ state                  : Factor w/ 4 levels "AZ","CA","CO",..: 1 1 1 1 1 1 1 1 1 1 ...
$ date                   : Factor w/ 2504 levels "2005-03-07","2005-03-08",..: 2031 1649 1936 1936 2001 1936 1936 2312 2056 1874 ...
$ stars.y                : int  5 4 4 5 4 3 5 5 1 4 ...
$ votes_cool             : int  0 0 1 0 0 0 1 1 0 0 ...
$ votes_funny            : int  0 0 1 0 0 0 1 1 1 0 ...
$ votes_useful           : int  0 0 1 0 1 0 2 1 2 0 ...
$ average_stars          : num  5 4.67 4.43 4.43 4.43 4.43 4.43 4.43 2.75 3.65 ...
$ name.y                 : Factor w/ 8323 levels "a","a.","A","A.",..: 3841 6354 7263 7263 7263 7263 7263 7263 5372 6556 ...
$ review_count.y         : int  2 4 7 7 7 7 7 7 4 20 ...
$ Total_votes_cool_user  : int  1 0 4 4 4 4 4 4 0 7 ...
$ Total_votes_funny_user : int  0 0 3 3 3 3 3 3 1 5 ...
$ Total_votes_useful_user: int  2 0 6 6 6 6 6 6 3 32 ...

My goal is to apply the randomForest algorithm, but randomForest only embrace factors till level 53. Any suggestion to solve this? 我的目标是应用randomForest算法,但是randomForest仅包含直到53级的因素。有什么建议可以解决这个问题? I have thought about turning all categorical values into integers, but I think it would not help for thereafter prediction efficiency desired. 我曾考虑过将所有分类值都转换为整数,但我认为这对以后所需的预测效率没有帮助。 Also I have had problems with NA values. 我也有NA值的问题。 I used rfImput for replacing them and I also had the same problems. 我用rfImput替换了它们,但我也遇到了同样的问题。

Thanks, 谢谢,

Many of your "factors" are not really factors at all. 您的许多“因素”根本不是真正的因素。 date is not a factor and should be converted to date. date不是一个因素,应该转换为日期。 name should be a string. name应为字符串。 The only one that probably could be seen as a factor is category but not as it is now. 可能被视为一个因素的唯一categorycategory但现在不是。 You need to parse it and separate all the categories. 您需要解析它并分离所有类别。 A link to help you out (maybe): https://www.stat.berkeley.edu/classes/s133/factors.html . 可能会帮助您的链接: https : //www.stat.berkeley.edu/classes/s133/factors.html userid is not a factor (since possibly each observation has a different value), and so on. userid不是一个因素(因为每个观察值可能都有不同的值),依此类推。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM