1
$\begingroup$

I want to build a classification model to match customers and products. I have a description of each product, and a description of each customer, and the label : customer *i* buy/did not buy product *j*.

Each sample/row is a pair (customer, product), so Feature 1 is customer's description, Feature 2 is product's description, and the target variable y is: "y = 1 : customer buys product", "y = 0 otherwise". The goal is to predict for new arriving products whether each customer is going to buy them or not.

I want to use Tf-Idf Vectorizer. I don't in which specific step I should fit_transform the descriptions, and how to put together Feature 1 with Feature 2.

  • Should I concatenate the descriptions of each pair (customer, product) and fit_transform only once I have the concatenation?

  • Should I put together 2 columns using ColumnTransformer? If so, is the classifier going to fit correctly the obtained features?

  • Should I transform using a unique vocabulary?

I found here a reference of three possible ways of working with two columns, but I don't see which one fits for my case.

Ps. Until now, I only got to build a similarity pairwise coefficient (using this), but there is no classification, and I know using labelled data can help. In particular, similarity measure gives the same weight to any text coincidence, but some coincidences should be more important than others.

$\endgroup$

1 Answer 1

0
$\begingroup$

One uses a frequency or TFIDF representation in the features when the target directly depends on specific words. For example for spam classification words like "cheap, free, viagra, exclusive..." are direct indicators of the target label.

In your case the target doesn't directly depend on specific words, it depends whether the same words appear in both the customer and product descriptions. This is an indirect relationship and most regular ML algorithms cannot really deal with that. So your design is unlikely to work in my opinion.

Until now, I only got to build a similarity pairwise coefficient (using this), but there is no classification, and I know using labelled data can help. In particular, similarity measure gives the same weight to any text coincidence, but some coincidences should be more important than others.

This makes more sense for your purpose: use only the similarity score as a feature and train a model to predict the label. Technically the model will only learn the optimal threshold to separate the labels, so you can just use linear regression for instance. You could improve this method by calculating different types of similarity measures and provide all of them as features.

Note: if you use TFIDF vectors for measuring similarity, it doesn't give the same weight to every word. However don't expect perfect result: a lot depends on the data itself, are you sure that the customer description gives useful indications about the products they're interested in? For example if a customer description contains the word "computer" it doesn't mean they're interested in every possible type of computer.

$\endgroup$
3
  • $\begingroup$ Thanks ! I have some questions. - I thought that putting together 2 blocks of columns obtained via transformation, and then fitting a classifier, should find some correlation between words that are repeated in both blocks of columns (like "computer" and "white"). Is this a wrong reasoning? - which other similarity measures may I use? - logistic regression more than linear regression, right? - the descriptions are useful, because it is actually a model of "customers looking for consultants", so customers are very precise in their requirements, and consultants' CVs are precise too $\endgroup$
    – sgduran91
    Mar 17, 2021 at 10:51
  • $\begingroup$ @sgduran91 most algorithms don't deal directly with any correlation between features. For example a decision tree model could represent a condition group1_computer=true and group2_computer=true and group1_white=true and group2_white=true, but it cannot represent a more general condition like group1_X=true and group2_X=true and group1_Y=true and group2_Y=true. This means that either you need a huge amount of training data in order to represent all the possible combinations and it will create a model which doesn't generalize much, or the data needs to be preprocessed in a way which ... $\endgroup$
    – Erwan
    Mar 17, 2021 at 15:05
  • $\begingroup$ ... facilitates the job for the model: for example in this case it's simple to have features like "number of words in common between the two groups". About similarity measures: cosine-TFIDF is a standard one, usually the cosine-BM25 works better, and there other simple options like Jaccard, overlap coefficient. Another approach would be to use word embeddings, but that's a bit more complex. $\endgroup$
    – Erwan
    Mar 17, 2021 at 15:10

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.