'problem with input features for latent dirichlet allocation
I am trying to make predicitions with my LDA model. But when i pass a string to it it gives an error about mismatching input features. Now my question is how can i make my model accept any input and still predict the right topic. Right now it takes 54777 as input.
model:
cv = CountVectorizer(max_df=0.95, min_df=2, stop_words='english')
dtm = cv.fit_transform(npr['Article'])
LDA = LatentDirichletAllocation(n_components=7,random_state=42)
LDA.fit(dtm)
prediction
txt = ["The election of Donald Trump was a surprise to pollsters, pundits and, perhaps most of all, the Democratic Party."]
vectorizer = CountVectorizer()
txt_vectorized = vectorizer.fit_transform(txt)
predict = LDA.transform(txt_vectorized)
print(predict)
error:
ValueError: X has 16 features, but LatentDirichletAllocation is expecting 54777 features as input.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
