3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

DataRobot Appテンプレート活用:不正検知から営業予測アプリへの変更事例

Posted at

         hata01.png

DataRobotで、製造業およびヘルスケア業界のお客様を中心に担当しているシニアデータサイエンティストの畑 遼介です。

以前DataRobot社のブログで、生成AIと予測AIを組み合わせたAIアプリケーションであるDataRobotと生成AIで実現する!次世代予測コンテンツジェネレーターという内容を投稿しました。

しかしながら、皆様のデータに適用し利用するためには、開発が必要となります。ここでの開発には、高度な専門知識が求められるという印象があるかもしれません。しかし、DataRobotのAppテンプレートを活用すれば、比較的容易に業務に貢献するAIアプリケーションを構築できます。

本記事では、予測AIの出力を生成AIが解説する「予測コンテンツジェネレータ」というDataRobotアプリテンプレートのカスタマイズ容易性を、具体的な変更事例を通じて解説します。本稿では一例として、「不正検知」用アプリテンプレートを、「営業案件の確度予測」を支援するアプリケーションへ変更するプロセスを紹介します。DataRobot Appテンプレートの潜在能力と、そのカスタマイズの平易性をご理解いただければ幸いです。

カスタマイズの意義と平易性

DataRobotのAppテンプレートは、特定の業務に合わせたアプリケーションを迅速に構築するための基盤を提供します。これらのテンプレートは、高い柔軟性を持ち、容易にカスタマイズが行える点が大きな特長です。

今回の事例では、DataRobotの予測AIから出力される予測の説明に基づき、生成AIが予測結果の理由を解釈します。これは、現場の担当者がAIの予測結果を理解し活用するために重要です。予測の根拠が明確でなければ、AIの判断に対する信頼が得られず、現場への導入が進まない事態を防ぐ目的があります。

その一例として、私たちが提供する「予測コンテンツジェネレータ」に含まれる、金融取引の不正監視を目的とした「Fraud Monitor Officer」を、営業部門がリード顧客の契約確度を評価し戦略的な意思決定を支援する「Opportunity Judging Helper」へと改修しました。このカスタマイズは想定以上に容易に実施できました。以下にその詳細を記載します。

主な変更点の概要

hata02.png

hata03.png

要点を把握すれば、アプリケーションの変更は容易に行えます。具体的には、notebooksフォルダ内に格納されている特定のNotebookを一つ選択し編集します。今回はtrain_model_fraud.ipynbを編集する想定で説明します。1〜3については上記のフォルダの中のnotebooksを編集しました。

主要な変更ポイント:

1.アプリケーション基本設定のカスタマイズ:

  • ページタイトルや説明文を、新たな用途に合わせて更新します。
  • レコード識別子を、例えば「Transaction ID」から「社名」のように変更します。
  • 生成AIへの指示(プロンプト)も、営業シーンに合わせて調整します。
  • 予測結果のラベルや説明も、「不正の疑いあり/なし」から「契約確度 高/低」のように具体的に記述します。

2. 使用データセット/登録名称の変更:

  • データセット名やファイルパスを、実際に使用する営業案件のデータに差し替えます。

3. 予測対象(ターゲット変数)の変更:

  • 予測対象項目を、「SARの発生有無」から「契約成立」へと変更します。

4. 読み込むNotebookのパス設定変更:

  • アプリテンプレート実行時に利用するNotebookのパスを、編集したファイルに合わせて変更します。

具体的な変更箇所

実際にコードのどの部分を変更したのか、具体的に説明します。

1. アプリケーション基本設定のカスタマイズ:app_ds_settingsの変更 (Notebooks内)

AppDataScienceSettingsは、アプリケーションの外観、動作、生成AIとの連携方法などを定義する設定群です。この設定群を調整することで、アプリケーションの印象は大きく変わります。

変更前 (一例:不正検知アプリの場合)

