3
$\begingroup$

I have data in the following form:

table 1
id, feature1, predict
1, xyz,yes
2, abc, yes

table2
id, feature2
1, class1
1, class2
1, class3
2, class2

I could perform a one many join and train on the resultant set- which is one way to go about it. But If I rather wanted to maintain the length of the resultant set equal length of table 1, what is the technique?

$\endgroup$

1 Answer 1

2
$\begingroup$

One possible approach is to perform an encoding, where each level of the feature2 corresponds to a new feature (column). This way you may describe the 1:N relation between the feature 1 and 2

Here a small example in R

> table1  <- data.frame(id = c(1,2),  feature1 = c("xyz","abc"), predict = c(T,T))
> table2  <- data.frame(id = c(1,1,1,2), feature2 = c("class1", "class2", "class3", "class2"))
> 
> ## encoding
> table(table2)
   feature2
id  class1 class2 class3
  1      1      1      1
  2      0      1      0

The new object contains the (now unique) id and setting of the feature2. You need only to merge (join) the result to the table1 (basically same task a DB join - which variance: inner, outer or full depends on your requirements).

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.