MLPredictor - グローバル (非推奨)
MLPredictor API は 予測インテリジェンス による予測のユーティリティメソッドを提供します。
MLPredictor API には 予測インテリジェンス プラグイン (com.glide.platform_ml) が必要です。この API は sn_ml 名前空間内で提供されます。
このクラスには、入力データから予測結果を取得するために必要なすべてのメソッドが含まれています。
MLPredictor - MLPredictor()
新しい MLPredictor オブジェクトをインスタンス化します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
次の例は、ビジネスルールで MLPredictor オブジェクトを使用して予測後の最終値を記録する方法を示しています。
function executeRule(current, previous /*null when async*/) {
var predictor = new MLPredictor();
predictor.recordFinalValuesInPredictionResults(current, "On close");
}(current, previous);
MLPredictor - applyPrediction(GlideRecord now_GR, アレイ solutions)
指定されたソリューションのアレイから指定されたレコードに予測値を設定します。
| 名前 | タイプ | 説明 |
|---|---|---|
| now_GR | GlideRecord | 予測されたソリューションのアレイを適用するレコード。 |
| solutions | アレイ | GlideRecord に関連付けられる、指定されたソリューションオブジェクト。 |
| タイプ | 説明 |
|---|---|
| なし |
次の例は、ビジネスルールでの applyPrediction() メソッドの使用方法を示しています。
(function executeRule(current, previous /*null when async*/) {
var mlPredictor = new MLPredictor();
//Get the list of active solutions for the glide record table
var solutions = mlPredictor.findActiveSolutionsForRecord(current);
//Run prediction and apply predicted value to the record
mlPredictor.applyPrediction(current, solution);
})(current, previous);
MLPredictor - applyPredictionForSolution(GlideRecord now_GR, オブジェクト solution)
指定された分類のソリューションから取得した予測値を、指定された GlideRecord に適用します。
GlideRecord の各ソリューションについて、このメソッドを呼び出して結果を予測し、その結果でインシデントのフィールド値を設定します。
| 名前 | タイプ | 説明 |
|---|---|---|
| now_GR | GlideRecord | 予測を実行して結果を適用する対象の値を含む GlideRecord オブジェクト。 |
| solution | オブジェクト | 実行する分類のソリューションオブジェクト。 |
| タイプ | 説明 |
|---|---|
| ブーリアン | 予測が成功した場合は True、失敗した場合はエラー。 |
このテンプレートを使用するには、インシデントベース予測 (テンプレート) ビジネスルールをコピーし、新しいレコードを [アクティブ] にして、コメントされた指示に従って solutionNames 変数を初期化します。
(function executeRule(current, previous /*null when async*/) {
var solutionNames = ["solution1", "solution2", ...];
/* For domain separation (MSP) use case */
// var solutionNames;
// if (current.sys_domain == "A")
// solutionNames = ["solution_A1", "solution_A2", ...];
// else if (current.sys_domain == "B")
// solutionNames = ["solution_B1", "solution_B2", ...];
// else
// ...
var predictor = new MLPredictor();
var info = "";
solutionNames.forEach(function(solutionName) {
var solution = predictor.findActiveSolution(solutionName);
if (!solution)
return;
/* The next line of code does the prediction and updates the current record. */
predictor.applyPredictionForSolution(current, solution);
/* If no prediction is done, do not build the prediction info message. */
if (!predictor.applyPredictionForSolution(current, solution))
return;
/* If user doesn't have 'itil' role, we don't build prediction info message. */
if (!gs.hasRole('itil'))
return;
/* Building prediction info message */
var fieldName = solution.getPredictedField();
var fieldLabel = current.getElement(fieldName).getED().getLabel();
var predictedDisplayValue = current.getDisplayValue(fieldName);
var msg = gs.getMessage("Predicted {0} for {1}.", [predictedDisplayValue, fieldLabel]);
if (info.length > 0)
info += " ";
info += msg;
});
/* Print out prediction info message on screen. */
if (info.length > 0) {
var incidentUrl = "<a href='"+current.getLink()+"'>"+current.number+":</a>";
gs.addInfoMessage(incidentUrl + " " + info);
}
})(current, previous);
MLPredictor - findActiveSolution(文字列 solutionName)
ソリューションオブジェクトを取得します。
このメソッドは、ml_solution 定義とソリューションがアクティブな場合にのみソリューションを返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| solutionName | 文字列 | ml_solution レコードの名前。 |
| タイプ | 説明 |
|---|---|
| オブジェクト | ml_solution の定義とソリューションがアクティブな場合は指定された solutionName のソリューションオブジェクト、アクティブでない場合は null。 |
この例では、ハードコードされた値を取得して、指定された機械学習モデルに渡します。結果と信頼性の変数を使用して、値やその他のビジネスロジックを設定できます。
var solutionName = 'ml_incident_assignment';
var shortDescriptionValue = "Unable to connect!"
var input = {
short_description : shortDescriptionValue
};
var MLP = new MLPredictor();
var solution = MLP.findActiveSolution(solutionName);
var predictedOutcome = solution.predictText(input);
var outcome = predictedOutcome.predictedValue();
var confidence = predictedOutcome.confidence();
gs.info("Predicted value: " + outcome)
gs.info("Confidence: " + confidence)
出力:
DxC_ML:
******* Finished Prediction********* *** Script: Predicted value: Software *** Script:
Confidence: 80.78079080096245
MLPredictor - findActiveSolutionsForRecord(GlideRecord now_GR)
指定された GlideRecord 内のテーブルに対するアクティブなソリューションを取得します。
| 名前 | タイプ | 説明 |
|---|---|---|
| now_GR | GlideRecord | アクティブなソリューションオブジェクトの収集元の GlideRecord。 |
| タイプ | 説明 |
|---|---|
| アレイ | 指定されたレコードが属するテーブルに関連付けられたアクティブなソリューションオブジェクトのアレイ。 |
このスクリプトは GlideRecord (インシデントなど) を渡し、GlideRecord のすべてのソリューションを処理して、それぞれの値を返します。
/* This is only to get a hard-coded GR */
var current = new GlideRecord('incident');
current.get('965c9e5347c12200e0ef563dbb9a7156');
var predictor = new MLPredictor();
var solutions = predictor.findActiveSolutionsForRecord(current);
solutions.forEach(function(solution) {
var outcome = solution.predict(current);
/* Use this to set the field to the predicted value in the GlideRecord */
var fieldName = solution.getPredictedField();
current[fieldName] = outcome.predictedValue();
current.update();
gs.info("Predicted value: " + outcome.predictedValue())
gs.info("Confidence: " + outcome.confidence())
});
出力 (アサイン先グループの予測):
DxC_ML: ******* Finished Prediction*********
*** Script: Predicted value: Software *** Script: Confidence:
99.74530683715315
出力 (カテゴリの予測):
DxC_ML:
******* Finished Prediction********* *** Script: Predicted value: Software *** Script:
Confidence: 98.7172805135524
MLPredictor - getPredictedValue(オブジェクト solution, オブジェクト outcome)
指定された予測の結果に基づいて、指定されたソリューションの予測値を取得します。
| 名前 | タイプ | 説明 |
|---|---|---|
| solution | オブジェクト | 予測値の取得元のソリューション。 |
| outcome | オブジェクト | 指定されたソリューションに対する予測の結果 (var outcome = solution.predict(now_GR))。 |
| タイプ | 説明 |
|---|---|
| 文字列 | 指定された予測の結果に基づく、指定されたソリューションの予測値。 |
| Null | 予測の信頼性がしきい値を満たさない場合は null を返します。 |
MLPredictor - getPredictions(GlideRecord now_GR, オブジェクト solution, オブジェクト options)
指定されたソリューションの予測を取得します。
| 名前 | タイプ | 説明 |
|---|---|---|
| now_GR | GlideRecord | 予測する対象の GlideRecord。 |
| solution | オブジェクト | 実行するソリューションオブジェクト。 |
| options | オブジェクト | 次のプロパティを持つ、JSON オブジェクトのキーと値のペア (オプション)。
|
| タイプ | 説明 |
|---|---|
| アレイ | 予測結果オブジェクトのアレイ |
次の例では、指定されたソリューションを呼び出し、それに対して予測を実行します。
function printOutcomeArr(outcomeArr) {
gs.print('################## Results ##################');
for (var i=0; i<outcomeArr.length; i++) {
var outcome = outcomeArr[i];
gs.print((i+1) + ' : ' + outcome.predictedValue() + ', ' + outcome.predictedValueSysId() + ', ' + outcome.confidence());
}
}
var solutionName = 'ml_x_snc_global_prop_flip_test';
var predictor = new MLPredictor();
var solution = predictor.findActiveSolution(solutionName);
var now_GR = new GlideRecord('incident');
now_GR.get('1c741bd70b2322007518478d83673af3');
var options = {};
options.top_n = '10'; // top_n is an integer between 1 and 1000
options.apply_threshold = false; // Value can be set to true or false
printOutcomeArr(predictor.getPredictions(now_GR, solution, options));
MLPredictor - isClassificationSolution(オブジェクト solution)
ソリューションオブジェクトが分類タイプかどうかを示します。
| 名前 | タイプ | 説明 |
|---|---|---|
| solution | オブジェクト | ML ソリューションの名前。 |
| タイプ | 説明 |
|---|---|
| ブーリアン | 入力ソリューションが分類タイプの場合は true を返し、そうでない場合は false を返します。 |
var isClassificationSolution = this.isClassificationSolution(solution);
//classification solution each class has different threshold
//therefore needs to get all the results from ml engine
if (applyThreshold && isClassificationSolution) {
var maxClassificationTopN = 50;
outcomeArr = solution.predictTopN(now_GR, maxClassificationTopN);
}
else {
outcomeArr = solution.predictTopN(now_GR, topN);
}
if (outcomeArr === null) {
//instead of returning null returning empty array
return [];
}
MLPredictor - isSimilaritySolution(オブジェクト solution)
ソリューションオブジェクトが類似性タイプかどうかを示します。
| 名前 | タイプ | 説明 |
|---|---|---|
| solution | オブジェクト | ML ソリューションの名前。例:ml_incident_categorization |
| タイプ | 説明 |
|---|---|
| ブーリアン | 入力ソリューションが類似性タイプの場合は true を返し、そうでない場合は false を返します。 |
MLPredictor - outcome.confidence()
予測値の信頼性を取得します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | 予測の推定精度 (%)。例:53.84615375762915 |
var MLP = new MLPredictor();
var solution = MLP.findActiveSolution(solutionName);
var predictedOutcome = solution.predictText(input);
var outcome = predictedOutcome.predictedValue();
var confidence = predictedOutcome.confidence();
gs.info("Predicted value: " + outcome)
gs.info("Confidence: " + confidence)
MLPredictor - outcome.predictedValue()
MLPredictor 結果オブジェクトから予測値を取得します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | 結果オブジェクトから取得した予測値。 |
var MLP = new MLPredictor();
var solution = MLP.findActiveSolution(solutionName);
var predictedOutcome = solution.predictText(input);
var outcome = predictedOutcome.predictedValue();
var confidence = predictedOutcome.confidence();
gs.info("Predicted value: " + outcome)
gs.info("Confidence: " + confidence)
MLPredictor - outcome.predictedValueSysId()
予測値の sys_id を取得します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | 予測値の sys_id。 |
function printOutcomeArr(outcomeArr) {
gs.print('################## Results ##################');
for (var i=0; i<outcomeArr.length; i++) {
var outcome = outcomeArr[i];
gs.print((i+1) + ' : ' + outcome.predictedValue() + ', ' + outcome.predictedValueSysId() + ', ' + outcome.confidence());
}
MLPredictor - recordFinalValuesInPredictionResults(GlideRecord now_GR, 文字列 reason)
指定された GlideRecord に、最終的な予測結果の値とその理由 (オプションで指定) を設定します。
| 名前 | タイプ | 説明 |
|---|---|---|
| now_GR | GlideRecord | 最終的な予測結果の値を設定する GlideRecord。 |
| 理由 | 文字列 | オプション。結果を適用する理由。 |
| タイプ | 説明 |
|---|---|
| なし |
次の例では、インシデントがクローズされると recordFinalValuesInPredictionResults() メソッドが呼び出されます。
(function executeRule(current, previous /*null when async*/) {
var predictor = new MLPredictor();
predictor.recordFinalValuesInPredictionResults(current, "On close");
})(current, previous);
MLPredictor - solution.getCapability()
トレーニング済みソリューションの機能情報を取得します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | トレーニング済みソリューションの定義 ID とバージョン、それ以外の場合はエラーメッセージ |
MLPredictor - solution.getName()
予測に使用されたソリューションの名前を取得します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | 予測に使用されたソリューションの名前。例:ml_incident_categorization |
MLPredictor - solution.getPredictedField()
ソリューションの予測値を取得します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | ソリューションの予測出力フィールドの値 |
/* Get a hard-coded GR */
var current = new GlideRecord('incident');
current.get('965c9e5347c12200e0ef563dbb9a7156');
var predictor = new MLPredictor();
var solutions = predictor.findActiveSolutionsForRecord(current);
solutions.forEach(function(solution) {
var outcome = solution.predict(current);
/* Use this to set the field to the predicted value in the GlideRecord */
var fieldName = solution.getPredictedField();
current[fieldName] = outcome.predictedValue();
current.update();
gs.info("Predicted value: " + outcome.predictedValue())
gs.info("Confidence: " + outcome.confidence())
});
MLPredictor - solution.getThreshold(文字列 className)
ソリューションのしきい値を取得します。
しきい値は、最小限の予測精度を反映するパーセンテージを表します。
| 名前 | タイプ | 説明 |
|---|---|---|
| className | 文字列 | ソリューション出力フィールドの指定されたカテゴリ値 |
| タイプ | 説明 |
|---|---|
| 数字 | 0 〜 100 のパーセンテージで表されるしきい値の値。 |
MLPredictor - solution.getVersion()
アクティブなソリューションのバージョンを取得します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | アクティブなソリューションのバージョン |
MLPredictor - solution.isActive()
指定されたソリューションがアクティブかどうかを判断します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| ブーリアン | ソリューションがアクティブな場合は true、そうでない場合は false |
MLPredictor - solution.predict(GlideRecord now_GR, オブジェクト threshold)
ソリューションの予測結果を結果オブジェクトとして取得します。
| 名前 | タイプ | 説明 |
|---|---|---|
| now_GR | GlideRecord | ソリューション入力テーブルの GlideRecord |
| threshold | オブジェクト | しきい値 (類似性のソリューションレベルのしきい値、分類のクラスレベルのしきい値) |
| タイプ | 説明 |
|---|---|
| オブジェクト | 指定されたソリューションの予測結果 (var outcome = solution.predict(now_GR))。 |
solutions.forEach(function(solution) {
var outcome = solution.predict(current);
/* Use this to set the field to the predicted value in the GlideRecord
var fieldName = solution.getPredictedField();
current[fieldName] = outcome.predictedValue();
current.update();
*/
gs.info("Predicted value: " + outcome.predictedValue())
gs.info("Confidence: " + outcome.confidence())
});
MLPredictor - solution.predictTopN(GlideRecord now_GR, オブジェクト topN)
予想される予測数までの結果オブジェクトのリストを返します。最大予測数は 1000 です。
| 名前 | タイプ | 説明 |
|---|---|---|
| now_GR | GlideRecord | ソリューションの GlideRecord |
| topN | オブジェクト | 予想される予測数。1000 を超えた場合は 1000 件の結果が返される |
| タイプ | 説明 |
|---|---|
| アレイ | GlideRecord、しきい値、Sys ID、および予想される予測数 (topN オブジェクト) を含むアレイ内の結果オブジェクトのリスト |
var isClassificationSolution = this.isClassificationSolution(solution);
//classification solution each class has different threshold
//therefore needs to get all the results from ml engine
if (applyThreshold && isClassificationSolution) {
var maxClassificationTopN = 50;
outcomeArr = solution.predictTopN(now_GR, maxClassificationTopN);
}
else {
outcomeArr = solution.predictTopN(now_GR, topN);
}
if (outcomeArr === null) {
//instead of returning null returning empty array
return [];
}