Unsupervised Learning in Python
Benjamin Wilson
Director of Research at lateral.io
fit()
/ transform()
patternNMF(n_components=2)
csr_matrix
samples
is the word-frequency arrayfrom sklearn.decomposition import NMF
model = NMF(n_components=2)
model.fit(samples)
NMF(n_components=2)
nmf_features = model.transform(samples)
print(model.components_)
[[ 0.01 0. 2.13 0.54]
[ 0.99 1.47 0. 0.5 ]]
print(nmf_features)
[[ 0. 0.2 ]
[ 0.19 0. ]
...
[ 0.15 0.12]]
print(samples[i,:])
[ 0.12 0.18 0.32 0.14]
print(nmf_features[i,:])
[ 0.15 0.12]
Unsupervised Learning in Python