Skip to main content

Restructuring of ddop

Project description

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
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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ddop2-0.0.22.tar.gz (4.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ddop2-0.0.22-py3-none-any.whl (4.2 MB view details)

Uploaded Python 3

File details

Details for the file ddop2-0.0.22.tar.gz.

File metadata

  • Download URL: ddop2-0.0.22.tar.gz
  • Upload date:
  • Size: 4.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.4

File hashes

Hashes for ddop2-0.0.22.tar.gz
Algorithm Hash digest
SHA256 1f603cd0dd2ca16ae9f836ce30754fb8a33b922c010e8f79ab351378d89b6475
MD5 7815e82a5b43432a2ce127620f03d26b
BLAKE2b-256 576f694d3552f4e3713aa8f72d2db1b45db66aab1c338910f27acd9e9f46971b

See more details on using hashes here.

File details

Details for the file ddop2-0.0.22-py3-none-any.whl.

File metadata

  • Download URL: ddop2-0.0.22-py3-none-any.whl
  • Upload date:
  • Size: 4.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.4

File hashes

Hashes for ddop2-0.0.22-py3-none-any.whl
Algorithm Hash digest
SHA256 6cc9a0f18e2cfe45bfc482e81b03c75e8336cee4c5a3874ac73255bbc8df202f
MD5 36bb5251875cfee7a646604e821f9084
BLAKE2b-256 36573584fea910396c2c248000cf3787745e8a80fc4020dd8435812a79a68478

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page