モデルパフォーマンスのインサイト¶
DataRobotには、モデルパフォーマンスの把握や評価に役立つインサイトが複数用意されています。
- ROC曲線:さまざまな分類しきい値における真陽性率と偽陽性率のトレードオフを示す受信者動作特性曲線。 二値分類モデルで利用できます。
- リフトチャート:モデルがターゲット母集団をどの程度適切にセグメント化しているか、またターゲット特徴量の値の各範囲においてモデルのパフォーマンスがどの程度良好であるかを示します。 分類モデルと連続値モデルで利用できます。
- 残差:連続値モデルにおける予測誤差の分布を表示します。
これらのインサイトは、さまざまなデータパーティション(検定、交差検定、ホールドアウト)に対して計算でき、データスライスでフィルターすることができます。
The following example code assumes that you have a trained model object called model.
ROC曲線¶
次の例は、二値分類モデルのROC曲線を計算して取得する方法を示しています。
from datarobot.insights.roc_curve import RocCurve
model_id = model.id # or model_id = 'YOUR_MODEL_ID'
# Compute a new ROC curve and wait for it to complete
roc = RocCurve.create(entity_id=model_id) # default source is 'validation'
# Access ROC curve properties
print(roc.auc)
>>> 0.85
print(roc.kolmogorov_smirnov_metric)
>>> 0.42
print(roc.roc_points[:2])
>>> [{'accuracy': 0.539375, 'f1_score': 0.0, 'false_negative_score': 737, ...}, ...]
# Compute ROC curve on a different partition, and return immediately with job reference
job = RocCurve.compute(entity_id=model_id, source='holdout')
# Wait for the job to complete
roc_holdout = job.get_result_when_complete()
print(roc_holdout.auc)
>>> 0.83
# Get a pre-existing ROC curve (if already computed)
existing_roc = RocCurve.get(entity_id=model_id, source='validation')
# List all available ROC curves for a model
roc_list = RocCurve.list(entity_id=model_id)
print(roc_list)
>>> [<datarobot.insights.roc_curve.RocCurve object at 0x7fc0a7549f60>, ...]
print([(r.source, r.auc) for r in roc_list])
>>> [('validation', 0.85), ('holdout', 0.83)]
データスライスを使用したROC曲線¶
特定のデータスライスに対してROC曲線を計算できます。
from datarobot.insights.roc_curve import RocCurve
# Get a pre-existing ROC curve for a specific data slice
roc_sliced = RocCurve.get(entity_id=model_id, source='validation', data_slice_id='slice_id_here')
# Or compute a new one
job = RocCurve.compute(entity_id=model_id, source='validation', data_slice_id='slice_id_here')
roc_sliced = job.get_result_when_complete()
リフトチャート¶
リフトチャートは、モデルがターゲット母集団をどの程度適切にセグメント化しているか、またターゲット特徴量の値の各範囲においてモデルのパフォーマンスがどの程度良好であるかを示します。
from datarobot.insights.lift_chart import LiftChart
model_id = model.id # or model_id = 'YOUR_MODEL_ID'
# Compute a new lift chart and wait for it to complete
lift = LiftChart.create(entity_id=model_id) # default source is 'validation'
# Access lift chart bins
print(lift.bins[:3])
>>> [{'actual': 0.4, 'predicted': 0.227, 'bin_weight': 5.0}, ...]
# Compute lift chart on a different partition, and return immediately with job reference
job = LiftChart.compute(entity_id=model_id, source='holdout')
# Wait for the job to complete
lift_holdout = job.get_result_when_complete()
# Get a pre-existing lift chart (if already computed)
existing_lift = LiftChart.get(entity_id=model_id, source='validation')
# List all available lift charts for a model
lift_list = LiftChart.list(entity_id=model_id)
print(lift_list)
>>> [<datarobot.insights.lift_chart.LiftChart object at 0x7fe242eeaa10>, ...]
print([l.source for l in lift_list])
>>> ['validation', 'holdout', 'crossValidation']
# Get lift chart for a specific data slice
lift_sliced = LiftChart.get(entity_id=model_id, source='validation', data_slice_id='slice_id_here')
残差¶
残差チャートは、連続値モデルにおける予測誤差の分布を表示します。
from datarobot.insights.residuals import Residuals
model_id = model.id # or model_id = 'YOUR_MODEL_ID'
# Compute a new residuals chart and wait for it to complete
residuals = Residuals.create(entity_id=model_id) # default source is 'validation'
# Access residuals properties
print(residuals.coefficient_of_determination)
>>> 0.85
print(residuals.residual_mean)
>>> 0.023
print(residuals.standard_deviation)
>>> 1.42
# Access histogram data
print(residuals.histogram[:3])
>>> [{'interval_start': -33.37, 'interval_end': -32.52, 'occurrences': 1}, ...]
# Access raw chart data (actual, predicted, residual, row number)
print(residuals.chart_data[:3])
>>> [[45.2, 43.8, -1.4, 0], [52.1, 51.9, -0.2, 1], ...]
# Compute residuals on a different partition, and return immediately with job reference
job = Residuals.compute(entity_id=model_id, source='holdout')
# Wait for the job to complete
residuals_holdout = job.get_result_when_complete()
# Get a pre-existing residuals chart (if already computed)
existing_residuals = Residuals.get(entity_id=model_id, source='validation')
# List all available residuals charts for a model
residuals_list = Residuals.list(entity_id=model_id)
print(residuals_list)
>>> [<datarobot.insights.residuals.Residuals object at 0x7fbce8305ae0>, ...]
print([r.source for r in residuals_list])
>>> ['validation', 'holdout']
# Get residuals for a specific data slice
residuals_sliced = Residuals.get(entity_id=model_id, source='validation', data_slice_id='slice_id_here')