app_ds_settings = AppDataScienceSettings(
    page_title="Fraud Monitor Officer",
    # ... (中略) ...
    record_identifier={
        "column_name": "record_id",
        "display_name": "Transaction ID",
    },
    text_explanation_feature="csrNotes",
    target_probability_description="the likelihood of fraudulent activity",
    email_prompt=textwrap.dedent("""\
        Draft an email to a fraud analyst that the transaction was {prediction_label}.
        The email should refer to the transaction id {selected_record} and contain a subject line and body.
        Keep the email tone {tone}. Keep the length {verbosity}. Try not to use many emojis.

        Incorporate the following list of factors that influenced the determination:

        {rsp}"""),
    outcome_details=[  # Each item should be a target value with it's corresponding label and optional description
        OutcomeDetail(
            prediction=0,
            label="Non-fraudulent",
            description="The transaction is not suspicious and does not require further investigation.",
        ),
        OutcomeDetail(
            prediction=1,
            label="Suspicious activity",
            description="The transaction requires a detailed review by the fraud investigative analyst.",
        ),
    ],
    # ... (中略) ...
    system_prompt=textwrap.dedent("""\
        You are a fraud monitoring specialist named Bob...
        ...decide if a Suspicious Acitivty Report (SAR) should be filed."""),
    # ... (その他の設定)
)

変更後 (営業案件予測アプリへカスタマイズ)

app_ds_settings = AppDataScienceSettings(
    page_title="Opportunity Judging Helper", # 変更: アプリの目的に合わせてタイトルを更新
    # ... (中略) ...
    record_identifier={
        "column_name": "社名", # 変更: 識別子を日本語の「社名」に変更
        "display_name": "社名", # 変更: 表示名も「社名」に更新
    },
    text_explanation_feature=None,  # 変更: テキスト特徴量の説明が不要な場合はNoneに設定
    target_probability_description="the likelihood of contract closure for lead",  # 変更: ターゲットの説明も更新
    email_prompt = textwrap.dedent("""\
        Draft an email to the sales team regarding the predicted likelihood of contract closure for lead {selected_record}.
        The predicted outcome is {prediction_label}.
        The email should contain a subject line and body.
        Keep the email tone {tone}. Keep the length {verbosity}. Try not to use many emojis.

        The following factors influenced this prediction:

        {rsp}"""), # プロンプトを変更
    outcome_details = [  # Each item should be a target value with it's corresponding label and optional description
        OutcomeDetail(
            prediction=0,
            label="Low likelihood of closing",
            description="Based on the analysis, this lead has a low probability of resulting in a closed contract and may require nurturing or disqualification.",
        ),
        OutcomeDetail(
            prediction=1,
            label="High likelihood of closing",
            description="Based on the analysis, this lead has a high probability of resulting in a closed contract and warrants proactive engagement.",
        ),
    ], # 説明を変更
    # ... (中略) ...
    system_prompt=textwrap.dedent("""\
        You are a sales performance analyst named Ai...
        ...decide on the appropriate sales strategy and level of engagement.
        Output by Japansese."""), # 変更: AIへの指示を営業向けに更新。日本語出力の指示も有効に作用します。
    # ... (tones, verbosity, model_specなどは、必要に応じて調整、または既存設定を維持)
)

解説:

  • page_title: アプリケーションのタイトルを用途に合わせて変更します。
  • record_identifier: データを特定するキー項目とその表示名を指定。日本語の使用も問題ありません。
  • text_explanation_feature: テキストデータの特徴量説明が不要な場合は None に設定します。
  • target_probability_description: 予測確率が何を示すか、ユーザーに分かりやすく記述します。
  • email_prompt: このプロンプトは、既存のプロンプト、対象データ、期待する内容を生成AIに入力することで、適切な形に書き換えられました。自ら追加して更に情報を持たせるとより良くなると思います。
  • outcome_details: 同様に、ここでの説明文も、関連データと概要を生成AIに入力し生成しました。
  • system_prompt: AIの役割や全体的な指示内容です。同様に、システムプロンプトも、関連データと期待する役割を生成AIに指示し生成しました。ただ、日本語で出力して欲しいという点だけを追加しました。

