Skip to main content

A package for Script Table Operator that applies set theory to machine learning in Python.

Project description

tdstone2 Package

Overview

The tdstone2 package is designed to simplify the operationalization of Python code for data analysis and machine learning on the Teradata Vantage system. It leverages the massive parallel processing architecture of Teradata Vantage to run hundreds of Python scripts across hundreds of data partitions. This approach enables the industrialization, lineage, and reproducibility of millions of custom models while minimizing data movement.

Features

  • Hyper-segmented Model Deployment: Deploy scikit-learn pipelines or custom Python functions across segmented datasets for parallel execution.
  • Model Lineage and Reproducibility: Automatically track the lineage of models and ensure reproducibility across different data partitions.
  • Efficient Data Handling: Minimize data movement by leveraging Teradata's parallel processing capabilities to execute models directly on the database.

Installation

To install tdstone2, use pip:

pip install tdstone2

Ensure you have access to a Teradata Vantage system and the necessary credentials to connect and execute queries.

Usage

Hyper-segmented Model Deployment

3.1 Engineering of the Scikit-learn Classifier Pipeline

from sklearn.preprocessing import StandardScaler
from sklearn.ensemble import RandomForestClassifier

# Example usage
steps_classifier = [
    ('scaler', StandardScaler()),
    ('classifier', RandomForestClassifier(max_depth=5, n_estimators=95))
]

3.2 Deployment of the Scikit-learn Pipeline

from tdstone2.tdshypermodel import HyperModel
from tdstone2.tdstone import TDStone

sto = TDStone(schema_name=Param['database'], SEARCHUIFDBPATH=Param['user'])
model_parameters = {
    "target": 'Y2',
    "column_categorical": ['flag', 'Y2'],
    "column_names_X": ['X1', 'X2', 'X3', 'X4', 'X5', 'X6', 'X7', 'X8', 'X9', 'flag']
}

model = HyperModel(
    tdstone=sto,
    metadata={'project': 'test'},
    skl_pipeline_steps=steps_classifier,
    model_parameters=model_parameters,
    dataset=tdml.in_schema(Param['database'], 'dataset_00'),
    id_row='ID',
    id_partition='Partition_ID',
    id_fold='FOLD',
    fold_training='train',
    convert_to_onnx=False, # <-- set to True if you want to get the ONNX version of your trained models
    store_pickle=True, # <-- to store your full object in pickle format
)

# Model deployment outputs

3.3 Local Execution for Validation/Debugging

exec(code_and_data['code'])
local_model = MyModel(**code_and_data['arguments'])
df_local = code_and_data['data']
df_local['flag'] = df_local['flag'].astype('category')
df_local['Y2'] = df_local['Y2'].astype('category')
local_model.fit(code_and_data['data'])
local_model.score(code_and_data['data'])

Execution of the Deployed Hypermodel

4.1 Models Training

model.train()
# Outputs: Trained models are inserted into the specified repository

This training operation launches as many training there are data partitions identified by the id_partition column list, and belonging to the training FOLD.

4.2 Model Scoring

model.score()
# Outputs: Model scores are inserted into the specified scores table

This runs the scoring on all the data, using the latest model available for the corresponding data partition.

Reuse of the Hyper-segmented Model

2. Retrieve the Hyper-segmented Model

sto = TDStone(schema_name=Param['database'], SEARCHUIFDBPATH=Param['user'])
sto.list_hyper_models()
# Outputs: List of hyper models with their metadata

id = '0286d259-ecde-4cd0-ae4a-bcb3191383d1'  # Example model ID
existing_model = HyperModel(tdstone=sto)
existing_model.download(id=id)

Note that the model is not actually downloaded, but this just establish a connection between the model hosted in Vantage and the python client.

3. Update the Training

existing_model.train()
# Outputs: Updated trained models are inserted into the specified repository

4. Update the Scoring

existing_model.score()
# Outputs: Updated scores are inserted into the specified scores table

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

tdstone2-0.1.7.1-py3-none-any.whl (116.1 kB view details)

Uploaded Python 3

File details

Details for the file tdstone2-0.1.7.1-py3-none-any.whl.

File metadata

  • Download URL: tdstone2-0.1.7.1-py3-none-any.whl
  • Upload date:
  • Size: 116.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.3

File hashes

Hashes for tdstone2-0.1.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6a98a7330ed878ba6e37aef48c2d1540a9ca828c3acc82db6b3c75ac790dcf15
MD5 c10fc2014068a431f865da7a161bb984
BLAKE2b-256 c2632650967316bd3c430244a1bb7c8e8413234188c90384baa86ff27c50d691

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