mixed-imputer 0.1.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.

Potentially problematic release.


This version of mixed-imputer might be problematic. Click here for more details.

@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dnnsqe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,152 @@
1
+ Metadata-Version: 2.4
2
+ Name: mixed-imputer
3
+ Version: 0.1.0
4
+ Summary: Mixed-type MICE imputer for scikit-learn — handles both numerical and categorical (string) columns in DataFrames.
5
+ Author: dnnsqe
6
+ License: MIT
7
+ Project-URL: Repository, https://github.com/dnnsqe/mixed-imputer
8
+ Project-URL: Issues, https://github.com/dnnsqe/mixed-imputer
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Requires-Python: >=3.9
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: numpy
23
+ Requires-Dist: pandas
24
+ Requires-Dist: scipy
25
+ Requires-Dist: scikit-learn>=1.0
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest>=7; extra == "dev"
28
+ Requires-Dist: pytest-cov; extra == "dev"
29
+ Dynamic: license-file
30
+
31
+ # MixedTypeImputer
32
+
33
+ **MixedTypeImputer** is a scikit-learn compatible transformer that performs iterative imputation (MICE) on DataFrames containing both numerical and categorical (string) columns.
34
+
35
+ It automatically detects column types, encodes categoricals with `OrdinalEncoder`, runs an iterative MICE‑style imputer that chooses a regressor or classifier per column, and decodes categoricals back to their original string values.
36
+
37
+ ## Features
38
+
39
+ - **Mixed-type support** — handles numeric and string categorical columns in the same DataFrame
40
+ - **Auto-detection** — automatically identifies categorical columns by dtype (object/category/string)
41
+ - **Iterative imputation (MICE)** — models each column as a function of all others
42
+ - **Posterior sampling** — supports stochastic imputation via `sample_posterior=True`
43
+ - **scikit-learn compatible** — `fit` / `transform` / `fit_transform` API, works in `Pipeline`
44
+ - **DataFrame-native** — input a DataFrame, get a DataFrame back
45
+
46
+ ## Installation
47
+
48
+ ```bash
49
+ pip install mixed-imputer
50
+ ```
51
+
52
+ Or for development:
53
+
54
+ ```bash
55
+ git clone https://github.com/dnnsqe/mixed-imputer.git
56
+ cd mixed-imputer
57
+ pip install -e ".[dev]"
58
+ ```
59
+
60
+ ## Quick Start
61
+
62
+ ```python
63
+ import pandas as pd
64
+ import numpy as np
65
+ from mixed_imputer import MixedTypeImputer
66
+
67
+ # Create sample data with missing values
68
+ data = pd.DataFrame({
69
+ 'age': [25, 30, np.nan, 40],
70
+ 'city': ['paris', 'london', np.nan, 'paris'],
71
+ 'income': [50000, np.nan, 70000, 60000],
72
+ 'gender': ['M', 'F', 'M', np.nan],
73
+ })
74
+
75
+ # Auto-detect categorical columns (str, object, or category dtype)
76
+ # or specify them manually via categorical_features.
77
+ imputer = MixedTypeImputer(
78
+ max_iter=5,
79
+ random_state=42,
80
+ )
81
+
82
+ imputed = imputer.fit_transform(data)
83
+ print(imputed)
84
+ # age city income gender
85
+ # 0 25.000 paris 50000.0 M
86
+ # 1 30.000 london 58750.0 F
87
+ # 2 32.500 london 70000.0 M
88
+ # 3 40.000 paris 60000.0 F
89
+ ```
90
+
91
+ ## Parameters
92
+
93
+ | Parameter | Type | Default | Description |
94
+ |-----------|------|---------|-------------|
95
+ | `categorical_features` | list of int/str or None | `None` | Column indices or names that are categorical. If `None` and input is a DataFrame, columns with `object`, `string`, or `category` dtype are auto-detected. |
96
+ | `numeric_features` | list of int/str or None | `None` | Numeric column indices or names. If `None`, auto-detected as all columns whose dtype passes `pd.api.types.is_numeric_dtype` and are not listed in `categorical_features`. |
97
+ | `regressor` | estimator or None | `HistGradientBoostingRegressor()` | Regressor for numerical target columns. |
98
+ | `classifier` | estimator or None | `HistGradientBoostingClassifier()` | Classifier for categorical target columns. |
99
+ | `max_iter` | int | `10` | Maximum number of imputation rounds. |
100
+ | `tol` | float | `1e-3` | Tolerance for early stopping. |
101
+ | `initial_strategy` | str | `"mean"` | Initial imputation strategy (`"mean"`, `"median"`, `"most_frequent"`, `"constant"`). |
102
+ | `sample_posterior` | bool | `False` | If `True`, sample from predictive posterior for stochastic imputation. |
103
+ | `random_state` | int, RandomState or None | `None` | Seed for reproducibility. |
104
+ | `verbose` | int | `0` | Verbosity level. |
105
+ | `add_indicator` | bool | `False` | If `True`, add missing indicator columns. |
106
+ | `keep_empty_features` | bool | `False` | If `True`, keep features that are all-missing at fit time. |
107
+
108
+ ## How It Works
109
+
110
+ 1. **Column detection** — object/string/category dtype columns are identified as categorical; the rest as numeric.
111
+ 2. **Encoding** — categorical columns are encoded to integers using `OrdinalEncoder`, with NaN replaced by a sentinel value.
112
+ 3. **Iterative imputation** — a modified `IterativeImputer` uses `HistGradientBoostingRegressor` for numeric columns and `HistGradientBoostingClassifier` for categorical columns.
113
+ 4. **Decoding** — imputed integer values are inverse-transformed back to their original string categories.
114
+
115
+ ## Requirements
116
+
117
+ - Python ≥ 3.9
118
+ - numpy
119
+ - pandas
120
+ - scipy
121
+ - scikit-learn ≥ 1.0
122
+
123
+ ## Running Tests
124
+
125
+ ```bash
126
+ pip install -e ".[dev]"
127
+ pytest
128
+ ```
129
+
130
+ ## Examples
131
+
132
+ See [`examples/examples.py`](examples/examples.py) for a runnable script that demonstrates all major
133
+ features including auto-detection, posterior sampling, custom estimators, array
134
+ input, pipeline integration, and edge cases.
135
+
136
+ ## Known Limitations
137
+
138
+ - **Unseen categories at transform time** are encoded to the `unknown_value` of
139
+ the `OrdinalEncoder`. If the imputer assigns a value that decodes to an
140
+ unknown category it will appear as `NaN` in the output. Ensure the training
141
+ set covers the full vocabulary of each categorical column when possible.
142
+ - **`keep_empty_features=False`** (the default) drops columns that are entirely
143
+ `NaN` during `fit`. The dropped columns are removed from the output
144
+ DataFrame.
145
+
146
+ ## License
147
+
148
+ MIT — see [LICENSE](LICENSE) for details.
149
+
150
+ ## Links
151
+
152
+ - [GitHub Repository](https://github.com/dnnsqe/mixed-imputer)
@@ -0,0 +1,122 @@
1
+ # MixedTypeImputer
2
+
3
+ **MixedTypeImputer** is a scikit-learn compatible transformer that performs iterative imputation (MICE) on DataFrames containing both numerical and categorical (string) columns.
4
+
5
+ It automatically detects column types, encodes categoricals with `OrdinalEncoder`, runs an iterative MICE‑style imputer that chooses a regressor or classifier per column, and decodes categoricals back to their original string values.
6
+
7
+ ## Features
8
+
9
+ - **Mixed-type support** — handles numeric and string categorical columns in the same DataFrame
10
+ - **Auto-detection** — automatically identifies categorical columns by dtype (object/category/string)
11
+ - **Iterative imputation (MICE)** — models each column as a function of all others
12
+ - **Posterior sampling** — supports stochastic imputation via `sample_posterior=True`
13
+ - **scikit-learn compatible** — `fit` / `transform` / `fit_transform` API, works in `Pipeline`
14
+ - **DataFrame-native** — input a DataFrame, get a DataFrame back
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ pip install mixed-imputer
20
+ ```
21
+
22
+ Or for development:
23
+
24
+ ```bash
25
+ git clone https://github.com/dnnsqe/mixed-imputer.git
26
+ cd mixed-imputer
27
+ pip install -e ".[dev]"
28
+ ```
29
+
30
+ ## Quick Start
31
+
32
+ ```python
33
+ import pandas as pd
34
+ import numpy as np
35
+ from mixed_imputer import MixedTypeImputer
36
+
37
+ # Create sample data with missing values
38
+ data = pd.DataFrame({
39
+ 'age': [25, 30, np.nan, 40],
40
+ 'city': ['paris', 'london', np.nan, 'paris'],
41
+ 'income': [50000, np.nan, 70000, 60000],
42
+ 'gender': ['M', 'F', 'M', np.nan],
43
+ })
44
+
45
+ # Auto-detect categorical columns (str, object, or category dtype)
46
+ # or specify them manually via categorical_features.
47
+ imputer = MixedTypeImputer(
48
+ max_iter=5,
49
+ random_state=42,
50
+ )
51
+
52
+ imputed = imputer.fit_transform(data)
53
+ print(imputed)
54
+ # age city income gender
55
+ # 0 25.000 paris 50000.0 M
56
+ # 1 30.000 london 58750.0 F
57
+ # 2 32.500 london 70000.0 M
58
+ # 3 40.000 paris 60000.0 F
59
+ ```
60
+
61
+ ## Parameters
62
+
63
+ | Parameter | Type | Default | Description |
64
+ |-----------|------|---------|-------------|
65
+ | `categorical_features` | list of int/str or None | `None` | Column indices or names that are categorical. If `None` and input is a DataFrame, columns with `object`, `string`, or `category` dtype are auto-detected. |
66
+ | `numeric_features` | list of int/str or None | `None` | Numeric column indices or names. If `None`, auto-detected as all columns whose dtype passes `pd.api.types.is_numeric_dtype` and are not listed in `categorical_features`. |
67
+ | `regressor` | estimator or None | `HistGradientBoostingRegressor()` | Regressor for numerical target columns. |
68
+ | `classifier` | estimator or None | `HistGradientBoostingClassifier()` | Classifier for categorical target columns. |
69
+ | `max_iter` | int | `10` | Maximum number of imputation rounds. |
70
+ | `tol` | float | `1e-3` | Tolerance for early stopping. |
71
+ | `initial_strategy` | str | `"mean"` | Initial imputation strategy (`"mean"`, `"median"`, `"most_frequent"`, `"constant"`). |
72
+ | `sample_posterior` | bool | `False` | If `True`, sample from predictive posterior for stochastic imputation. |
73
+ | `random_state` | int, RandomState or None | `None` | Seed for reproducibility. |
74
+ | `verbose` | int | `0` | Verbosity level. |
75
+ | `add_indicator` | bool | `False` | If `True`, add missing indicator columns. |
76
+ | `keep_empty_features` | bool | `False` | If `True`, keep features that are all-missing at fit time. |
77
+
78
+ ## How It Works
79
+
80
+ 1. **Column detection** — object/string/category dtype columns are identified as categorical; the rest as numeric.
81
+ 2. **Encoding** — categorical columns are encoded to integers using `OrdinalEncoder`, with NaN replaced by a sentinel value.
82
+ 3. **Iterative imputation** — a modified `IterativeImputer` uses `HistGradientBoostingRegressor` for numeric columns and `HistGradientBoostingClassifier` for categorical columns.
83
+ 4. **Decoding** — imputed integer values are inverse-transformed back to their original string categories.
84
+
85
+ ## Requirements
86
+
87
+ - Python ≥ 3.9
88
+ - numpy
89
+ - pandas
90
+ - scipy
91
+ - scikit-learn ≥ 1.0
92
+
93
+ ## Running Tests
94
+
95
+ ```bash
96
+ pip install -e ".[dev]"
97
+ pytest
98
+ ```
99
+
100
+ ## Examples
101
+
102
+ See [`examples/examples.py`](examples/examples.py) for a runnable script that demonstrates all major
103
+ features including auto-detection, posterior sampling, custom estimators, array
104
+ input, pipeline integration, and edge cases.
105
+
106
+ ## Known Limitations
107
+
108
+ - **Unseen categories at transform time** are encoded to the `unknown_value` of
109
+ the `OrdinalEncoder`. If the imputer assigns a value that decodes to an
110
+ unknown category it will appear as `NaN` in the output. Ensure the training
111
+ set covers the full vocabulary of each categorical column when possible.
112
+ - **`keep_empty_features=False`** (the default) drops columns that are entirely
113
+ `NaN` during `fit`. The dropped columns are removed from the output
114
+ DataFrame.
115
+
116
+ ## License
117
+
118
+ MIT — see [LICENSE](LICENSE) for details.
119
+
120
+ ## Links
121
+
122
+ - [GitHub Repository](https://github.com/dnnsqe/mixed-imputer)
@@ -0,0 +1,51 @@
1
+ [build-system]
2
+ requires = ["setuptools>=64"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "mixed-imputer"
7
+ version = "0.1.0"
8
+ description = "Mixed-type MICE imputer for scikit-learn — handles both numerical and categorical (string) columns in DataFrames."
9
+ readme = "README.md"
10
+ license = {text = "MIT"}
11
+ authors = [
12
+ {name = "dnnsqe"}
13
+ ]
14
+ requires-python = ">=3.9"
15
+ dependencies = [
16
+ "numpy",
17
+ "pandas",
18
+ "scipy",
19
+ "scikit-learn>=1.0",
20
+ ]
21
+ classifiers = [
22
+ "Development Status :: 3 - Alpha",
23
+ "Intended Audience :: Science/Research",
24
+ "License :: OSI Approved :: MIT License",
25
+ "Programming Language :: Python :: 3",
26
+ "Programming Language :: Python :: 3.9",
27
+ "Programming Language :: Python :: 3.10",
28
+ "Programming Language :: Python :: 3.11",
29
+ "Programming Language :: Python :: 3.12",
30
+ "Programming Language :: Python :: 3.13",
31
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
32
+ ]
33
+
34
+ [project.optional-dependencies]
35
+ dev = [
36
+ "pytest>=7",
37
+ "pytest-cov",
38
+ ]
39
+
40
+ [project.urls]
41
+ Repository = "https://github.com/dnnsqe/mixed-imputer"
42
+ Issues = "https://github.com/dnnsqe/mixed-imputer"
43
+
44
+ [tool.setuptools.packages.find]
45
+ where = ["src"]
46
+
47
+ [tool.setuptools]
48
+ package-dir = {"" = "src"}
49
+
50
+ [tool.pytest.ini_options]
51
+ testpaths = ["tests"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,4 @@
1
+ from ._imputer import MixedTypeImputer
2
+ from ._version import __version__
3
+
4
+ __all__ = ["MixedTypeImputer", "__version__"]