hope someone kindly put time here,

my approach is like this: TFIDF -> LDA -> SVM

I am using LDA to extract topics. I want to do topic modelling and use the topics as features to do document classification.

I know that I have to send the feature vector to SVM, but my question is that how can I make this feature vector to send to svm? Is featureValue here is the probability assigned to each word? My question is kind of the step 3 in the below link that I dont know how to do it

svm on lda

but in this link there is no implementation, that is just explanation.

Many thanks for your time:)

  • 1
    $\begingroup$ 1), Ignore the tfidf part, you cannot use tfidf in lda, lda takes only term counts; 2), Feed the document-topic distribution vector that you get from lda, to your svm classifier. They are your feature vector. Simples. $\endgroup$ – Blue482 Aug 4 '17 at 0:24
  • $\begingroup$ @Blue482, May I ask you to leave the comment here datascience.stackexchange.com/questions/21947/apply-svm-on-lda I create this post just with email as guest and had not signed up, so I can not put comment as guest, I mean for commenting there is no option of comment as guest at all even with that email datascience.stackexchange.com/questions/21947/apply-svm-on-lda $\endgroup$ – sariii Aug 4 '17 at 1:26

Following your code in your other thread:

# Use tf (raw term count) features for LDA.
print("Extracting tf features for LDA...")
tf_vectorizer = CountVectorizer(max_df=0.95, min_df=2,
t0 = time()
tf = tf_vectorizer.fit_transform(data_samples)
print("done in %0.3fs." % (time() - t0))

print("Topic modelling with LDA...")
lda = LatentDirichletAllocation(n_topics=n_topics, max_iter=5,

lda_x = lda.fit_transform(tf)
# so lda_x is your doc-topic distribution that you can use for feature vector to your SVM model.
# lda.components_ is your topic-word distribution.

Hope this helps!

| improve this answer | |

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.