Applying a matrix decomposition for classification using a saved W matrix
<p>I'm performing an NMF decomposition on a tf-idf input in order to perform topic analysis. </p>

<pre><code>def decomp(tfidfm, topic_count):
    model = decomposition.NMF(init="nndsvd", n_components=topic_count,     max_iter=500)
    H = model.fit_transform(tfidfm)
    W = model.components_
    return W, H
</code></pre>

<p>This returns <em>W</em>, a model definition consisting of topics to term assignments, and <em>H</em>, a document to topic assignment matrix</p>

<p>So far so good, I can use H to classify documents based on their association via term frequency to a list of topics which in turn are also based on their association to term frequency. </p>

<p>I'd like to save the topic-term-associations to disk so I can reapply them later - and have adopted the method described here [<a href="http://stackoverflow.com/questions/8955448]">http://stackoverflow.com/questions/8955448]</a> to store the sparse-matrix reperesentation of W.</p>

<p>So what I'd like to do now, is perform the same process, only fixing the topic-definition matrix W.</p>

<p>In the documentation, it appears that I can set W in the calling parameters something along the lines of:</p>

<pre><code>def applyModel(tfidfm,W,topic_count):
    model = decomposition.NMF(init="nndsvd", n_components=topic_count, max_iter=500)
    H = model.fit_transform(X=tfidfm, W=W)
    W = model.components_
    return W, H
</code></pre>

<p>And I've tried this, but it doesn't appear to work. </p>

<p>I've tested by compiling a W matrix using a differently sized vocabulary, then feeding that into the <code>applyModel</code> function, the shape of the resulting matrices should be defined (or I should say, that is what I'm intending) by the W model, but this isn't the case. </p>

<p>The short version of this question is: How can I save the topic-model generated from a matrix decomposition, such that I can use it to classify a different document set than the one used to originally generate it?</p>

<p>In other terms, if <strong>V</strong>=<strong>WH</strong>, then how can I return <strong>H</strong>, given <strong>V</strong> and <strong>W</strong>?</p>

<p>The initial equation is: <img src="https://i.stack.imgur.com/Vg05x.gif" alt="initial equation"> and we solve it for <img src="https://i.stack.imgur.com/yuuvq.gif" alt="H"> like this: <img src="https://i.stack.imgur.com/I4jLY.gif" alt="How to solve it for H">.</p>

<p>Here <img src="https://i.stack.imgur.com/ClqEe.gif" alt="inverse of W"> denotes the inverse of the matrix <img src="https://i.stack.imgur.com/ki72B.gif" alt="W">, which exists only if <img src="https://i.stack.imgur.com/ki72B.gif" alt="W"> is nonsingular.</p>

<p>The multiplication order is, as always, important. If you had <img src="https://i.stack.imgur.com/icKMv.gif" alt="if the order is changed">, you'd need to multiply <img src="https://i.stack.imgur.com/lvvsw.gif" alt="V"> by the inverse of <img src="https://i.stack.imgur.com/ki72B.gif" alt="W"> the other way round: <img src="https://i.stack.imgur.com/Z5Mtd.gif" alt="no description">.</p>

python scikit-learn tf-idf matrix-decomposition nmf