No project description provided
Project description
polars-ml
Machine Learning Polars Plugin
Getting Started
Install from Pypi:
pip install polars-ml
Examples
Sparse Namespace
import polars as pl
import polars_ml.sparse as ps
df = pl.DataFrame({
'feature': [
[0, 1, 0, 0, 5, 0],
[2, 0, 0, 0, 3, 4],
[0, 1],
None
]
})
df_sparse = df.with_columns(
ps.from_list(pl.col('feature')).alias('sparse_feature')
)
print(df_sparse)
shape: (4, 2)
┌─────────────┬─────────────────────────┐
│ feature ┆ sparse_feature │
│ --- ┆ --- │
│ list[i64] ┆ struct[3] │
╞═════════════╪═════════════════════════╡
│ [0, 1, … 0] ┆ {6,[1, 4],[1, 5]} │
│ [2, 0, … 4] ┆ {6,[0, 4, 5],[2, 3, 4]} │
│ [0, 1] ┆ {2,[1],[1]} │
│ null ┆ {null,null,null} │
└─────────────┴─────────────────────────┘
df_sparse_norm = df_sparse.select('sparse_feature') \
.with_columns(ps.normalize(pl.col('sparse_feature'), how='vertical', p=2.0).alias('sparse_feature_norm'))
print(df_sparse_norm)
shape: (4, 2)
┌─────────────────────────┬───────────────────────────────────┐
│ sparse_feature ┆ sparse_feature_norm │
│ --- ┆ --- │
│ struct[3] ┆ struct[3] │
╞═════════════════════════╪═══════════════════════════════════╡
│ {6,[1, 4],[1, 5]} ┆ {6,[1, 4],[0.707107, 0.857493]} │
│ {6,[0, 4, 5],[2, 3, 4]} ┆ {6,[0, 4, 5],[1.0, 0.514496, 1.0… │
│ {2,[1],[1]} ┆ {2,[1],[0.707107]} │
│ {null,null,null} ┆ {null,null,null} │
└─────────────────────────┴───────────────────────────────────┘
Credits
- Rust Snowball Stemmer is taken from Tsoding's Seroost project (MIT). See here
- Marco Edward Gorelli - for using his polars plugin tutorial.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distributions
Close
Hashes for polars_ml-0.1.1-cp38-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | abe872dbc0eb3695a2d558d26c1ed8a98d09d1b995fb5edc66b65a6e53afc503 |
|
MD5 | c42f238ab5c988f245b19ca5716fc9fb |
|
BLAKE2b-256 | dbb6f844bb36e768bac13539d3629a46095d9c29b926a29b21299f2296282cc4 |
Close
Hashes for polars_ml-0.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec43310662b4b639e9d9acc9f5492d105657e9575b46bf6648b61637a7f43bd2 |
|
MD5 | e952733292640a9eaadd0a2cedbccf89 |
|
BLAKE2b-256 | 11af8671c181fd1ae10a488c91d4da85a06587883c016b513c35df3acc71b699 |