2. 使用データセットと登録名称の変更
アプリケーションが読み込むデータと、関連する名称を変更します。

変更前

use_case_name = f"NBO Fraud [{project_name}]"
use_case_description = "Suspicious Activity Monitoring"

dataset_name = f"NBO Fraud Training Data [{project_name}]"
file_path = "assets/fraud_monitoring_training.csv"

変更後

use_case_name = f"NBO Opp [{project_name}]" # 追加: ユースケース名を変更
use_case_description = "Suspicious Activity Monitoring" # ユースケースの説明も適宜変更を推奨

dataset_name = f"NBO Opp Training Data [{project_name}]" # 変更: データセット名を更新
file_path = "assets/lead_scoring_demo_data_train.csv" # 変更: 使用するCSVファイルのパスを指定

解説:

  • use_case_name/dataset_name: 主に名称の変更です。デフォルト設定でも動作に支障はありませんが、識別性を高めるために変更を推奨します。
  • file_path: 学習に使用するトレーニングデータのファイルパスを、実際のデータに合わせて指定します。使用するデータを変更する場合は、このパスを必ず更新してください。

3. 予測対象(ターゲット変数)の変更:AutoPilot実行引数
AIモデルに何を予測させるか(ターゲット変数)を指定します。

変更前

autopilotrun_args = AutopilotRunArgs(
    # ... (中略) ...
    analyze_and_model_config=AnalyzeAndModelArgs(
        metric="LogLoss", mode="quick", target="SAR", positive_class=1
    ),
    # ... (中略) ...
)

変更後

autopilotrun_args = AutopilotRunArgs(
    # ... (中略) ...
    analyze_and_model_config=AnalyzeAndModelArgs(
        metric="LogLoss", mode="quick", target="契約成立", positive_class=1 # 変更: 「契約成立」を予測対象として指定
    ),
    # ... (中略) ...
)

解説:

  • target: データセット内でAIに予測させたい列名を指定します。AIは指定された目的変数を理解し、学習を開始します。ここでは学習ターゲットのみを変更していますが、必要に応じて他の高度なオプションも設定可能です。

4. 読み込むNotebookのパス設定 (infra/setting_main.py)
最後に、編集したNotebookをアプリケーションが読み込むように設定します。

hata04.png

hata05.png

infraディレクトリ内のsetting_main.pyを開き、model_training_nbで指定されているNotebookのファイル名を、実際に編集したファイル名に変更します(必要な場合)。

変更前

model_training_nb = PROJECT_ROOT / "notebooks" / "train_model_nbo.ipynb"

変更後

model_training_nb = PROJECT_ROOT / "notebooks" / "train_model_fraud.ipynb"# fraudを編集した場合。編集したNotebooksの名前を変えた場合には、"YOUR_NOTEBOOKS_FILENAME.ipynb" のように自分の編集したファイル名に変更

解説:
デフォルトのNotebooks(train_model_nbo.ipynb)を利用して、ファイル名を変更せずに編集した場合は、ここでの設定変更は不要です。

まとめと今後の展望

本記事で示したように、DataRobotのAppテンプレートのカスタマイズは直感的であり、比較的容易に実施できます。高度なプログラミングスキルを必ずしも要さず、設定ファイル(Pythonコード)の一部編集により、本格的なAIアプリケーションを構築できる点は、大きな利点です。

今回は、一例として「不正検知」から「営業案件予測」という異なるユースケースへの適用を紹介しましたが、この柔軟性を活かし、多種多様なビジネスニーズに対応するカスタムアプリケーション開発が期待されます。

今回編集したものはこちらで確認できます。

皆様もDataRobotのAppテンプレートを活用し、ビジネスを加速させる独自のAIアプリケーション開発をご検討ください。その利便性と機能性に触れていただければ幸いです。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?