3
$\begingroup$
  1. I am working on a project for displaying products to customer by context, based on a search query. For example, I don't want customers to have to enter a specific product name, instead searching based on functionality (e.g., "walls do not heat much" would return product names such as "Whirlpool NEO IC355 ROY 3S 340 L Double Door Refrigerator")
  2. I have a training set comprised of the functionality associated products. I am planning to use Logistic Regression to train a model on these data. How do I process this data in Python or extract features to feed into logistic regression? I have heard of "Bag of words model", but not sure how to use this, or is it even applicable here?

I know there are plenty of NLTK libraries available. But, I want to implement it from the scratch or using minimum external libraries possible.

Please help or are there any resources to refer to?

$\endgroup$
1
$\begingroup$

Your problem looks more like a ranking problem than a classification problem to me. Have you tried a more naive method, like a 1-NN "classifier" with unigram text representation, Tf-Idf term weighting and a cosine similarity metric? It's far from the state of the art but it tends to give rather good results in retrieval and recommendation tasks.

| improve this answer | |
$\endgroup$
0
$\begingroup$

For your particular problem I'm not sure that using a supervised Logistic Regression approach is ideal, but I suppose that is a different and larger topic. To answer your question, yes you can use a "bag of words" representation of your text. Python's sci-kit learn library offers this functionality via both CountVectorizer and TfidfVectorizer. This will result in a sparse matrix representation of n-grams and occurrences of those n-grams in your corpus. From here you basically have 2 options, (1) training your supervised model directly on the sparse matrix or (2) reducing the dimension of your sparse matrix so it be represented as a dense matrix. Luckily sklearn offers functionality for both these, their LogisticRegression class supports sparse matrices and their TruncatedSVD implementation of PCA/LSA supports sparse matrices as well.

That should give what you need from a technical perspective to build a model, but I think the real question is what feature engineering you may be able to do in addition to simply training on the bag of words representation of the text.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks for answering. I will try to gain more insight into this $\endgroup$ – ashish chopra Sep 22 '15 at 3:20
0
$\begingroup$

You might train a topic model (like LDA) to approach this problem. This would allow you to represent your queries (which won't necessarily contain the exact name of the products desired) in terms of topic vectors. You can also represent your products in terms of their topic vectors.

You can then rank the products in terms of similarity (in topic vector space) to the query.

| improve this answer | |
$\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.