bitskitten 0.2.1__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {bitskitten-0.2.1 → bitskitten-0.3.0}/PKG-INFO +49 -20
- {bitskitten-0.2.1 → bitskitten-0.3.0}/README.md +48 -19
- {bitskitten-0.2.1 → bitskitten-0.3.0}/__init__.py +5 -1
- {bitskitten-0.2.1 → bitskitten-0.3.0}/bitskitten.egg-info/PKG-INFO +49 -20
- {bitskitten-0.2.1 → bitskitten-0.3.0}/bitskitten.egg-info/SOURCES.txt +5 -0
- {bitskitten-0.2.1 → bitskitten-0.3.0}/classes.py +212 -168
- bitskitten-0.3.0/metrics.py +36 -0
- {bitskitten-0.2.1 → bitskitten-0.3.0}/output.py +28 -19
- {bitskitten-0.2.1 → bitskitten-0.3.0}/pyproject.toml +1 -1
- bitskitten-0.3.0/tests/test_fit_time.py +207 -0
- {bitskitten-0.2.1 → bitskitten-0.3.0}/tests/test_smoke.py +2 -1
- bitskitten-0.3.0/text.py +77 -0
- {bitskitten-0.2.1 → bitskitten-0.3.0}/LICENSE +0 -0
- {bitskitten-0.2.1 → bitskitten-0.3.0}/bitskitten.egg-info/dependency_links.txt +0 -0
- {bitskitten-0.2.1 → bitskitten-0.3.0}/bitskitten.egg-info/requires.txt +0 -0
- {bitskitten-0.2.1 → bitskitten-0.3.0}/bitskitten.egg-info/top_level.txt +0 -0
- {bitskitten-0.2.1 → bitskitten-0.3.0}/input.py +0 -0
- {bitskitten-0.2.1 → bitskitten-0.3.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: bitskitten
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: EDA reports, plots and sklearn-compatible encoders
|
|
5
5
|
Author: Caerno
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -49,7 +49,7 @@ Requires Python ≥ 3.9, numpy, pandas, scikit-learn, matplotlib, seaborn.
|
|
|
49
49
|
|
|
50
50
|
```python
|
|
51
51
|
import pandas as pd
|
|
52
|
-
from bitskitten import informer, informer_print, imperfection, NanFixer, Digitalize
|
|
52
|
+
from bitskitten import informer, informer_print, imperfection, text_imperfection, NanFixer, Digitalize
|
|
53
53
|
|
|
54
54
|
df = pd.concat([train, test]) # test rows have no target -> NaN
|
|
55
55
|
|
|
@@ -65,11 +65,21 @@ imperfection(df) # what is missing and how varied it is
|
|
|
65
65
|
`imperfection` returns a frame sorted by NA share — share of missing values, number of
|
|
66
66
|
unique values, dtype and the values themselves. By default it shows non-numeric columns
|
|
67
67
|
only; `numeric=True` adds the rest, `no_nan=True` keeps only columns that actually have gaps.
|
|
68
|
+
`informer` switches to `describe()` of the target when it has more than `max_classes` distinct
|
|
69
|
+
values (regression).
|
|
70
|
+
|
|
71
|
+
`text_imperfection(texts)` is the same look at a corpus: one row per defect — empty, too short,
|
|
72
|
+
control characters, not NFKC-normalized, URL, HTML tag, base64-like run, repeated character or
|
|
73
|
+
word, Cyrillic and Latin mixed inside a word, few letters, exact duplicate — with share, count
|
|
74
|
+
and a few offending examples. Rows with zero hits are hidden (`no_clean=False` shows them).
|
|
68
75
|
|
|
69
76
|
## Encoders
|
|
70
77
|
|
|
71
|
-
Both are `
|
|
72
|
-
|
|
78
|
+
Both are `TransformerMixin` + `BaseEstimator` and pass `check_estimator`: statistics are
|
|
79
|
+
learned at `fit` and applied at `transform`, so the test set never leaks into its own filling,
|
|
80
|
+
a batch that lacks a category still comes out with the same columns, `get_feature_names_out`,
|
|
81
|
+
`set_output(transform="pandas")`, `check_is_fitted`, `clone` and grid search all work.
|
|
82
|
+
A frame in gives a frame out; an array in gives an array out (or a frame with `set_output`).
|
|
73
83
|
|
|
74
84
|
```python
|
|
75
85
|
from sklearn.pipeline import Pipeline
|
|
@@ -90,27 +100,30 @@ grid = GridSearchCV(pipe, {
|
|
|
90
100
|
})
|
|
91
101
|
```
|
|
92
102
|
|
|
93
|
-
**`NanFixer(lim=0.225, method="mean", filler="U")`** — picks a filling
|
|
94
|
-
at `fit` time
|
|
103
|
+
**`NanFixer(lim=0.225, method="mean", filler="U", random_state=None)`** — picks a filling
|
|
104
|
+
strategy per column at `fit` time, measures it on the fit data, applies it at `transform`:
|
|
95
105
|
|
|
96
|
-
| column | condition |
|
|
106
|
+
| column | condition (on the fit data) | fill |
|
|
97
107
|
|---|---|---|
|
|
98
|
-
| numeric | NA share ≤ `lim` | `method` (`mean`/`median`) |
|
|
99
|
-
| numeric | NA share > `lim` |
|
|
100
|
-
| object | one value dominates (>25%) | mode |
|
|
108
|
+
| numeric | NA share ≤ `lim` | `method` (`mean`/`median`) of the fit data |
|
|
109
|
+
| numeric | NA share > `lim` | draws from N(mean, std) of the fit data, clipped to its range |
|
|
110
|
+
| object | one value dominates (>25%) | that mode |
|
|
101
111
|
| object | otherwise | the `filler` string |
|
|
102
112
|
|
|
103
|
-
Columns of any other dtype pass through untouched.
|
|
113
|
+
Columns of any other dtype pass through untouched. The plan is in `plan_` after `fit`.
|
|
104
114
|
|
|
105
115
|
**`Digitalize(alim=10, mode="raw", ncut=5)`** — turns a mixed frame into a numeric one:
|
|
106
116
|
|
|
107
|
-
| column | condition | result |
|
|
117
|
+
| column | condition (on the fit data) | result |
|
|
108
118
|
|---|---|---|
|
|
109
119
|
| numeric | < 3 unique values | as is |
|
|
110
|
-
| any | < `alim` unique values | one-hot
|
|
111
|
-
| numeric | `mode="cut"` / `"qcut"` |
|
|
120
|
+
| any | < `alim` unique values | one-hot over the categories seen at fit: `col_value`; an unseen value → all zeros |
|
|
121
|
+
| numeric | `mode="cut"` / `"qcut"` | `col_cut5` / `col_qcut5`: `ncut` equal-spaced / equal-sized bins with edges from the fit data; out-of-range values go to the edge bins |
|
|
112
122
|
| numeric | `mode="raw"` | as is |
|
|
113
|
-
| non-numeric | ≥ `alim` unique values |
|
|
123
|
+
| non-numeric | ≥ `alim` unique values | `col_top5`: frequency rank from the fit data (most frequent → 1, the tail and unseen values → `ncut`) |
|
|
124
|
+
|
|
125
|
+
Output column names are `get_feature_names_out()`; up to 0.2 they were `pd.get_dummies`
|
|
126
|
+
prefixes (`col[:5]_value`) and depended on the batch.
|
|
114
127
|
|
|
115
128
|
**`FeatureTrans(series)`** is the shared kit both encoders are built from, and it is
|
|
116
129
|
iterable: it yields every transformation that makes sense for that column's dtype —
|
|
@@ -124,6 +137,21 @@ candidates = pd.concat(list(FeatureTrans(df["Fare"])), axis=1)
|
|
|
124
137
|
Its pieces are static methods you can also call directly: `count`, `freq`, `top`,
|
|
125
138
|
`cut`, `qcut`, `math`, `bilabel`, `fuzzy_mean`, `robust`, `fill`.
|
|
126
139
|
|
|
140
|
+
## Metric
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
from bitskitten import harmonic_score, harmonic_scorer
|
|
144
|
+
|
|
145
|
+
harmonic_score(y_true, y_pred) # 1.0 perfect, 0.0 if any class is lost
|
|
146
|
+
cross_val_score(clf, X, y, scoring=harmonic_scorer)
|
|
147
|
+
GridSearchCV(pipe, grid, scoring=harmonic_scorer)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
`harmonic_score` is the harmonic mean of every per-class precision and every per-class
|
|
151
|
+
recall — a class-agnostic generalization of F1 for when no class is "the positive one".
|
|
152
|
+
A class that is never predicted or never recovered pulls it to 0. `harmonic_from_confusion(conf)`
|
|
153
|
+
returns `(score, precision[], recall[])` from a ready confusion matrix.
|
|
154
|
+
|
|
127
155
|
## Plots
|
|
128
156
|
|
|
129
157
|
```python
|
|
@@ -133,10 +161,8 @@ hm, precision, recall = plot_conf_map(confusion_matrix(y_true, y_pred), title="R
|
|
|
133
161
|
```
|
|
134
162
|
|
|
135
163
|
`plot_conf_map` draws the confusion matrix as shares, with a precision row, a recall
|
|
136
|
-
column and — in the corner —
|
|
137
|
-
|
|
138
|
-
Returns `(harmonic_mean, precision, recall)`; `blind=True` computes without drawing,
|
|
139
|
-
which is what you want inside a scoring loop.
|
|
164
|
+
column and — in the corner — `harmonic_score`. Returns `(harmonic_mean, precision, recall)`;
|
|
165
|
+
`blind=True` computes without drawing.
|
|
140
166
|
|
|
141
167
|
`plot_some_scatters(X, y)` — pairwise scatter plots of every column combination, coloured by `y`.
|
|
142
168
|
|
|
@@ -186,8 +212,11 @@ pip install -e .[test]
|
|
|
186
212
|
pytest
|
|
187
213
|
```
|
|
188
214
|
|
|
215
|
+
The repo root *is* the package (flat layout), so the clone has to be in a folder named
|
|
216
|
+
`bitskitten` for `pytest` to import it; CI installs the wheel first for the same reason.
|
|
217
|
+
|
|
189
218
|
The drop-in zip in `download/` is a plain stdlib call, no notebook needed:
|
|
190
219
|
|
|
191
220
|
```bash
|
|
192
|
-
python -m zipfile -c download/bitskitten.zip __init__.py classes.py input.py output.py
|
|
221
|
+
python -m zipfile -c download/bitskitten.zip __init__.py classes.py input.py metrics.py output.py text.py
|
|
193
222
|
```
|
|
@@ -28,7 +28,7 @@ Requires Python ≥ 3.9, numpy, pandas, scikit-learn, matplotlib, seaborn.
|
|
|
28
28
|
|
|
29
29
|
```python
|
|
30
30
|
import pandas as pd
|
|
31
|
-
from bitskitten import informer, informer_print, imperfection, NanFixer, Digitalize
|
|
31
|
+
from bitskitten import informer, informer_print, imperfection, text_imperfection, NanFixer, Digitalize
|
|
32
32
|
|
|
33
33
|
df = pd.concat([train, test]) # test rows have no target -> NaN
|
|
34
34
|
|
|
@@ -44,11 +44,21 @@ imperfection(df) # what is missing and how varied it is
|
|
|
44
44
|
`imperfection` returns a frame sorted by NA share — share of missing values, number of
|
|
45
45
|
unique values, dtype and the values themselves. By default it shows non-numeric columns
|
|
46
46
|
only; `numeric=True` adds the rest, `no_nan=True` keeps only columns that actually have gaps.
|
|
47
|
+
`informer` switches to `describe()` of the target when it has more than `max_classes` distinct
|
|
48
|
+
values (regression).
|
|
49
|
+
|
|
50
|
+
`text_imperfection(texts)` is the same look at a corpus: one row per defect — empty, too short,
|
|
51
|
+
control characters, not NFKC-normalized, URL, HTML tag, base64-like run, repeated character or
|
|
52
|
+
word, Cyrillic and Latin mixed inside a word, few letters, exact duplicate — with share, count
|
|
53
|
+
and a few offending examples. Rows with zero hits are hidden (`no_clean=False` shows them).
|
|
47
54
|
|
|
48
55
|
## Encoders
|
|
49
56
|
|
|
50
|
-
Both are `
|
|
51
|
-
|
|
57
|
+
Both are `TransformerMixin` + `BaseEstimator` and pass `check_estimator`: statistics are
|
|
58
|
+
learned at `fit` and applied at `transform`, so the test set never leaks into its own filling,
|
|
59
|
+
a batch that lacks a category still comes out with the same columns, `get_feature_names_out`,
|
|
60
|
+
`set_output(transform="pandas")`, `check_is_fitted`, `clone` and grid search all work.
|
|
61
|
+
A frame in gives a frame out; an array in gives an array out (or a frame with `set_output`).
|
|
52
62
|
|
|
53
63
|
```python
|
|
54
64
|
from sklearn.pipeline import Pipeline
|
|
@@ -69,27 +79,30 @@ grid = GridSearchCV(pipe, {
|
|
|
69
79
|
})
|
|
70
80
|
```
|
|
71
81
|
|
|
72
|
-
**`NanFixer(lim=0.225, method="mean", filler="U")`** — picks a filling
|
|
73
|
-
at `fit` time
|
|
82
|
+
**`NanFixer(lim=0.225, method="mean", filler="U", random_state=None)`** — picks a filling
|
|
83
|
+
strategy per column at `fit` time, measures it on the fit data, applies it at `transform`:
|
|
74
84
|
|
|
75
|
-
| column | condition |
|
|
85
|
+
| column | condition (on the fit data) | fill |
|
|
76
86
|
|---|---|---|
|
|
77
|
-
| numeric | NA share ≤ `lim` | `method` (`mean`/`median`) |
|
|
78
|
-
| numeric | NA share > `lim` |
|
|
79
|
-
| object | one value dominates (>25%) | mode |
|
|
87
|
+
| numeric | NA share ≤ `lim` | `method` (`mean`/`median`) of the fit data |
|
|
88
|
+
| numeric | NA share > `lim` | draws from N(mean, std) of the fit data, clipped to its range |
|
|
89
|
+
| object | one value dominates (>25%) | that mode |
|
|
80
90
|
| object | otherwise | the `filler` string |
|
|
81
91
|
|
|
82
|
-
Columns of any other dtype pass through untouched.
|
|
92
|
+
Columns of any other dtype pass through untouched. The plan is in `plan_` after `fit`.
|
|
83
93
|
|
|
84
94
|
**`Digitalize(alim=10, mode="raw", ncut=5)`** — turns a mixed frame into a numeric one:
|
|
85
95
|
|
|
86
|
-
| column | condition | result |
|
|
96
|
+
| column | condition (on the fit data) | result |
|
|
87
97
|
|---|---|---|
|
|
88
98
|
| numeric | < 3 unique values | as is |
|
|
89
|
-
| any | < `alim` unique values | one-hot
|
|
90
|
-
| numeric | `mode="cut"` / `"qcut"` |
|
|
99
|
+
| any | < `alim` unique values | one-hot over the categories seen at fit: `col_value`; an unseen value → all zeros |
|
|
100
|
+
| numeric | `mode="cut"` / `"qcut"` | `col_cut5` / `col_qcut5`: `ncut` equal-spaced / equal-sized bins with edges from the fit data; out-of-range values go to the edge bins |
|
|
91
101
|
| numeric | `mode="raw"` | as is |
|
|
92
|
-
| non-numeric | ≥ `alim` unique values |
|
|
102
|
+
| non-numeric | ≥ `alim` unique values | `col_top5`: frequency rank from the fit data (most frequent → 1, the tail and unseen values → `ncut`) |
|
|
103
|
+
|
|
104
|
+
Output column names are `get_feature_names_out()`; up to 0.2 they were `pd.get_dummies`
|
|
105
|
+
prefixes (`col[:5]_value`) and depended on the batch.
|
|
93
106
|
|
|
94
107
|
**`FeatureTrans(series)`** is the shared kit both encoders are built from, and it is
|
|
95
108
|
iterable: it yields every transformation that makes sense for that column's dtype —
|
|
@@ -103,6 +116,21 @@ candidates = pd.concat(list(FeatureTrans(df["Fare"])), axis=1)
|
|
|
103
116
|
Its pieces are static methods you can also call directly: `count`, `freq`, `top`,
|
|
104
117
|
`cut`, `qcut`, `math`, `bilabel`, `fuzzy_mean`, `robust`, `fill`.
|
|
105
118
|
|
|
119
|
+
## Metric
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
from bitskitten import harmonic_score, harmonic_scorer
|
|
123
|
+
|
|
124
|
+
harmonic_score(y_true, y_pred) # 1.0 perfect, 0.0 if any class is lost
|
|
125
|
+
cross_val_score(clf, X, y, scoring=harmonic_scorer)
|
|
126
|
+
GridSearchCV(pipe, grid, scoring=harmonic_scorer)
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
`harmonic_score` is the harmonic mean of every per-class precision and every per-class
|
|
130
|
+
recall — a class-agnostic generalization of F1 for when no class is "the positive one".
|
|
131
|
+
A class that is never predicted or never recovered pulls it to 0. `harmonic_from_confusion(conf)`
|
|
132
|
+
returns `(score, precision[], recall[])` from a ready confusion matrix.
|
|
133
|
+
|
|
106
134
|
## Plots
|
|
107
135
|
|
|
108
136
|
```python
|
|
@@ -112,10 +140,8 @@ hm, precision, recall = plot_conf_map(confusion_matrix(y_true, y_pred), title="R
|
|
|
112
140
|
```
|
|
113
141
|
|
|
114
142
|
`plot_conf_map` draws the confusion matrix as shares, with a precision row, a recall
|
|
115
|
-
column and — in the corner —
|
|
116
|
-
|
|
117
|
-
Returns `(harmonic_mean, precision, recall)`; `blind=True` computes without drawing,
|
|
118
|
-
which is what you want inside a scoring loop.
|
|
143
|
+
column and — in the corner — `harmonic_score`. Returns `(harmonic_mean, precision, recall)`;
|
|
144
|
+
`blind=True` computes without drawing.
|
|
119
145
|
|
|
120
146
|
`plot_some_scatters(X, y)` — pairwise scatter plots of every column combination, coloured by `y`.
|
|
121
147
|
|
|
@@ -165,8 +191,11 @@ pip install -e .[test]
|
|
|
165
191
|
pytest
|
|
166
192
|
```
|
|
167
193
|
|
|
194
|
+
The repo root *is* the package (flat layout), so the clone has to be in a folder named
|
|
195
|
+
`bitskitten` for `pytest` to import it; CI installs the wheel first for the same reason.
|
|
196
|
+
|
|
168
197
|
The drop-in zip in `download/` is a plain stdlib call, no notebook needed:
|
|
169
198
|
|
|
170
199
|
```bash
|
|
171
|
-
python -m zipfile -c download/bitskitten.zip __init__.py classes.py input.py output.py
|
|
200
|
+
python -m zipfile -c download/bitskitten.zip __init__.py classes.py input.py metrics.py output.py text.py
|
|
172
201
|
```
|
|
@@ -6,10 +6,12 @@ Submodules stay importable on their own (`from bitskitten import output`),
|
|
|
6
6
|
which is also how the zipped drop-in build is used: `from classes import NanFixer`.
|
|
7
7
|
'''
|
|
8
8
|
|
|
9
|
-
__version__ = "0.
|
|
9
|
+
__version__ = "0.3.0"
|
|
10
10
|
|
|
11
11
|
from .classes import Digitalize, Encoder, FeatureTrans, NanFixer, SlowPolyLinearReg
|
|
12
12
|
from .input import number
|
|
13
|
+
from .metrics import harmonic_from_confusion, harmonic_score, harmonic_scorer
|
|
14
|
+
from .text import text_imperfection
|
|
13
15
|
from .output import (
|
|
14
16
|
imperfection,
|
|
15
17
|
img_framaker,
|
|
@@ -24,6 +26,8 @@ from .output import (
|
|
|
24
26
|
__all__ = [
|
|
25
27
|
"Digitalize", "Encoder", "FeatureTrans", "NanFixer", "SlowPolyLinearReg",
|
|
26
28
|
"number",
|
|
29
|
+
"harmonic_from_confusion", "harmonic_score", "harmonic_scorer",
|
|
30
|
+
"text_imperfection",
|
|
27
31
|
"imperfection", "informer", "informer_print", "multicolumn",
|
|
28
32
|
"plot_conf_map", "plot_some_scatters", "img_squeeze", "img_framaker",
|
|
29
33
|
]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: bitskitten
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: EDA reports, plots and sklearn-compatible encoders
|
|
5
5
|
Author: Caerno
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -49,7 +49,7 @@ Requires Python ≥ 3.9, numpy, pandas, scikit-learn, matplotlib, seaborn.
|
|
|
49
49
|
|
|
50
50
|
```python
|
|
51
51
|
import pandas as pd
|
|
52
|
-
from bitskitten import informer, informer_print, imperfection, NanFixer, Digitalize
|
|
52
|
+
from bitskitten import informer, informer_print, imperfection, text_imperfection, NanFixer, Digitalize
|
|
53
53
|
|
|
54
54
|
df = pd.concat([train, test]) # test rows have no target -> NaN
|
|
55
55
|
|
|
@@ -65,11 +65,21 @@ imperfection(df) # what is missing and how varied it is
|
|
|
65
65
|
`imperfection` returns a frame sorted by NA share — share of missing values, number of
|
|
66
66
|
unique values, dtype and the values themselves. By default it shows non-numeric columns
|
|
67
67
|
only; `numeric=True` adds the rest, `no_nan=True` keeps only columns that actually have gaps.
|
|
68
|
+
`informer` switches to `describe()` of the target when it has more than `max_classes` distinct
|
|
69
|
+
values (regression).
|
|
70
|
+
|
|
71
|
+
`text_imperfection(texts)` is the same look at a corpus: one row per defect — empty, too short,
|
|
72
|
+
control characters, not NFKC-normalized, URL, HTML tag, base64-like run, repeated character or
|
|
73
|
+
word, Cyrillic and Latin mixed inside a word, few letters, exact duplicate — with share, count
|
|
74
|
+
and a few offending examples. Rows with zero hits are hidden (`no_clean=False` shows them).
|
|
68
75
|
|
|
69
76
|
## Encoders
|
|
70
77
|
|
|
71
|
-
Both are `
|
|
72
|
-
|
|
78
|
+
Both are `TransformerMixin` + `BaseEstimator` and pass `check_estimator`: statistics are
|
|
79
|
+
learned at `fit` and applied at `transform`, so the test set never leaks into its own filling,
|
|
80
|
+
a batch that lacks a category still comes out with the same columns, `get_feature_names_out`,
|
|
81
|
+
`set_output(transform="pandas")`, `check_is_fitted`, `clone` and grid search all work.
|
|
82
|
+
A frame in gives a frame out; an array in gives an array out (or a frame with `set_output`).
|
|
73
83
|
|
|
74
84
|
```python
|
|
75
85
|
from sklearn.pipeline import Pipeline
|
|
@@ -90,27 +100,30 @@ grid = GridSearchCV(pipe, {
|
|
|
90
100
|
})
|
|
91
101
|
```
|
|
92
102
|
|
|
93
|
-
**`NanFixer(lim=0.225, method="mean", filler="U")`** — picks a filling
|
|
94
|
-
at `fit` time
|
|
103
|
+
**`NanFixer(lim=0.225, method="mean", filler="U", random_state=None)`** — picks a filling
|
|
104
|
+
strategy per column at `fit` time, measures it on the fit data, applies it at `transform`:
|
|
95
105
|
|
|
96
|
-
| column | condition |
|
|
106
|
+
| column | condition (on the fit data) | fill |
|
|
97
107
|
|---|---|---|
|
|
98
|
-
| numeric | NA share ≤ `lim` | `method` (`mean`/`median`) |
|
|
99
|
-
| numeric | NA share > `lim` |
|
|
100
|
-
| object | one value dominates (>25%) | mode |
|
|
108
|
+
| numeric | NA share ≤ `lim` | `method` (`mean`/`median`) of the fit data |
|
|
109
|
+
| numeric | NA share > `lim` | draws from N(mean, std) of the fit data, clipped to its range |
|
|
110
|
+
| object | one value dominates (>25%) | that mode |
|
|
101
111
|
| object | otherwise | the `filler` string |
|
|
102
112
|
|
|
103
|
-
Columns of any other dtype pass through untouched.
|
|
113
|
+
Columns of any other dtype pass through untouched. The plan is in `plan_` after `fit`.
|
|
104
114
|
|
|
105
115
|
**`Digitalize(alim=10, mode="raw", ncut=5)`** — turns a mixed frame into a numeric one:
|
|
106
116
|
|
|
107
|
-
| column | condition | result |
|
|
117
|
+
| column | condition (on the fit data) | result |
|
|
108
118
|
|---|---|---|
|
|
109
119
|
| numeric | < 3 unique values | as is |
|
|
110
|
-
| any | < `alim` unique values | one-hot
|
|
111
|
-
| numeric | `mode="cut"` / `"qcut"` |
|
|
120
|
+
| any | < `alim` unique values | one-hot over the categories seen at fit: `col_value`; an unseen value → all zeros |
|
|
121
|
+
| numeric | `mode="cut"` / `"qcut"` | `col_cut5` / `col_qcut5`: `ncut` equal-spaced / equal-sized bins with edges from the fit data; out-of-range values go to the edge bins |
|
|
112
122
|
| numeric | `mode="raw"` | as is |
|
|
113
|
-
| non-numeric | ≥ `alim` unique values |
|
|
123
|
+
| non-numeric | ≥ `alim` unique values | `col_top5`: frequency rank from the fit data (most frequent → 1, the tail and unseen values → `ncut`) |
|
|
124
|
+
|
|
125
|
+
Output column names are `get_feature_names_out()`; up to 0.2 they were `pd.get_dummies`
|
|
126
|
+
prefixes (`col[:5]_value`) and depended on the batch.
|
|
114
127
|
|
|
115
128
|
**`FeatureTrans(series)`** is the shared kit both encoders are built from, and it is
|
|
116
129
|
iterable: it yields every transformation that makes sense for that column's dtype —
|
|
@@ -124,6 +137,21 @@ candidates = pd.concat(list(FeatureTrans(df["Fare"])), axis=1)
|
|
|
124
137
|
Its pieces are static methods you can also call directly: `count`, `freq`, `top`,
|
|
125
138
|
`cut`, `qcut`, `math`, `bilabel`, `fuzzy_mean`, `robust`, `fill`.
|
|
126
139
|
|
|
140
|
+
## Metric
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
from bitskitten import harmonic_score, harmonic_scorer
|
|
144
|
+
|
|
145
|
+
harmonic_score(y_true, y_pred) # 1.0 perfect, 0.0 if any class is lost
|
|
146
|
+
cross_val_score(clf, X, y, scoring=harmonic_scorer)
|
|
147
|
+
GridSearchCV(pipe, grid, scoring=harmonic_scorer)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
`harmonic_score` is the harmonic mean of every per-class precision and every per-class
|
|
151
|
+
recall — a class-agnostic generalization of F1 for when no class is "the positive one".
|
|
152
|
+
A class that is never predicted or never recovered pulls it to 0. `harmonic_from_confusion(conf)`
|
|
153
|
+
returns `(score, precision[], recall[])` from a ready confusion matrix.
|
|
154
|
+
|
|
127
155
|
## Plots
|
|
128
156
|
|
|
129
157
|
```python
|
|
@@ -133,10 +161,8 @@ hm, precision, recall = plot_conf_map(confusion_matrix(y_true, y_pred), title="R
|
|
|
133
161
|
```
|
|
134
162
|
|
|
135
163
|
`plot_conf_map` draws the confusion matrix as shares, with a precision row, a recall
|
|
136
|
-
column and — in the corner —
|
|
137
|
-
|
|
138
|
-
Returns `(harmonic_mean, precision, recall)`; `blind=True` computes without drawing,
|
|
139
|
-
which is what you want inside a scoring loop.
|
|
164
|
+
column and — in the corner — `harmonic_score`. Returns `(harmonic_mean, precision, recall)`;
|
|
165
|
+
`blind=True` computes without drawing.
|
|
140
166
|
|
|
141
167
|
`plot_some_scatters(X, y)` — pairwise scatter plots of every column combination, coloured by `y`.
|
|
142
168
|
|
|
@@ -186,8 +212,11 @@ pip install -e .[test]
|
|
|
186
212
|
pytest
|
|
187
213
|
```
|
|
188
214
|
|
|
215
|
+
The repo root *is* the package (flat layout), so the clone has to be in a folder named
|
|
216
|
+
`bitskitten` for `pytest` to import it; CI installs the wheel first for the same reason.
|
|
217
|
+
|
|
189
218
|
The drop-in zip in `download/` is a plain stdlib call, no notebook needed:
|
|
190
219
|
|
|
191
220
|
```bash
|
|
192
|
-
python -m zipfile -c download/bitskitten.zip __init__.py classes.py input.py output.py
|
|
221
|
+
python -m zipfile -c download/bitskitten.zip __init__.py classes.py input.py metrics.py output.py text.py
|
|
193
222
|
```
|
|
@@ -3,15 +3,20 @@ README.md
|
|
|
3
3
|
__init__.py
|
|
4
4
|
classes.py
|
|
5
5
|
input.py
|
|
6
|
+
metrics.py
|
|
6
7
|
output.py
|
|
7
8
|
pyproject.toml
|
|
9
|
+
text.py
|
|
8
10
|
./__init__.py
|
|
9
11
|
./classes.py
|
|
10
12
|
./input.py
|
|
13
|
+
./metrics.py
|
|
11
14
|
./output.py
|
|
15
|
+
./text.py
|
|
12
16
|
bitskitten.egg-info/PKG-INFO
|
|
13
17
|
bitskitten.egg-info/SOURCES.txt
|
|
14
18
|
bitskitten.egg-info/dependency_links.txt
|
|
15
19
|
bitskitten.egg-info/requires.txt
|
|
16
20
|
bitskitten.egg-info/top_level.txt
|
|
21
|
+
tests/test_fit_time.py
|
|
17
22
|
tests/test_smoke.py
|