0
$\begingroup$

How can I predict the compatibility of 2 people as a boolean classification problem?

I want to know if below is an appropriate approach to modelling compatibility, or if I should be using "market basket analysis" or some other approach instead?

I'm less interested in the specific result below, and more interested in if this is a realistic way to frame this data science problem.

Background:

Assume people only have 3 attributes: compassion, extroversion and humor. These are also boolean and can be modelled as 1s and 0s in a list ([compassion, extroversion, humor]).

So someone with all 3 characteristics would be [1,1,1] and someone with only humor would be [0,0,1].

We have pairs of people who match and do not match, specified by 1 or 0, where 1=match and 0=no_match.

How to solve this?

I don't consider this a simple distance problem (ie: euclidean distance) because its very possible that generally an introvert and extrovert get along, but 2 extroverts don't.

Data:

person1   person2     match?
--------  --------    ------
([1,1,0], [1,0,1]) => 1
([0,0,0], [1,1,1]) => 1
([1,0,1], [1,0,0]) => 0
([1,1,1], [0,1,0]) => 0
([0,0,0], [0,1,1]) => 1
([1,1,0], [1,1,1]) => 0
([1,0,0], [1,0,1]) => 0
([0,0,1], [0,0,0]) => 0
([0,0,0], [0,0,1]) => 0
([0,0,0], [0,1,1]) => 1
([0,1,0], [0,1,1]) => 0
([0,1,0], [0,1,1]) => 0
([0,1,0], [1,0,0]) => 1

What I've tried:

My first thought was to concatenate both individuals' data for each example. Then use that to fit the model.

Data structured as python code:

X_train = [
    [1,1,0,1,0,1],
    [0,0,0,1,1,1],
    [1,0,1,1,0,0],
    [1,1,1,0,1,0],
    [0,0,0,0,1,1],
    [1,1,0,1,1,1],
    [1,0,0,1,0,1],
    [0,0,1,0,0,0],
    [0,0,0,0,0,1],
    [0,0,0,0,1,1],
    [0,1,0,0,1,1],
    [0,1,0,0,1,1],
    [0,1,0,1,0,0],
]

y_train = [1,1,0,0,1,0,0,0,0,1,0,0,1]

X_test = [
    [0,1,1,0,0,0],
    [1,1,0,1,0,1],
    [1,0,0,1,0,0],
    [0,0,0,1,0,0],
    [0,1,0,0,0,0],
    [0,0,0,0,0,0],    
]

y_test = [1,1,0,0,1,0]

Computing the match:

from sklearn.metrics import classification_report

from sklearn.ensemble import RandomForestClassifier
rf = RandomForestClassifier()
rf.fit(X_train, y_train)
y_pred = rf.predict(X_test)

print(classification_report(y_test,y_pred))

             precision    recall  f1-score   support

          0       0.60      1.00      0.75         3
          1       1.00      0.33      0.50         3

avg / total       0.80      0.67      0.62         6

I'm less concerned about the results here and more interested in if this is a proper way to frame this problem.

Can you offer a suggestion?

$\endgroup$
2
  • 1
    $\begingroup$ I don't understand the question completely - are you asking whether Random Forests are a good choice or do you want to model your data differently? $\endgroup$
    – André
    Sep 26 '18 at 7:49
  • $\begingroup$ @André I want to know if this is an appropriate approach to modelling compatibility, or if I should be using "market basket analysis" or some other approach instead? $\endgroup$
    – tim_xyz
    Sep 26 '18 at 14:30
2
$\begingroup$

Your approach to modeling compatibility seems sound, and definitely makes more sense than market basket analysis. From what I could gather, your goal is to predict compatibility, and you have access to a certain signal that you can use as your compatibility label for the training set (for example, you know for a fact that persons X and Y are compatible but Y and Z are not). In these circumstances, supervised learning definitely sounds appropriate.

Based on the example you gave, there are a few things about this problem that you may consider (if you haven't already):

  • Should the features (e.g. compassion, extroversion, humor) be binary, or on a continuous spectrum? This depends on your data, of course, but perhaps you may get a better measure of compatibility if you can get the finer grain of detail that continuous features provide.
  • Same for the class: is it exclusively binary (classification) or could this be treated as a regression problem (predict the degree of compatibility)? Even if treating it as classification, certain models output class posterior probabilities, which could be interpreted as degrees of compatibility.
  • Compatibility is most likely a symmetrical relationship: if a is compatible with b, then b is compatible with a. If your dataset is formed of the two individuals' data concatenated, should you create two examples per pair (one in each order)? Is there another way to enforce symmetry in your model? Also, can the signal you use for your compatibility label really be interpreted in this symmetrical sense, or does it only tell you that, for instance person A likes person B, but not necessarily the other way around.
  • How will you evaluate your model? If compatibility is more continuous than discrete, for example, then perhaps recall, precision and accuracy aren't the best metrics, and you may want to use something like RMSE?
$\endgroup$

Your Answer

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

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