Skip to content

アプリケーション内で をクリックすると、お使いのDataRobotバージョンに関する全プラットフォームドキュメントにアクセスできます。

Custom model components

To create and upload a custom model, you need to define two components—the model’s content and an environment where the model’s content will run:

  • The model content is code written in Python or R. DataRobotで正しく解析するには、コードは特定の条件に従う必要があります。 The model artifact's structure should match the library used by the model. In addition, it should use the appropriate custom hooks for Python, R, and Java models. 任意で、アップロードしてモデルのコードとともに使用するファイルを追加できます(たとえば、カスタムモデルにテキスト前処理が含まれている場合、別のファイルに辞書を追加したい場合があります)。

  • The model environment is defined using a Docker file and additional files that will allow DataRobot to build an image where the model will run. さまざまなビルトイン環境があります。ユーザーはLinuxパッケージをインストールする必要がある場合にのみ独自の環境を構築する必要があります。 For more detailed information, see the section on custom model environments.

At a high level, the steps to define a custom model with these components include:

  1. Define and test model content locally (i.e., on your computer).

  2. Optionally, create a container environment where the model will run.

  3. Upload the model content and environment (if applicable) into DataRobot.

モデルコンテンツ

カスタムモデルを定義するには、以下のテーブルにリストされているファイルを含むローカルフォルダーを作成します(詳細については表を参照してください)。

ヒント

To ensure your assembled custom model folder has the correct contents, you can find examples of these files in the DataRobot model template repository on GitHub.

ファイル 説明 必須
Model artifact file
or
custom.py/custom.R file
Provide a model artifact and/or a custom code file.
  • Model artifact: a serialized model artifact with a file extension corresponding to the chosen environment language.
  • Custom code: custom capabilities implemented with hooks (or functions) that enable DataRobot to run the code and integrate it with other capabilities.
可能
model-metadata.yaml 入力/出力データ要件を含むモデルのメタデータを説明するファイル。 You can supply a schema that can then be used to validate the model when building and training a blueprint. A schema lets you specify whether a custom model supports or outputs:
  • Certain data types
  • Missing values
  • Sparse data
  • A certain number of columns
Required when a custom model outputs non-numeric data. 提供しない場合、デフォルトスキーマが使用されます。
requirements.txt 基本環境に追加するPythonまたはRパッケージのリスト。 This list pre-installs Python or R packages that the custom model is using but are not a part of the base environment いいえ
追加ファイル モデルで使用するその他のファイル(たとえば、custom.py内で使用するヘルパー関数を定義するファイル)。 いいえ

Pythonでは、バージョン(行に1つのパッケージ)でパッケージのリストを提供します。 例:

numpy>=1.16.0, <1.19.0
pandas==1.1.0
scikit-learn==0.23.1
lightgbm==3.0.0
gensim==3.8.3
sagemaker-scikit-learn-extension==1.1.0 

Rでは、バージョン(行に1つのパッケージ)でパッケージのリストを提供します。 例:

dplyr
stats 

Model code

To define a custom model using DataRobot’s framework, your custom model should include a model artifact corresponding to the chosen environment language, custom code in a custom.py (for Python models) or custom.R (for R models) file, or both. If you provide only the custom code (without a model artifact), you must use the load_model hook. The following hooks can be used in your custom code:

フック(機能) 非構造化 / 構造化 目的
init() 両方 Initialize the model run by loading model libraries and reading model files. This hook is executed only once at the beginning of a run.
load_model() 両方 Load all supported and trained objects from multiple artifacts, or load a trained object stored in an artifact with a format not natively supported by DataRobot. This hook is executed only once at the beginning of a run.
read_input_data() Structured Customize how the model reads data; for example, with encoding and missing value handling.
transform() Structured Define the logic used by custom transformers and estimators to generate transformed data.
score() Structured 予測を生成するカスタム推定器で使用するロジックを定義します。
score_unstructured 非構造化 Define the output of a custom estimator and returns predictions on input data. 変換モデルにこのフックは使用しないでください。
post_process() Structured Define the post processing steps applied to the model's predictions.

備考

These hooks are executed in the order listed.

For more information on defining a custom model's code, see the hooks for structured custom models or unstructured custom models.

Model metadata

メタデータを定義するには、model-metadata.yamlファイルを作成して、モデルまたはモデルのディレクトリのトップレベルに置きます。 The file specifies additional information about a custom model.

モデル環境

カスタムモデルが実行される環境を定義するための複数のオプションがあります。 以下を実行することが可能です。

  • Choose from a variety of drop-in environments.

  • Modify a drop-in environment to include missing Python or R packages by specifying the packages in the model's requirements.txt file. 提供された場合、requirements.txtをモデルコンテンツ内のcustom.pyまたはcustom.Rと共にアップロードする必要があります。 モデルコンテンツにサブフォルダーが含まれている場合、上部フォルダーに置く必要があります。

  • Build a custom environment if you need to install Linux packages.

    カスタムモデルを作成する場合、使用するカスタム環境にはモデルコンテンツとの互換性がある必要があります(モデルのランタイム環境が定義されます)。 To ensure you follow the compatibility guidelines:

    • Use or modify the custom environment templates that are compatible with your custom models.

    • Reference the guidelines for building your own environment. 環境テンプレートを使用することをお勧めします。特定のユースケース(DRUMを使用せず、独自の予測サーバーを実装する場合など)を除き、独自の環境を構築することは推奨されません。


更新しました March 9, 2023
Back to top