ngboost 0.5.2.dev0__tar.gz → 0.5.4__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.
- {ngboost-0.5.2.dev0 → ngboost-0.5.4}/PKG-INFO +1 -1
- {ngboost-0.5.2.dev0 → ngboost-0.5.4}/ngboost/ngboost.py +60 -18
- {ngboost-0.5.2.dev0 → ngboost-0.5.4}/pyproject.toml +2 -1
- {ngboost-0.5.2.dev0 → ngboost-0.5.4}/setup.py +1 -1
- {ngboost-0.5.2.dev0 → ngboost-0.5.4}/LICENSE +0 -0
- {ngboost-0.5.2.dev0 → ngboost-0.5.4}/README.md +0 -0
- {ngboost-0.5.2.dev0 → ngboost-0.5.4}/ngboost/__init__.py +0 -0
- {ngboost-0.5.2.dev0 → ngboost-0.5.4}/ngboost/api.py +0 -0
- {ngboost-0.5.2.dev0 → ngboost-0.5.4}/ngboost/distns/__init__.py +0 -0
- {ngboost-0.5.2.dev0 → ngboost-0.5.4}/ngboost/distns/categorical.py +0 -0
- {ngboost-0.5.2.dev0 → ngboost-0.5.4}/ngboost/distns/cauchy.py +0 -0
- {ngboost-0.5.2.dev0 → ngboost-0.5.4}/ngboost/distns/distn.py +0 -0
- {ngboost-0.5.2.dev0 → ngboost-0.5.4}/ngboost/distns/exponential.py +0 -0
- {ngboost-0.5.2.dev0 → ngboost-0.5.4}/ngboost/distns/gamma.py +0 -0
- {ngboost-0.5.2.dev0 → ngboost-0.5.4}/ngboost/distns/laplace.py +0 -0
- {ngboost-0.5.2.dev0 → ngboost-0.5.4}/ngboost/distns/lognormal.py +0 -0
- {ngboost-0.5.2.dev0 → ngboost-0.5.4}/ngboost/distns/multivariate_normal.py +0 -0
- {ngboost-0.5.2.dev0 → ngboost-0.5.4}/ngboost/distns/normal.py +0 -0
- {ngboost-0.5.2.dev0 → ngboost-0.5.4}/ngboost/distns/poisson.py +0 -0
- {ngboost-0.5.2.dev0 → ngboost-0.5.4}/ngboost/distns/t.py +0 -0
- {ngboost-0.5.2.dev0 → ngboost-0.5.4}/ngboost/distns/utils.py +0 -0
- {ngboost-0.5.2.dev0 → ngboost-0.5.4}/ngboost/evaluation.py +0 -0
- {ngboost-0.5.2.dev0 → ngboost-0.5.4}/ngboost/helpers.py +0 -0
- {ngboost-0.5.2.dev0 → ngboost-0.5.4}/ngboost/learners.py +0 -0
- {ngboost-0.5.2.dev0 → ngboost-0.5.4}/ngboost/manifold.py +0 -0
- {ngboost-0.5.2.dev0 → ngboost-0.5.4}/ngboost/scores.py +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"""The NGBoost library"""
|
|
2
|
+
|
|
2
3
|
# pylint: disable=line-too-long,too-many-instance-attributes,too-many-arguments
|
|
3
4
|
# pylint: disable=unused-argument,too-many-locals,too-many-branches,too-many-statements
|
|
4
5
|
# pylint: disable=unused-variable,invalid-unary-operand-type,attribute-defined-outside-init
|
|
@@ -320,29 +321,69 @@ class NGBoost:
|
|
|
320
321
|
# This will overwrite any X_val and Y_val values passed by the user directly.
|
|
321
322
|
if self.early_stopping_rounds is not None:
|
|
322
323
|
early_stopping_rounds = self.early_stopping_rounds
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
X,
|
|
327
|
-
Y,
|
|
328
|
-
test_size=self.validation_fraction,
|
|
329
|
-
random_state=self.random_state,
|
|
324
|
+
if X_val is None and Y_val is None:
|
|
325
|
+
print(
|
|
326
|
+
f"early_stopping_rounds is set to {early_stopping_rounds} but no validation set is provided creating val set with {self.validation_fraction} of the training data"
|
|
330
327
|
)
|
|
328
|
+
if sample_weight is None:
|
|
329
|
+
print(
|
|
330
|
+
"Creating validation set without sample weight similar to the training data"
|
|
331
|
+
)
|
|
332
|
+
X, X_val, Y, Y_val = train_test_split(
|
|
333
|
+
X,
|
|
334
|
+
Y,
|
|
335
|
+
test_size=self.validation_fraction,
|
|
336
|
+
random_state=self.random_state,
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
else:
|
|
340
|
+
print(
|
|
341
|
+
"Creating validation set with sample weight similar to the training data"
|
|
342
|
+
)
|
|
343
|
+
(
|
|
344
|
+
X,
|
|
345
|
+
X_val,
|
|
346
|
+
Y,
|
|
347
|
+
Y_val,
|
|
348
|
+
sample_weight,
|
|
349
|
+
val_sample_weight,
|
|
350
|
+
) = train_test_split(
|
|
351
|
+
X,
|
|
352
|
+
Y,
|
|
353
|
+
sample_weight,
|
|
354
|
+
test_size=self.validation_fraction,
|
|
355
|
+
random_state=self.random_state,
|
|
356
|
+
)
|
|
357
|
+
elif X_val is not None and Y_val is not None:
|
|
358
|
+
if sample_weight is not None and val_sample_weight is None:
|
|
359
|
+
raise ValueError(
|
|
360
|
+
"Training data is passed with sample weights but the validation data is missing sample weights pass the appropriate val_sample_weights"
|
|
361
|
+
)
|
|
362
|
+
if sample_weight is None and val_sample_weight is not None:
|
|
363
|
+
raise ValueError(
|
|
364
|
+
"sample weights mismatch between training and validation data check and pass the appropriate val_sample_weights"
|
|
365
|
+
)
|
|
366
|
+
|
|
367
|
+
print("Using passed validation data to check for early stopping.")
|
|
331
368
|
|
|
332
369
|
else:
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
)
|
|
370
|
+
if (X_val is not None and Y_val is None) or (
|
|
371
|
+
X_val is None and Y_val is not None
|
|
372
|
+
):
|
|
373
|
+
raise ValueError(
|
|
374
|
+
"Inconsistent Validation data either X_val or Y_val is missing, check the data"
|
|
375
|
+
)
|
|
340
376
|
|
|
341
377
|
if Y is None:
|
|
342
378
|
raise ValueError("y cannot be None")
|
|
343
379
|
|
|
344
380
|
X, Y = check_X_y(
|
|
345
|
-
X,
|
|
381
|
+
X,
|
|
382
|
+
Y,
|
|
383
|
+
accept_sparse=True,
|
|
384
|
+
force_all_finite="allow-nan",
|
|
385
|
+
multi_output=self.multi_output,
|
|
386
|
+
y_numeric=True,
|
|
346
387
|
)
|
|
347
388
|
|
|
348
389
|
self.n_features = X.shape[1]
|
|
@@ -357,8 +398,9 @@ class NGBoost:
|
|
|
357
398
|
X_val,
|
|
358
399
|
Y_val,
|
|
359
400
|
accept_sparse=True,
|
|
360
|
-
|
|
401
|
+
force_all_finite="allow-nan",
|
|
361
402
|
multi_output=self.multi_output,
|
|
403
|
+
y_numeric=True,
|
|
362
404
|
)
|
|
363
405
|
val_params = self.pred_param(X_val)
|
|
364
406
|
val_loss_list = []
|
|
@@ -490,7 +532,7 @@ class NGBoost:
|
|
|
490
532
|
A NGBoost distribution object
|
|
491
533
|
"""
|
|
492
534
|
|
|
493
|
-
X = check_array(X, accept_sparse=True)
|
|
535
|
+
X = check_array(X, accept_sparse=True, force_all_finite="allow-nan")
|
|
494
536
|
|
|
495
537
|
params = np.asarray(self.pred_param(X, max_iter))
|
|
496
538
|
dist = self.Dist(params.T)
|
|
@@ -537,7 +579,7 @@ class NGBoost:
|
|
|
537
579
|
Numpy array of the estimates of Y
|
|
538
580
|
"""
|
|
539
581
|
|
|
540
|
-
X = check_array(X, accept_sparse=True)
|
|
582
|
+
X = check_array(X, accept_sparse=True, force_all_finite="allow-nan")
|
|
541
583
|
|
|
542
584
|
return self.pred_dist(X, max_iter=max_iter).predict()
|
|
543
585
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "ngboost"
|
|
3
|
-
version = "0.5.
|
|
3
|
+
version = "0.5.4"
|
|
4
4
|
description = "Library for probabilistic predictions via gradient boosting."
|
|
5
5
|
authors = ["Stanford ML Group <avati@cs.stanford.edu>"]
|
|
6
6
|
readme = "README.md"
|
|
@@ -28,6 +28,7 @@ isort = "^5.6.4"
|
|
|
28
28
|
pylint = "^3.0.3"
|
|
29
29
|
flake8 = "^7.0.0"
|
|
30
30
|
|
|
31
|
+
|
|
31
32
|
[build-system]
|
|
32
33
|
requires = ["poetry-core>=1.0.0"]
|
|
33
34
|
build-backend = "poetry.core.masonry.api"
|
|
@@ -16,7 +16,7 @@ install_requires = \
|
|
|
16
16
|
|
|
17
17
|
setup_kwargs = {
|
|
18
18
|
'name': 'ngboost',
|
|
19
|
-
'version': '0.5.
|
|
19
|
+
'version': '0.5.4',
|
|
20
20
|
'description': 'Library for probabilistic predictions via gradient boosting.',
|
|
21
21
|
'long_description': '# NGBoost: Natural Gradient Boosting for Probabilistic Prediction\n\n<h4 align="center">\n\n\n[](https://github.com/stanfordmlgroup/ngboost/graphs/contributors)\n[](https://opensource.org/licenses/Apache-2.0)\n[](https://github.com/psf/black)\n[](https://pypi.org/project/ngboost)\n[](https://pypistats.org/packages/ngboost)\n\n</h4>\n\nngboost is a Python library that implements Natural Gradient Boosting, as described in ["NGBoost: Natural Gradient Boosting for Probabilistic Prediction"](https://stanfordmlgroup.github.io/projects/ngboost/). It is built on top of [Scikit-Learn](https://scikit-learn.org/stable/), and is designed to be scalable and modular with respect to choice of proper scoring rule, distribution, and base learner. A didactic introduction to the methodology underlying NGBoost is available in this [slide deck](https://docs.google.com/presentation/d/1Tn23Su0ygR6z11jy3xVNiLGv0ggiUQue/edit?usp=share_link&ouid=102290675300480810195&rtpof=true&sd=true).\n\n## Installation\n\n```sh\nvia pip\n\npip install --upgrade ngboost\n\nvia conda-forge\n\nconda install -c conda-forge ngboost\n```\n\n## Usage\n\nProbabilistic regression example on the Boston housing dataset:\n\n```python\nfrom ngboost import NGBRegressor\n\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import mean_squared_error\n\n#Load Boston housing dataset\ndata_url = "http://lib.stat.cmu.edu/datasets/boston"\nraw_df = pd.read_csv(data_url, sep="\\s+", skiprows=22, header=None)\nX = np.hstack([raw_df.values[::2, :], raw_df.values[1::2, :2]])\nY = raw_df.values[1::2, 2]\n\nX_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2)\n\nngb = NGBRegressor().fit(X_train, Y_train)\nY_preds = ngb.predict(X_test)\nY_dists = ngb.pred_dist(X_test)\n\n# test Mean Squared Error\ntest_MSE = mean_squared_error(Y_preds, Y_test)\nprint(\'Test MSE\', test_MSE)\n\n# test Negative Log Likelihood\ntest_NLL = -Y_dists.logpdf(Y_test).mean()\nprint(\'Test NLL\', test_NLL)\n```\n\nDetails on available distributions, scoring rules, learners, tuning, and model interpretation are available in our [user guide](https://stanfordmlgroup.github.io/ngboost/intro.html), which also includes numerous usage examples and information on how to add new distributions or scores to NGBoost.\n\n## License\n\n[Apache License 2.0](https://github.com/stanfordmlgroup/ngboost/blob/master/LICENSE).\n\n## Reference\n\nTony Duan, Anand Avati, Daisy Yi Ding, Khanh K. Thai, Sanjay Basu, Andrew Y. Ng, Alejandro Schuler. 2019.\nNGBoost: Natural Gradient Boosting for Probabilistic Prediction.\n[arXiv](https://arxiv.org/abs/1910.03225)\n',
|
|
22
22
|
'author': 'Stanford ML Group',
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|