MLPredictor - グローバル (使用廃止)
MLPredictor API は、予測インテリジェンス予測のためのユーティリティメソッドを提供します。
MLPredictor API には 予測インテリジェンス プラグイン (com.glide.platform_ml) が必要で、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, Array 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, Object 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 | オブジェクト | 指定されたソリューションの予測結果 (var outcome = solution.predict(now_GR))。 |
| タイプ | 説明 |
|---|---|
| 文字列 | 予測の指定された結果に基づいた、指定されたソリューションの予測値。 |
| Null | 予測の信頼性がしきい値を満たさない場合は null を返します。 |
MLPredictor - getPredictions(GlideRecord now_GR、オブジェクトソリューション、オブジェクトオプション)
指定されたソリューションの予測を取得します。
| 名前 | タイプ | 説明 |
|---|---|---|
| now_GR | GlideRecord | 予測する GlideRecord。 |
| solution | オブジェクト | 実行するソリューションオブジェクト。 |
| オプション | オブジェクト | 次のプロパティを持つオプションの 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 | オブジェクト | 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 | オブジェクト | 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(String className)
ソリューションのしきい値を取得します。
しきい値は、最小予測精度を反映するパーセンテージを表します。
| 名前 | タイプ | 説明 |
|---|---|---|
| className | 文字列 | ソリューション出力フィールドの指定されたカテゴリ値 |
| タイプ | 説明 |
|---|---|
| 番号 | 0 〜 100 のパーセンテージで表されるしきい値。 |
MLPredictor - solution.getVersion()
アクティブなソリューションのバージョンを取得します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | アクティブなソリューションのバージョン |
MLPredictor - solution.isActive()
指定されたソリューションがアクティブかどうかを判定します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| ブール | ソリューションがアクティブな場合は true、それ以外の場合は false |
MLPredictor - solution.predict(GlideRecord now_GR, オブジェクトしきい値)
ソリューション予測結果を結果オブジェクトとして取得します。
| 名前 | タイプ | 説明 |
|---|---|---|
| now_GR | GlideRecord | ソリューション入力テーブルの GlideRecord |
| しきい値 | オブジェクト | しきい値 (類似性のソリューションレベルしきい値、分類のクラスレベルしきい値) |
| タイプ | 説明 |
|---|---|
| オブジェクト | 指定されたソリューションの予測結果 (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, Object topN)
予想される予測数までの結果オブジェクトのリストを返します。最大数は 1000 予測です。
| 名前 | タイプ | 説明 |
|---|---|---|
| now_GR | GlideRecord | ソリューションの GlideRecord |
| topN | オブジェクト | 予測の予想数。1000 を超える数は 1000 件の結果を返します |
| タイプ | 説明 |
|---|---|
| アレイ | GlideRecord、しきい値、システム 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 [];
}