<metaproperty="og:description" content="Scikit-learn handles four kinds of data for X as used in fit(X, y), fit(X), fit_transform(X) and transform(X) as well as Xt as returned by transform(X) and fit_transform(X): array-like objects In f..." />
<metaname="description" content="Scikit-learn handles four kinds of data for X as used in fit(X, y), fit(X), fit_transform(X) and transform(X) as well as Xt as returned by transform(X) and fit_transform(X): array-like objects In f..." />
<title>13. Data Interoperability — scikit-learn 1.10.dev0 documentation</title>
<liclass="toctree-l1 has-children"><aclass="reference internal" href="model_selection.html">3. Model selection and evaluation</a><details><summary><spanclass="toctree-toggle" role="presentation"><iclass="fa-solid fa-chevron-down"></i></span></summary><ul>
<liclass="toctree-l2"><aclass="reference internal" href="modules/grid_search.html">3.2. Tuning the hyper-parameters of an estimator</a></li>
<liclass="toctree-l2"><aclass="reference internal" href="modules/classification_threshold.html">3.3. Tuning the decision threshold for class prediction</a></li>
<liclass="toctree-l2"><aclass="reference internal" href="modules/model_evaluation.html">3.4. Metrics and scoring: quantifying the quality of predictions</a></li>
<liclass="toctree-l2"><aclass="reference internal" href="modules/learning_curve.html">3.5. Validation curves: plotting scores to evaluate models</a></li>
<liclass="toctree-l2"><aclass="reference internal" href="computing/parallelism.html">10.3. Parallelism and resource management</a></li>
</ul>
</details></li>
<liclass="toctree-l1"><aclass="reference internal" href="model_persistence.html">11. Model persistence</a></li>
<liclass="toctree-l1"><aclass="reference internal" href="common_pitfalls.html">12. Common pitfalls and recommended practices</a></li>
<liclass="toctree-l1 current active has-children"><aclass="current reference internal" href="#">13. Data Interoperability</a><detailsopen="open"><summary><spanclass="toctree-toggle" role="presentation"><iclass="fa-solid fa-chevron-down"></i></span></summary><ul>
<liclass="toctree-l2"><aclass="reference internal" href="modules/df_output_transform.html">13.1. Pandas/Polars Output for Transformers with <codeclass="docutils literal notranslate"><spanclass="pre">set_output</span></code> API</a></li>
<liclass="toctree-l2"><aclass="reference internal" href="modules/array_api.html">13.2. Array API support (experimental)</a></li>
</ul>
</details></li>
<liclass="toctree-l1"><aclass="reference internal" href="machine_learning_map.html">14. Choosing the right estimator</a></li>
<liclass="toctree-l1"><aclass="reference internal" href="presentations.html">15. External Resources, Videos and Talks</a></li>
<h1><spanclass="section-number">13. </span>Data Interoperability<aclass="headerlink" href="#data-interoperability" title="Link to this heading">#</a></h1>
<p>Scikit-learn handles four kinds of data for <aclass="reference internal" href="glossary.html#term-X"><spanclass="xref std std-term">X</span></a> as used in <codeclass="docutils literal notranslate"><spanclass="pre">fit(X,</span><spanclass="pre">y)</span></code>, <codeclass="docutils literal notranslate"><spanclass="pre">fit(X)</span></code>,
<codeclass="docutils literal notranslate"><spanclass="pre">fit_transform(X)</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">transform(X)</span></code> as well as <aclass="reference internal" href="glossary.html#term-Xt"><spanclass="xref std std-term">Xt</span></a> as returned by
<codeclass="docutils literal notranslate"><spanclass="pre">transform(X)</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">fit_transform(X)</span></code>:</p>
<p>In <codeclass="docutils literal notranslate"><spanclass="pre">fit(X)</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">transform(X)</span></code>, array-like <codeclass="docutils literal notranslate"><spanclass="pre">X</span></code> is converted to a numpy ndarray by
calling <codeclass="docutils literal notranslate"><spanclass="pre">numpy.asarray</span></code> upon them.
The returned <codeclass="docutils literal notranslate"><spanclass="pre">Xt</span></code> of <codeclass="docutils literal notranslate"><spanclass="pre">transform</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">fit_transform</span></code> is also a numpy ndarray or it
is a sparse matrix or sparse array, see next bullet.</p>
</li>
<li><p><aclass="reference internal" href="glossary.html#term-sparse-matrix"><spanclass="xref std std-term">sparse matrices</span></a> and sparse arrays</p>
<p>Many estimators can deal with sparse <codeclass="docutils literal notranslate"><spanclass="pre">X</span></code>, some cannot and will raise an error.
For instance, <aclass="reference internal" href="modules/generated/sklearn.linear_model.LogisticRegression.html#sklearn.linear_model.LogisticRegression" title="sklearn.linear_model.LogisticRegression"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">linear_model.LogisticRegression</span></code></a> can be fit on sparse <codeclass="docutils literal notranslate"><spanclass="pre">X</span></code>,
This also controls whether sparse attributes are sparse matrices or sparse arrays.</p>
</li>
<li><p>tabular data: pandas and polars dataframes</p>
<p>See <aclass="reference internal" href="modules/df_output_transform.html#df-output-transform"><spanclass="std std-ref">Pandas/Polars Output for Transformers with set_output API</span></a>.</p>
</li>
<li><p>Array API compliant arrays</p>
<p>Very importantly, this includes arrays on the GPU, see <aclass="reference internal" href="modules/array_api.html#array-api"><spanclass="std std-ref">Array API support (experimental)</span></a>.</p>
</li>
</ul>
<divclass="toctree-wrapper compound">
<ul>
<liclass="toctree-l1"><aclass="reference internal" href="modules/df_output_transform.html">13.1. Pandas/Polars Output for Transformers with <codeclass="docutils literal notranslate"><spanclass="pre">set_output</span></code> API</a><ul>
<liclass="toctree-l2"><aclass="reference internal" href="modules/df_output_transform.html#propagation-of-feature-names">13.1.1. Propagation of Feature Names</a></li>
<liclass="toctree-l2"><aclass="reference internal" href="modules/df_output_transform.html#introducing-the-set-output-api">13.1.2. Introducing the <codeclass="docutils literal notranslate"><spanclass="pre">set_output</span></code> API</a></li>
</ul>
</li>
<liclass="toctree-l1"><aclass="reference internal" href="modules/array_api.html">13.2. Array API support (experimental)</a><ul>
<liclass="toctree-l2"><aclass="reference internal" href="modules/array_api.html#enabling-array-api-support">13.2.2. Enabling array API support</a></li>
<liclass="toctree-l2"><aclass="reference internal" href="modules/array_api.html#example-usage">13.2.3. Example usage</a></li>
<liclass="toctree-l2"><aclass="reference internal" href="modules/array_api.html#support-for-array-api-compatible-inputs">13.2.4. Support for array API compatible inputs</a></li>
<liclass="toctree-l2"><aclass="reference internal" href="modules/array_api.html#input-and-output-array-type-handling">13.2.5. Input and output array type handling</a></li>
<liclass="toctree-l2"><aclass="reference internal" href="modules/array_api.html#common-estimator-checks-for-developers">13.2.6. Common estimator checks (for developers)</a></li>
<pclass="prev-next-title"><spanclass="section-number">12. </span>Common pitfalls and recommended practices</p>
</div>
</a>
<aclass="right-next"
href="modules/df_output_transform.html"
title="next page">
<divclass="prev-next-info">
<pclass="prev-next-subtitle">next</p>
<pclass="prev-next-title"><spanclass="section-number">13.1. </span>Pandas/Polars Output for Transformers with <codeclass="docutils literal notranslate"><spanclass="pre">set_output</span></code> API</p>