bitbullet 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.
Files changed (112) hide show
  1. bitbullet-0.1.0/LICENSE +21 -0
  2. bitbullet-0.1.0/PKG-INFO +296 -0
  3. bitbullet-0.1.0/README.md +222 -0
  4. bitbullet-0.1.0/bitbullet/__init__.py +1 -0
  5. bitbullet-0.1.0/bitbullet/cluster/__init__.py +34 -0
  6. bitbullet-0.1.0/bitbullet/cluster/algorithms/__init__.py +0 -0
  7. bitbullet-0.1.0/bitbullet/cluster/algorithms/density/__init__.py +0 -0
  8. bitbullet-0.1.0/bitbullet/cluster/algorithms/density/dbscan.py +252 -0
  9. bitbullet-0.1.0/bitbullet/cluster/algorithms/model_based/__init__.py +0 -0
  10. bitbullet-0.1.0/bitbullet/cluster/algorithms/model_based/gmm.py +283 -0
  11. bitbullet-0.1.0/bitbullet/cluster/algorithms/partitional/__init__.py +19 -0
  12. bitbullet-0.1.0/bitbullet/cluster/algorithms/partitional/kmeans.py +157 -0
  13. bitbullet-0.1.0/bitbullet/cluster/algorithms/partitional/kmodes.py +334 -0
  14. bitbullet-0.1.0/bitbullet/cluster/algorithms/partitional/kprototypes.py +281 -0
  15. bitbullet-0.1.0/bitbullet/cluster/core/__init__.py +74 -0
  16. bitbullet-0.1.0/bitbullet/cluster/core/autopipeline.py +355 -0
  17. bitbullet-0.1.0/bitbullet/cluster/core/base.py +348 -0
  18. bitbullet-0.1.0/bitbullet/cluster/core/registry.py +61 -0
  19. bitbullet-0.1.0/bitbullet/cluster/distance/__init__.py +23 -0
  20. bitbullet-0.1.0/bitbullet/cluster/distance/mixed.py +178 -0
  21. bitbullet-0.1.0/bitbullet/cluster/distances/__init__.py +0 -0
  22. bitbullet-0.1.0/bitbullet/cluster/distances/memory_efficient.py +297 -0
  23. bitbullet-0.1.0/bitbullet/cluster/evaluation/__init__.py +66 -0
  24. bitbullet-0.1.0/bitbullet/cluster/evaluation/metrics.py +537 -0
  25. bitbullet-0.1.0/bitbullet/cluster/evaluation/profiling.py +602 -0
  26. bitbullet-0.1.0/bitbullet/cluster/evaluation/selection.py +214 -0
  27. bitbullet-0.1.0/bitbullet/cluster/utils/__init__.py +13 -0
  28. bitbullet-0.1.0/bitbullet/cluster/utils/sample_size.py +655 -0
  29. bitbullet-0.1.0/bitbullet/cluster/visualization/__init__.py +54 -0
  30. bitbullet-0.1.0/bitbullet/cluster/visualization/decomposition.py +324 -0
  31. bitbullet-0.1.0/bitbullet/cluster/visualization/interactive.py +496 -0
  32. bitbullet-0.1.0/bitbullet/cluster/weights/__init__.py +0 -0
  33. bitbullet-0.1.0/bitbullet/cluster/weights/categorical_weights.py +295 -0
  34. bitbullet-0.1.0/bitbullet/cluster/weights/gamma_estimation.py +273 -0
  35. bitbullet-0.1.0/bitbullet/evaluate/__init__.py +41 -0
  36. bitbullet-0.1.0/bitbullet/evaluate/classification.py +181 -0
  37. bitbullet-0.1.0/bitbullet/evaluate/config.py +50 -0
  38. bitbullet-0.1.0/bitbullet/evaluate/evaluator.py +322 -0
  39. bitbullet-0.1.0/bitbullet/evaluate/regression.py +136 -0
  40. bitbullet-0.1.0/bitbullet/model/__init__.py +55 -0
  41. bitbullet-0.1.0/bitbullet/model/core/__init__.py +1 -0
  42. bitbullet-0.1.0/bitbullet/model/core/base.py +213 -0
  43. bitbullet-0.1.0/bitbullet/model/core/metadata.py +335 -0
  44. bitbullet-0.1.0/bitbullet/model/core/registry.py +127 -0
  45. bitbullet-0.1.0/bitbullet/model/serialization/__init__.py +1 -0
  46. bitbullet-0.1.0/bitbullet/model/serialization/model_serializer.py +378 -0
  47. bitbullet-0.1.0/bitbullet/model/wrappers/__init__.py +39 -0
  48. bitbullet-0.1.0/bitbullet/model/wrappers/lgbm_wrapper.py +311 -0
  49. bitbullet-0.1.0/bitbullet/model/wrappers/xgb_wrapper.py +181 -0
  50. bitbullet-0.1.0/bitbullet/train/__init__.py +57 -0
  51. bitbullet-0.1.0/bitbullet/train/callbacks/__init__.py +0 -0
  52. bitbullet-0.1.0/bitbullet/train/core/__init__.py +1 -0
  53. bitbullet-0.1.0/bitbullet/train/core/base.py +526 -0
  54. bitbullet-0.1.0/bitbullet/train/core/config.py +216 -0
  55. bitbullet-0.1.0/bitbullet/train/core/state.py +149 -0
  56. bitbullet-0.1.0/bitbullet/train/evaluation/__init__.py +0 -0
  57. bitbullet-0.1.0/bitbullet/train/evaluation/threshold_optimizer.py +153 -0
  58. bitbullet-0.1.0/bitbullet/train/explainability/__init__.py +19 -0
  59. bitbullet-0.1.0/bitbullet/train/explainability/shap_explainer.py +581 -0
  60. bitbullet-0.1.0/bitbullet/train/feature_selection/__init__.py +0 -0
  61. bitbullet-0.1.0/bitbullet/train/feature_selection/selector_factory.py +609 -0
  62. bitbullet-0.1.0/bitbullet/train/optimizers/__init__.py +0 -0
  63. bitbullet-0.1.0/bitbullet/train/optimizers/hyperparameter_grids.py +511 -0
  64. bitbullet-0.1.0/bitbullet/train/optimizers/optuna_optimizer.py +252 -0
  65. bitbullet-0.1.0/bitbullet/train/reports/__init__.py +19 -0
  66. bitbullet-0.1.0/bitbullet/train/reports/feature_report.py +365 -0
  67. bitbullet-0.1.0/bitbullet/train/reports/training_report.py +325 -0
  68. bitbullet-0.1.0/bitbullet/train/trainers/__init__.py +0 -0
  69. bitbullet-0.1.0/bitbullet/train/trainers/optuna_trainer.py +1044 -0
  70. bitbullet-0.1.0/bitbullet/train/utils/__init__.py +0 -0
  71. bitbullet-0.1.0/bitbullet/train/utils/sample_weights.py +174 -0
  72. bitbullet-0.1.0/bitbullet/transform/__init__.py +29 -0
  73. bitbullet-0.1.0/bitbullet/transform/core/__init__.py +7 -0
  74. bitbullet-0.1.0/bitbullet/transform/core/base.py +308 -0
  75. bitbullet-0.1.0/bitbullet/transform/core/pipeline.py +518 -0
  76. bitbullet-0.1.0/bitbullet/transform/core/registry.py +241 -0
  77. bitbullet-0.1.0/bitbullet/transform/eda.py +148 -0
  78. bitbullet-0.1.0/bitbullet/transform/transformers/__init__.py +13 -0
  79. bitbullet-0.1.0/bitbullet/transform/transformers/categorical.py +344 -0
  80. bitbullet-0.1.0/bitbullet/transform/transformers/datetime.py +191 -0
  81. bitbullet-0.1.0/bitbullet/transform/transformers/numerical.py +407 -0
  82. bitbullet-0.1.0/bitbullet/transform/transformers/target.py +487 -0
  83. bitbullet-0.1.0/bitbullet.egg-info/PKG-INFO +296 -0
  84. bitbullet-0.1.0/bitbullet.egg-info/SOURCES.txt +110 -0
  85. bitbullet-0.1.0/bitbullet.egg-info/dependency_links.txt +1 -0
  86. bitbullet-0.1.0/bitbullet.egg-info/requires.txt +57 -0
  87. bitbullet-0.1.0/bitbullet.egg-info/top_level.txt +1 -0
  88. bitbullet-0.1.0/pyproject.toml +123 -0
  89. bitbullet-0.1.0/setup.cfg +4 -0
  90. bitbullet-0.1.0/tests/test_basic.py +245 -0
  91. bitbullet-0.1.0/tests/test_categorical_weights.py +157 -0
  92. bitbullet-0.1.0/tests/test_classification_metrics_report.py +57 -0
  93. bitbullet-0.1.0/tests/test_dbscan.py +302 -0
  94. bitbullet-0.1.0/tests/test_distances.py +237 -0
  95. bitbullet-0.1.0/tests/test_documentation_examples.py +541 -0
  96. bitbullet-0.1.0/tests/test_evaluation.py +385 -0
  97. bitbullet-0.1.0/tests/test_feature_selection.py +391 -0
  98. bitbullet-0.1.0/tests/test_gamma_estimation.py +188 -0
  99. bitbullet-0.1.0/tests/test_gmm.py +354 -0
  100. bitbullet-0.1.0/tests/test_kmeans.py +244 -0
  101. bitbullet-0.1.0/tests/test_kmodes_metadata.py +36 -0
  102. bitbullet-0.1.0/tests/test_kprototypes.py +171 -0
  103. bitbullet-0.1.0/tests/test_lgbm_wrapper.py +382 -0
  104. bitbullet-0.1.0/tests/test_model_serializer.py +490 -0
  105. bitbullet-0.1.0/tests/test_optuna_progress_count.py +45 -0
  106. bitbullet-0.1.0/tests/test_optuna_trainer.py +651 -0
  107. bitbullet-0.1.0/tests/test_partitional_lazy_imports.py +25 -0
  108. bitbullet-0.1.0/tests/test_regression_metrics_report.py +75 -0
  109. bitbullet-0.1.0/tests/test_regression_training.py +197 -0
  110. bitbullet-0.1.0/tests/test_rf_oob_bootstrap.py +37 -0
  111. bitbullet-0.1.0/tests/test_train_search_strategies.py +114 -0
  112. bitbullet-0.1.0/tests/test_visualization.py +435 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 BitBullet
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,296 @@
1
+ Metadata-Version: 2.4
2
+ Name: bitbullet
3
+ Version: 0.1.0
4
+ Summary: Composable data-science building blocks for tabular transformation, training, clustering, evaluation, and model metadata.
5
+ Author-email: BitBullet <contact@bitbullet.ai>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://bitbullet.ai
8
+ Project-URL: Repository, https://gitlab.com/bitbullet/bitbullet
9
+ Project-URL: Documentation, https://bitbullet.ai
10
+ Project-URL: Issues, https://gitlab.com/bitbullet/bitbullet/-/issues
11
+ Keywords: machine-learning,clustering,mlops,data-science,optimization
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Requires-Python: >=3.10
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: numpy>=1.24.0
23
+ Requires-Dist: pandas>=2.0.0
24
+ Requires-Dist: scipy>=1.11.0
25
+ Requires-Dist: scikit-learn>=1.3.0
26
+ Requires-Dist: joblib>=1.3.0
27
+ Requires-Dist: pydantic>=2.0.0
28
+ Requires-Dist: pyarrow>=12.0.0
29
+ Provides-Extra: inference-models
30
+ Requires-Dist: xgboost>=1.7.0; extra == "inference-models"
31
+ Requires-Dist: lightgbm>=3.3.0; extra == "inference-models"
32
+ Provides-Extra: inference-cluster
33
+ Requires-Dist: hdbscan>=0.8.33; extra == "inference-cluster"
34
+ Requires-Dist: kmodes>=0.12.0; extra == "inference-cluster"
35
+ Requires-Dist: umap-learn>=0.5.3; extra == "inference-cluster"
36
+ Requires-Dist: prince>=0.13.0; extra == "inference-cluster"
37
+ Provides-Extra: train
38
+ Requires-Dist: xgboost>=1.7.0; extra == "train"
39
+ Requires-Dist: lightgbm>=3.3.0; extra == "train"
40
+ Requires-Dist: optuna>=3.0.0; extra == "train"
41
+ Requires-Dist: shap>=0.42.0; extra == "train"
42
+ Requires-Dist: tqdm>=4.65.0; extra == "train"
43
+ Requires-Dist: psutil>=5.9.0; extra == "train"
44
+ Provides-Extra: viz
45
+ Requires-Dist: matplotlib>=3.7.0; extra == "viz"
46
+ Requires-Dist: seaborn>=0.12.0; extra == "viz"
47
+ Requires-Dist: plotly>=5.14.0; extra == "viz"
48
+ Requires-Dist: ipywidgets>=8.0.0; extra == "viz"
49
+ Requires-Dist: ipython>=8.0.0; extra == "viz"
50
+ Provides-Extra: all
51
+ Requires-Dist: xgboost>=1.7.0; extra == "all"
52
+ Requires-Dist: lightgbm>=3.3.0; extra == "all"
53
+ Requires-Dist: hdbscan>=0.8.33; extra == "all"
54
+ Requires-Dist: kmodes>=0.12.0; extra == "all"
55
+ Requires-Dist: umap-learn>=0.5.3; extra == "all"
56
+ Requires-Dist: prince>=0.13.0; extra == "all"
57
+ Requires-Dist: optuna>=3.0.0; extra == "all"
58
+ Requires-Dist: shap>=0.42.0; extra == "all"
59
+ Requires-Dist: tqdm>=4.65.0; extra == "all"
60
+ Requires-Dist: psutil>=5.9.0; extra == "all"
61
+ Requires-Dist: matplotlib>=3.7.0; extra == "all"
62
+ Requires-Dist: seaborn>=0.12.0; extra == "all"
63
+ Requires-Dist: plotly>=5.14.0; extra == "all"
64
+ Requires-Dist: ipywidgets>=8.0.0; extra == "all"
65
+ Requires-Dist: ipython>=8.0.0; extra == "all"
66
+ Provides-Extra: dev
67
+ Requires-Dist: pytest>=7.4.0; extra == "dev"
68
+ Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
69
+ Requires-Dist: black>=23.0.0; extra == "dev"
70
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
71
+ Requires-Dist: mypy>=1.5.0; extra == "dev"
72
+ Requires-Dist: build>=1.0.0; extra == "dev"
73
+ Dynamic: license-file
74
+
75
+ # BitBullet
76
+
77
+ BitBullet is a Python data-science SDK for tabular machine learning workflows.
78
+ It provides composable building blocks for transformation pipelines, model
79
+ training, clustering, evaluation, and reproducible artifact metadata.
80
+
81
+ The SDK is intentionally workflow-friendly without being platform-specific. You
82
+ can use the pieces step by step, wire them into notebooks, or embed them in your
83
+ own services.
84
+
85
+ ## Modules
86
+
87
+ | Module | Purpose |
88
+ | --- | --- |
89
+ | `bitbullet.transform` | Fitted transformation pipelines for numerical, categorical, and datetime features. |
90
+ | `bitbullet.train` | Supervised classification/regression training utilities, Optuna-backed search, feature selection, sample weights, threshold optimization, and training reports. |
91
+ | `bitbullet.cluster` | K-Means, K-Modes, K-Prototypes, DBSCAN, GMM, gamma estimation, categorical weighting, K selection, profiling, and clustering metrics. |
92
+ | `bitbullet.evaluate` | Structured classification, regression, and clustering evaluation numbers for reports and metadata. |
93
+ | `bitbullet.model` | Model wrappers, model metadata, dataset metadata, and serialization helpers. |
94
+
95
+ ## Installation
96
+
97
+ ```bash
98
+ pip install bitbullet
99
+ ```
100
+
101
+ Optional extras keep installations lean:
102
+
103
+ ```bash
104
+ pip install "bitbullet[inference-models]" # LightGBM and XGBoost wrappers
105
+ pip install "bitbullet[inference-cluster]" # clustering extras such as kmodes
106
+ pip install "bitbullet[train,viz]" # training, SHAP, and plotting tools
107
+ pip install "bitbullet[all]" # complete SDK
108
+ ```
109
+
110
+ Development install:
111
+
112
+ ```bash
113
+ git clone https://gitlab.com/bitbullet/bitbullet.git
114
+ cd bitbullet
115
+ pip install -e ".[all,dev]"
116
+ ```
117
+
118
+ ## Transform Data
119
+
120
+ ```python
121
+ from bitbullet.transform import TransformPipeline
122
+
123
+ pipeline = TransformPipeline(name="credit_features")
124
+ pipeline.add("numerical", "standard_scale", columns=["income", "balance"])
125
+ pipeline.add("categorical", "onehot_encode", columns=["region"])
126
+
127
+ X_transformed = pipeline.fit_transform(X_train)
128
+ X_new = pipeline.transform(X_new_raw)
129
+ pipeline.save("artifacts/transform_pipeline.joblib")
130
+ ```
131
+
132
+ Target-aware encoders receive `y` directly. `target_encode` is leakage-aware:
133
+ `fit_transform(..., y=...)` returns out-of-fold training encodings, while later
134
+ `transform(...)` calls use the stored full-training smoothed mapping.
135
+
136
+ ```python
137
+ pipeline = TransformPipeline()
138
+ pipeline.add(
139
+ "categorical",
140
+ "target_encode",
141
+ columns=["merchant_category"],
142
+ params={"target_type": "classification", "cv_folds": 5, "cv_strategy": "stratified"},
143
+ )
144
+ X_encoded = pipeline.fit_transform(X_train, y=y_train)
145
+ ```
146
+
147
+ ## Train A Classifier
148
+
149
+ ```python
150
+ from bitbullet.train import TrainConfig, OptunaTrainer
151
+
152
+ config = TrainConfig(
153
+ name="default_risk_lgbm",
154
+ model_type="lgbm",
155
+ task="binary_classification",
156
+ n_trials=30,
157
+ optimization_metric="roc_auc",
158
+ optuna_sampler="tpe", # tpe, random, grid, cmaes
159
+ )
160
+
161
+ trainer = OptunaTrainer(config)
162
+ model = trainer.fit(X_train, y_train, X_val=X_val, y_val=y_val)
163
+
164
+ print(trainer.best_params)
165
+ print(trainer.state.optimal_threshold)
166
+ ```
167
+
168
+ Manual fixed-parameter training is available when you do not want a search:
169
+
170
+ ```python
171
+ config = TrainConfig(
172
+ name="fixed_rf",
173
+ model_type="random_forest",
174
+ optimizer="manual",
175
+ model_params={"n_estimators": 300, "max_depth": 20},
176
+ )
177
+ ```
178
+
179
+ Optuna-backed grid and random search are explicit sampler choices:
180
+
181
+ ```python
182
+ config = TrainConfig(
183
+ name="small_grid",
184
+ model_type="lgbm",
185
+ optuna_sampler="grid",
186
+ search_space={
187
+ "num_leaves": [31, 63],
188
+ "learning_rate": [0.05, 0.1],
189
+ },
190
+ )
191
+ ```
192
+
193
+ ## Evaluate Classification
194
+
195
+ ```python
196
+ from bitbullet.evaluate import evaluate_classification
197
+
198
+ report = evaluate_classification(
199
+ y_true=y_test,
200
+ y_pred_proba=model.predict_proba(X_test),
201
+ threshold=trainer.state.optimal_threshold or 0.5,
202
+ )
203
+
204
+ metadata_ready = report.to_dict()
205
+ ```
206
+
207
+ ## Train And Evaluate A Regressor
208
+
209
+ ```python
210
+ from bitbullet.evaluate import evaluate_regression
211
+ from bitbullet.train import TrainConfig, OptunaTrainer
212
+
213
+ config = TrainConfig(
214
+ name="house_price_lgbm",
215
+ model_type="lgbm",
216
+ task="regression",
217
+ n_trials=30,
218
+ optimization_metric="rmse", # minimize by default for regression
219
+ optuna_sampler="tpe",
220
+ )
221
+
222
+ trainer = OptunaTrainer(config)
223
+ model = trainer.fit(X_train, y_train)
224
+
225
+ y_pred = model.predict(X_test)
226
+ report = evaluate_regression(
227
+ y_true=y_test,
228
+ y_pred=y_pred,
229
+ n_features=X_train.shape[1],
230
+ )
231
+
232
+ metadata_ready = report.to_dict()
233
+ ```
234
+
235
+ ## Cluster Data
236
+
237
+ ```python
238
+ from bitbullet.cluster.core import ClusterConfig
239
+ from bitbullet.cluster.algorithms.partitional import KPrototypesClusterer
240
+
241
+ config = ClusterConfig(
242
+ name="customer_segments",
243
+ algorithm_type="partitional",
244
+ method="kprototypes",
245
+ n_clusters=5,
246
+ numerical_columns=["income", "spend"],
247
+ categorical_columns=["region", "channel"],
248
+ params={
249
+ "gamma": "huang",
250
+ "categorical_weights": "relevance",
251
+ "init": "Cao",
252
+ "n_init": 10,
253
+ },
254
+ )
255
+
256
+ clusterer = KPrototypesClusterer(config)
257
+ labels = clusterer.fit_predict(df)
258
+
259
+ print(clusterer.state.fitted_params["gamma_by_column"])
260
+ print(clusterer.state.fitted_params["categorical_weights_by_column"])
261
+ ```
262
+
263
+ ## Save Models With Metadata
264
+
265
+ ```python
266
+ from bitbullet.model import ModelMetadata, ModelSerializer
267
+
268
+ metadata = ModelMetadata(
269
+ name="default_risk_lgbm",
270
+ model_type=model.model_type,
271
+ framework=model.framework,
272
+ task="binary_classification",
273
+ metrics=report.metrics,
274
+ )
275
+ metadata.add_feature_schema(X_train)
276
+
277
+ ModelSerializer.save(
278
+ model=model,
279
+ path="artifacts/default_risk_lgbm.pkl",
280
+ metadata=metadata,
281
+ train_data=(X_train, y_train),
282
+ test_data=(X_test, y_test),
283
+ include_datasets=False,
284
+ )
285
+ ```
286
+
287
+ ## Design Boundary
288
+
289
+ BitBullet SDK components do not know about hosted projects, users, queues,
290
+ frontend pages, or product-specific container contracts. They provide the
291
+ reusable data-science pieces: fitted state, metrics, metadata, and serializers.
292
+ Higher-level services can compose those pieces into their own execution flows.
293
+
294
+ ## License
295
+
296
+ MIT
@@ -0,0 +1,222 @@
1
+ # BitBullet
2
+
3
+ BitBullet is a Python data-science SDK for tabular machine learning workflows.
4
+ It provides composable building blocks for transformation pipelines, model
5
+ training, clustering, evaluation, and reproducible artifact metadata.
6
+
7
+ The SDK is intentionally workflow-friendly without being platform-specific. You
8
+ can use the pieces step by step, wire them into notebooks, or embed them in your
9
+ own services.
10
+
11
+ ## Modules
12
+
13
+ | Module | Purpose |
14
+ | --- | --- |
15
+ | `bitbullet.transform` | Fitted transformation pipelines for numerical, categorical, and datetime features. |
16
+ | `bitbullet.train` | Supervised classification/regression training utilities, Optuna-backed search, feature selection, sample weights, threshold optimization, and training reports. |
17
+ | `bitbullet.cluster` | K-Means, K-Modes, K-Prototypes, DBSCAN, GMM, gamma estimation, categorical weighting, K selection, profiling, and clustering metrics. |
18
+ | `bitbullet.evaluate` | Structured classification, regression, and clustering evaluation numbers for reports and metadata. |
19
+ | `bitbullet.model` | Model wrappers, model metadata, dataset metadata, and serialization helpers. |
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ pip install bitbullet
25
+ ```
26
+
27
+ Optional extras keep installations lean:
28
+
29
+ ```bash
30
+ pip install "bitbullet[inference-models]" # LightGBM and XGBoost wrappers
31
+ pip install "bitbullet[inference-cluster]" # clustering extras such as kmodes
32
+ pip install "bitbullet[train,viz]" # training, SHAP, and plotting tools
33
+ pip install "bitbullet[all]" # complete SDK
34
+ ```
35
+
36
+ Development install:
37
+
38
+ ```bash
39
+ git clone https://gitlab.com/bitbullet/bitbullet.git
40
+ cd bitbullet
41
+ pip install -e ".[all,dev]"
42
+ ```
43
+
44
+ ## Transform Data
45
+
46
+ ```python
47
+ from bitbullet.transform import TransformPipeline
48
+
49
+ pipeline = TransformPipeline(name="credit_features")
50
+ pipeline.add("numerical", "standard_scale", columns=["income", "balance"])
51
+ pipeline.add("categorical", "onehot_encode", columns=["region"])
52
+
53
+ X_transformed = pipeline.fit_transform(X_train)
54
+ X_new = pipeline.transform(X_new_raw)
55
+ pipeline.save("artifacts/transform_pipeline.joblib")
56
+ ```
57
+
58
+ Target-aware encoders receive `y` directly. `target_encode` is leakage-aware:
59
+ `fit_transform(..., y=...)` returns out-of-fold training encodings, while later
60
+ `transform(...)` calls use the stored full-training smoothed mapping.
61
+
62
+ ```python
63
+ pipeline = TransformPipeline()
64
+ pipeline.add(
65
+ "categorical",
66
+ "target_encode",
67
+ columns=["merchant_category"],
68
+ params={"target_type": "classification", "cv_folds": 5, "cv_strategy": "stratified"},
69
+ )
70
+ X_encoded = pipeline.fit_transform(X_train, y=y_train)
71
+ ```
72
+
73
+ ## Train A Classifier
74
+
75
+ ```python
76
+ from bitbullet.train import TrainConfig, OptunaTrainer
77
+
78
+ config = TrainConfig(
79
+ name="default_risk_lgbm",
80
+ model_type="lgbm",
81
+ task="binary_classification",
82
+ n_trials=30,
83
+ optimization_metric="roc_auc",
84
+ optuna_sampler="tpe", # tpe, random, grid, cmaes
85
+ )
86
+
87
+ trainer = OptunaTrainer(config)
88
+ model = trainer.fit(X_train, y_train, X_val=X_val, y_val=y_val)
89
+
90
+ print(trainer.best_params)
91
+ print(trainer.state.optimal_threshold)
92
+ ```
93
+
94
+ Manual fixed-parameter training is available when you do not want a search:
95
+
96
+ ```python
97
+ config = TrainConfig(
98
+ name="fixed_rf",
99
+ model_type="random_forest",
100
+ optimizer="manual",
101
+ model_params={"n_estimators": 300, "max_depth": 20},
102
+ )
103
+ ```
104
+
105
+ Optuna-backed grid and random search are explicit sampler choices:
106
+
107
+ ```python
108
+ config = TrainConfig(
109
+ name="small_grid",
110
+ model_type="lgbm",
111
+ optuna_sampler="grid",
112
+ search_space={
113
+ "num_leaves": [31, 63],
114
+ "learning_rate": [0.05, 0.1],
115
+ },
116
+ )
117
+ ```
118
+
119
+ ## Evaluate Classification
120
+
121
+ ```python
122
+ from bitbullet.evaluate import evaluate_classification
123
+
124
+ report = evaluate_classification(
125
+ y_true=y_test,
126
+ y_pred_proba=model.predict_proba(X_test),
127
+ threshold=trainer.state.optimal_threshold or 0.5,
128
+ )
129
+
130
+ metadata_ready = report.to_dict()
131
+ ```
132
+
133
+ ## Train And Evaluate A Regressor
134
+
135
+ ```python
136
+ from bitbullet.evaluate import evaluate_regression
137
+ from bitbullet.train import TrainConfig, OptunaTrainer
138
+
139
+ config = TrainConfig(
140
+ name="house_price_lgbm",
141
+ model_type="lgbm",
142
+ task="regression",
143
+ n_trials=30,
144
+ optimization_metric="rmse", # minimize by default for regression
145
+ optuna_sampler="tpe",
146
+ )
147
+
148
+ trainer = OptunaTrainer(config)
149
+ model = trainer.fit(X_train, y_train)
150
+
151
+ y_pred = model.predict(X_test)
152
+ report = evaluate_regression(
153
+ y_true=y_test,
154
+ y_pred=y_pred,
155
+ n_features=X_train.shape[1],
156
+ )
157
+
158
+ metadata_ready = report.to_dict()
159
+ ```
160
+
161
+ ## Cluster Data
162
+
163
+ ```python
164
+ from bitbullet.cluster.core import ClusterConfig
165
+ from bitbullet.cluster.algorithms.partitional import KPrototypesClusterer
166
+
167
+ config = ClusterConfig(
168
+ name="customer_segments",
169
+ algorithm_type="partitional",
170
+ method="kprototypes",
171
+ n_clusters=5,
172
+ numerical_columns=["income", "spend"],
173
+ categorical_columns=["region", "channel"],
174
+ params={
175
+ "gamma": "huang",
176
+ "categorical_weights": "relevance",
177
+ "init": "Cao",
178
+ "n_init": 10,
179
+ },
180
+ )
181
+
182
+ clusterer = KPrototypesClusterer(config)
183
+ labels = clusterer.fit_predict(df)
184
+
185
+ print(clusterer.state.fitted_params["gamma_by_column"])
186
+ print(clusterer.state.fitted_params["categorical_weights_by_column"])
187
+ ```
188
+
189
+ ## Save Models With Metadata
190
+
191
+ ```python
192
+ from bitbullet.model import ModelMetadata, ModelSerializer
193
+
194
+ metadata = ModelMetadata(
195
+ name="default_risk_lgbm",
196
+ model_type=model.model_type,
197
+ framework=model.framework,
198
+ task="binary_classification",
199
+ metrics=report.metrics,
200
+ )
201
+ metadata.add_feature_schema(X_train)
202
+
203
+ ModelSerializer.save(
204
+ model=model,
205
+ path="artifacts/default_risk_lgbm.pkl",
206
+ metadata=metadata,
207
+ train_data=(X_train, y_train),
208
+ test_data=(X_test, y_test),
209
+ include_datasets=False,
210
+ )
211
+ ```
212
+
213
+ ## Design Boundary
214
+
215
+ BitBullet SDK components do not know about hosted projects, users, queues,
216
+ frontend pages, or product-specific container contracts. They provide the
217
+ reusable data-science pieces: fitted state, metrics, metadata, and serializers.
218
+ Higher-level services can compose those pieces into their own execution flows.
219
+
220
+ ## License
221
+
222
+ MIT
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"
@@ -0,0 +1,34 @@
1
+ """
2
+ BitBullet Cluster - Production-grade clustering engine for mixed data types.
3
+
4
+ This package provides a comprehensive clustering solution with:
5
+ - Support for mixed numerical and categorical data
6
+ - Multiple clustering algorithms (K-Modes, K-Prototypes, K-Means, DBSCAN, GMM)
7
+ - Data-driven feature weighting
8
+ - Memory-efficient distance computation
9
+ - Production-ready serialization
10
+ - Comprehensive evaluation metrics
11
+ - Beautiful visualizations
12
+ """
13
+
14
+ from bitbullet.cluster.core.base import BaseClusterer, ClusterConfig, ClusterState
15
+ from bitbullet.cluster.weights.categorical_weights import CategoricalWeights
16
+ from bitbullet.cluster.weights.gamma_estimation import GammaEstimator
17
+ from bitbullet.cluster.utils.sample_size import (
18
+ SampleSizeEstimator,
19
+ SampleSizeEstimate,
20
+ estimate_sample_size,
21
+ )
22
+
23
+ __version__ = "0.1.0"
24
+
25
+ __all__ = [
26
+ "BaseClusterer",
27
+ "ClusterConfig",
28
+ "ClusterState",
29
+ "CategoricalWeights",
30
+ "GammaEstimator",
31
+ "SampleSizeEstimator",
32
+ "SampleSizeEstimate",
33
+ "estimate_sample_size",
34
+ ]