<p>Since <a href="https://scikit-learn.org/dev/whats_new.html#id36" rel="nofollow noreferrer">version 0.21.0</a>, the <a href="https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.PolynomialFeatures.html#sklearn-preprocessing-polynomialfeatures" rel="nofollow noreferrer">PolynomialFeatures</a> class accepts CSR matrices for degrees 2 and 3. The method laid out <a href="https://arxiv.org/abs/1803.06418" rel="nofollow noreferrer">here</a> is used, and the computation is much, much faster than if the input is a CSC matrix or dense (assuming the data's sparse to any reasonable degree - even slightly).</p>
How to make polynomial features using sparse matrix in Scikit-learn
<p>I am using Scikit-learn for converting my train data to polynomials features and then fit it to a linear model.</p>

<pre><code>model = Pipeline([('poly', PolynomialFeatures(degree=3)),
              ('linear', LinearRegression(fit_intercept=False))])
model.fit(X, y)
</code></pre>

<p>But it throws an error </p>

<pre><code>TypeError: A sparse matrix was passed, but dense data is required
</code></pre>

<p>I know my data is <code>sparse matrix</code> format. So when I try to convert my data to <code>dense matrix</code> it shows <code>memory error</code>. Because my data is huge(50k~). Because of these large amounts of data I can't convert it to a dense matrix. </p>

<p>I also find <a href="https://github.com/scikit-learn/scikit-learn/issues/8376" rel="nofollow noreferrer">Github Issues</a> where this feature is requested. But still not implemented. </p>

<p>So please can someone tell how to use sparse data format in PolynomialFeatures in Scikit-learn without converting it to dense format?</p>