NMF applied to Wikipedia articles
In the video, you saw NMF applied to transform a toy word-frequency array. Now it's your turn to apply NMF, this time using the tf-idf word-frequency array of Wikipedia articles, given as a csr matrix articles. Here, fit the model and transform the articles. In the next exercise, you'll explore the result.
Bu egzersiz
Unsupervised Learning in Python
kursunun bir parçasıdırEgzersiz talimatları
- Import
NMFfromsklearn.decomposition. - Create an
NMFinstance calledmodelwith6components. - Fit the model to the word count data
articles. - Use the
.transform()method ofmodelto transformarticles, and assign the result tonmf_features. - Print
nmf_featuresto get a first idea what it looks like (.round(2)rounds the entries to 2 decimal places.)
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
# Import NMF
____
# Create an NMF instance: model
model = ____
# Fit the model to articles
____
# Transform the articles: nmf_features
nmf_features = ____
# Print the NMF features
print(nmf_features.round(2))