Unsupervised Learning in Python
Benjamin Wilson
Director of Research at lateral.io
print(articles.shape)
(20000, 800)
from sklearn.decomposition import NMF
nmf = NMF(n_components=10)
nmf.fit(articles)
NMF(n_components=10)
print(nmf.components_.shape)
(10, 800)
print(sample)
[ 0. 1. 0.5 1. 0. 1. ]
bitmap = sample.reshape((2, 3))
print(bitmap)
[[ 0. 1. 0.5]
[ 1. 0. 1. ]]
from matplotlib import pyplot as plt
plt.imshow(bitmap, cmap='gray', interpolation='nearest')
plt.show()
Unsupervised Learning in Python