0
$\begingroup$

The response variable as well as all predictor variables in my dataset are factors. I want to build a model for predicting the response variable. As I understand I have to first encode my predictor variables. I need advise on how to do the same in R.

I tried building knn & Random Forest models, but this is not working as the execution is never getting completed.

"rs" is the response variable and all others are predictor variables. "bt" depends on "td", but others are completely independent.

Below are the structure & head of my dataframe.

> 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 ...
> 

> head(df)
# A tibble: 6 x 10
  rs    bno   bttm  bwtm  bts    tw    td    bwl   
  <fct> <fct> <fct> <fct> <fct>  <fct> <fct> <fct> 
1 0     1     tm 13 tm 7  pl 408 tm 3  b     pl 205
2 4     2     tm 8  tm 7  pl 531 tm 5  f     pl 369
3 0     3     tm 6  tm 3  pl 276 tm 13 f     pl 308
4 2     4     tm 3  tm 5  pl 460 tm 8  b     pl 227
5 2     5     tm 6  tm 5  pl 71  tm 13 b     pl 340
6 2     6     tm 8  tm 4  pl 57  tm 1  f     pl 117
# ... with 2 more variables: bt <fct>, ven <fct>
> 
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.