Welcome to ddop
ddop is a Python library for data-driven operations management. The
goal of ddop is to provide well-established data-driven operations
management tools within a programming environment that is accessible and
easy to use even for non-experts. At the current state ddop contains
well known data-driven newsvendor models, a set of performance metrics
that can be used for model evaluation and selection, as well as datasets
that are useful to quickly illustrate the behavior of the various
algorithms implemented in ddop or as benchmark for testing new models.
Through its consistent and easy-to-use interface one can run and compare
provided models with only a few lines of code.
Install
ddop is available via PyPI using:
pip install ddop2
Quickstart
ddop provides a varity of newsvendor models. The following example
shows how to use one of these models for decision making. It assumes a
very basic knowledge of data-driven operations management practices.
As first step we initialize the model we want to use. In this example
RandomForestWeightedNewsvendor.
from ddop2.newsvendor import RandomForestWeightedNewsvendor
rf_nv = RandomForestWeightedNewsvendor(cu=2, co=1)
2023-08-09 22:10:47.225307: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-08-09 22:10:48.239997: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
A model can take a set of parameters, each describing the model or the optimization problem it tries to solve. Here we set the underage costs cu to 2 and the overage costs co to 1.
As next step we load the Yaz Dataset and split it into train and test set.
from ddop2.datasets import load_yaz
from sklearn.model_selection import train_test_split
X, y = load_yaz(one_hot_encoding=True, return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, shuffle=False, random_state=0)
After the model is initialized, the fit method can be used to learn a
decision model from the training data X_train, y_train.
rf_nv.fit(X_train, y_train)
<style>#sk-container-id-1 {color: black;background-color: white;}#sk-container-id-1 pre{padding: 0;}#sk-container-id-1 div.sk-toggleable {background-color: white;}#sk-container-id-1 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-1 label.sk-toggleable__label-arrow:before {content: "▸";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-1 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-1 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-1 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: "▾";}#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-1 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-1 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-1 div.sk-parallel-item::after {content: "";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-serial::before {content: "";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-1 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-1 div.sk-item {position: relative;z-index: 1;}#sk-container-id-1 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-1 div.sk-item::before, #sk-container-id-1 div.sk-parallel-item::before {content: "";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-1 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-1 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-1 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-1 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-1 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-1 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-1 div.sk-label-container {text-align: center;}#sk-container-id-1 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-1 div.sk-text-repr-fallback {display: none;}</style>RandomForestWeightedNewsvendor(co=1, cu=2)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
RandomForestWeightedNewsvendor(co=1, cu=2)
We can then use the predict method to make a decision for new data samples.
rf_nv.predict(X_test)
array([[ 5, 4, 14, ..., 23, 35, 22],
[ 6, 6, 11, ..., 26, 37, 23],
[ 8, 8, 16, ..., 35, 55, 40],
...,
[ 5, 6, 12, ..., 23, 41, 25],
[ 6, 6, 13, ..., 24, 41, 32],
[ 8, 9, 15, ..., 34, 57, 42]])
To get a representation of the model’s decision quality we can use the
score function, which takes as input X_test and y_test. The
score function makes a decision for each sample in X_test and
calculates the negated average costs with respect to the true values
y_test and the overage and underage costs.
rf_nv.score(X_test, y_test)
-6.859375000000001
Metadata
Release files for ddop2 0.0.22
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ddop2-0.0.22.tar.gz | 4.2 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ddop2-0.0.22-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.4 MB
Release files / ddop2-0.0.22.tar.gz
| Download URL | ddop2-0.0.22.tar.gz |
|---|---|
| Size | 4.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1f603cd0dd2ca16ae9f836ce30754fb8a33b922c010e8f79ab351378d89b6475
|
|
BLAKE2b-256 checksum How to use checksums |
576f694d3552f4e3713aa8f72d2db1b45db66aab1c338910f27acd9e9f46971b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.4
|
Release files / ddop2-0.0.22-py3-none-any.whl
| Download URL | ddop2-0.0.22-py3-none-any.whl |
|---|---|
| Size | 4.2 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6cc9a0f18e2cfe45bfc482e81b03c75e8336cee4c5a3874ac73255bbc8df202f
|
|
BLAKE2b-256 checksum How to use checksums |
36573584fea910396c2c248000cf3787745e8a80fc4020dd8435812a79a68478
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.4
|