我的数据集中的响应变量以及所有预测变量都是因素。我想建立一个预测响应变量的模型。据我了解,我必须先对预测变量进行编码。我需要有关如何在R中执行相同操作的建议。
我曾尝试构建knn和Random Forest模型,但这无法正常工作,因为执行从未完成。
“ rs”是响应变量,所有其他都是预测变量。 “ bt”取决于“ td”,但其他完全独立。
下面是我的数据框的结构。
> str(df)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 17520 obs. of 10 variables:
$ rs : Factor w/ 8 levels "0","1","2","3",..: 1 5 1 3 3 3 2 1 5 8 ...
$ bno : Factor w/ 135 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
$ bttm: Factor w/ 13 levels "tm 1","tm 10",..: 5 12 10 7 10 12 1 13 7 6 ...
$ bwtm: Factor w/ 13 levels "tm 1","tm 10",..: 11 11 7 9 9 8 12 11 4 9 ...
$ bts : Factor w/ 348 levels "pl 100","pl 101",..: 207 295 114 246 328 318 312 14 147 118 ...
$ tw : Factor w/ 13 levels "tm 1","tm 10",..: 7 9 5 12 5 1 11 8 9 7 ...
$ td : Factor w/ 2 levels "b","f": 1 2 2 1 1 2 1 2 1 2 ...
$ bwl : Factor w/ 282 levels "pl 10","pl 106",..: 60 160 123 71 139 9 109 229 6 148 ...
$ bt : Factor w/ 2 levels "1","2": 1 2 1 2 1 2 1 2 1 2 ...
$ ven : Factor w/ 41 levels "v 1","v 10","v 11",..: 6 21 35 26 34 13 23 10 17 25 ...
>
我想知道我将采用的方法并进行编码以对预测变量进行编码。
我的数据集中的响应变量以及所有预测变量都是因素。我想建立一个预测响应变量的模型。据我了解,我必须先对预测变量进行编码...
如果使用的是基于树的方法,则无需对变量进行编码。