略過導覽

Machine Learning Samples

Sample: OJ Sales Simulated Data

OJ Sales Many Models Forecasting Retail Sales Grocery

此資料集衍生自 Dominick 的 OJ 資料集,內含額外的模擬資料,旨在提供可輕鬆於 Azure Machine Learning 上同時訓練數千個模型的資料集。

該資料包含 121 週內每週的冷藏柳橙汁銷售額。 內含 3,991 間店家,每間店有 3 種柳橙汁品牌,以便訓練 11,973 個模型。

如需原始資料集的詳細資訊,請參閱此連結。 您也可以存取原始資料集

通知

Microsoft 係依「現況」提供 Azure 開放資料集。 針對 貴用戶對資料集的使用,Microsoft 不提供任何明示或默示的擔保、保證或條件。 在 貴用戶當地法律允許的範圍內,針對因使用資料集而導致的任何直接性、衍生性、特殊性、間接性、附隨性或懲罰性損害或損失,Microsoft 概不承擔任何責任。

此資料集是根據 Microsoft 接收來源資料的原始條款所提供。 資料集可能包含源自 Microsoft 的資料。

Access

Available inWhen to use
Azure Notebooks

Quickly explore the dataset with Jupyter notebooks hosted on Azure or your local machine.

Azure Databricks

Use this when you need the scale of an Azure managed Spark cluster to process the dataset.

Preview

WeekStarting Store Brand Quantity Advert Price Revenue
10/1/1992 12:00:00 AM 3023 minute.maid 15495 1 1.99 30835.05
10/1/1992 12:00:00 AM 1766 minute.maid 11111 1 2.12 23555.32
10/1/1992 12:00:00 AM 3075 minute.maid 10715 1 2.23 23894.45
10/1/1992 12:00:00 AM 716 minute.maid 11292 1 2.04 23035.68
10/1/1992 12:00:00 AM 3231 minute.maid 12811 1 2.63 33692.93
10/1/1992 12:00:00 AM 1067 minute.maid 14741 1 2.3 33904.3
10/1/1992 12:00:00 AM 1260 minute.maid 18689 1 1.91 35695.99
10/1/1992 12:00:00 AM 1368 minute.maid 18334 1 2.53 46385.02
10/1/1992 12:00:00 AM 1639 minute.maid 16272 1 2.63 42795.36
10/1/1992 12:00:00 AM 2983 minute.maid 19797 1 1.95 38604.15
Name Data type Unique Values (sample) Description
Advert int 1

指出該週是否有該柳橙汁廣告的值

  • 0:沒有廣告
  • 1:有廣告
Brand string tropicana
dominicks

柳橙汁品牌

Price double 2.6
2.09

柳橙汁的價格 (美元)

Quantity int 10939
11638

該週售出的柳橙汁數量

Revenue double 36036.0
33264.0

該週的柳橙汁銷售額 (美元)

Store int 3767
2868

售出柳橙汁的店家數

WeekStarting timestamp 1991-01-24 00:00:00
1990-09-06 00:00:00

指出銷售額所屬週次的日期

Select your preferred service:

Azure Notebooks

Azure Databricks

Azure Notebooks

Package: Language: Python
In [ ]:
from azureml.core.workspace import Workspace
ws = Workspace.from_config()
datastore = ws.get_default_config()
In [ ]:
from azureml.opendatasets import OjSalesSimulated

Read data from Azure Open Datasets

In [ ]:
# Create a Data Directory in local path
import os

oj_sales_path = "oj_sales_data"

if not os.path.exists(oj_sales_path):
    os.mkdir(oj_sales_path)
In [ ]:
# Pull all of the data
oj_sales_files = OjSalesSimulated.get_file_dataset()

# or pull a subset of the data
oj_sales_files = OjSalesSimulated.get_file_dataset(num_files=10)
In [ ]:
oj_sales_files.download(oj_sales_path, overwrite=True)

Upload the individual datasets to Blob Storage

We upload the data to Blob and will create the FileDataset from this folder of csv files.

In [ ]:
target_path = 'oj_sales_data'

datastore.upload(src_dir = oj_sales_path,
                target_path = target_path,
                overwrite = True, 
                show_progress = True)

Create the file dataset

We need to define the path of the data to create the FileDataset.

In [ ]:
from azureml.core.dataset import Dataset

ds_name = 'oj_data'
path_on_datastore = datastore.path(target_path + '/')

input_ds = Dataset.File.from_files(path=path_on_datastore, validate=False)

Register the file dataset to the workspace

We want to register the dataset to our workspace so we can call it as an input into our Pipeline for forecasting.

In [ ]:
registered_ds = input_ds.register(ws, ds_name, create_new_version=True)
named_ds = registered_ds.as_named_input(ds_name)

Azure Databricks

Package: Language: Python
In [1]:
# This is a package in preview.
# You need to pip install azureml-opendatasets in Databricks cluster. https://docs.microsoft.com/en-us/azure/data-explorer/connect-from-databricks#install-the-python-library-on-your-azure-databricks-cluster
# Download or mount OJ Sales raw files Azure Machine Learning file datasets.
# This works only for Linux based compute. See https://docs.microsoft.com/en-us/azure/machine-learning/service/how-to-create-register-datasets to learn more about datasets.

from azureml.opendatasets import OjSalesSimulated

ojss_file = OjSalesSimulated.get_file_dataset()
ojss_file
In [2]:
ojss_file.to_path()
In [3]:
# Download files to local storage
import os
import tempfile

mount_point = tempfile.mkdtemp()
ojss_file.download(mount_point, overwrite=True)
In [4]:
# Mount files. Useful when training job will run on a remote compute.
import gzip
import struct
import pandas as pd
import numpy as np

# load compressed OJ Sales Simulated gz files and return numpy arrays
def load_data(filename, label=False):
    with gzip.open(filename) as gz:
        gz.read(4)
        n_items = struct.unpack('>I', gz.read(4))
        if not label:
            n_rows = struct.unpack('>I', gz.read(4))[0]
            n_cols = struct.unpack('>I', gz.read(4))[0]
            res = np.frombuffer(gz.read(n_items[0] * n_rows * n_cols), dtype=np.uint8)
            res = res.reshape(n_items[0], n_rows * n_cols)
        else:
            res = np.frombuffer(gz.read(n_items[0]), dtype=np.uint8)
            res = res.reshape(n_items[0], 1)
    return pd.DataFrame(res)
In [5]:
import sys
mount_point = tempfile.mkdtemp()
print(mount_point)
print(os.path.exists(mount_point))
print(os.listdir(mount_point))

if sys.platform == 'linux':
  print("start mounting....")
  with ojss_file.mount(mount_point):
    print(os.listdir(mount_point))  
    train_images_df = load_data(os.path.join(mount_point, 'train-tabular-oj-ubyte.gz'))
    print(train_images_df.info())
In [6]: