데이터과학 삼학년

Bigquery ML Explainable AI (XAI) 본문

GCP

Bigquery ML Explainable AI (XAI)

Dan-k 2021. 11. 10. 20:38
반응형

Bigquery ML에서 모델을 create하고, 모델을 이용해 예측을 할때,

단순히 predict 뿐만 아니라 explain_predict를 이용하여 모델의 결과를 설명할 수 있는 여러 요소를 조회할 수 있다.

이를 통해 간단한 쿼리만으로 모델의 학습과 예측결과, 그리고 예측 결과에 대한 설명자료까지 확인이 가능하다.

 

아래 표는 모델별 explainability method를 무엇을 썼는지 나타내 준다.

일반적인 통계기반의 ML은 coefficient를 기준으로 모델을 설명한다.

 

Local vs. Global Explainability

Explainability encompasses two types: local and global explainability. These are also known respectively as local and global feature importance.

  • Local explainability : Returns feature attribution values for each explained example. These values describe how much a particular feature affected the prediction relative to the baseline prediction.
    • 예측 대상 데이터에 대한 feature 특성을 리턴함. 이 값은 얼마나 특정 feature가 baseline 예측과 관련하여 예측에 영향을 미치는지 확인이 가능함.
  • Global explainability : Returns the feature's overall influence on the model, often obtained by aggregating the feature attributions over the entire dataset. A higher absolute value indicates the feature had a greater influence on the model’s predictions.
    • 모델에서 feature의 전체적인 영향도를  리턴함. value가 클수록 모델 예측에 더 큰 영향을 미치는 feature를 의미함.

Explainable AI Offerings in BigQuery ML

[모델 생성 코드]

CREATE OR REPLACE MODEL
  `census.census_model`
OPTIONS
  ( model_type='LOGISTIC_REG',
    auto_class_weights=TRUE,
    input_label_cols=['income_bracket']
  ) AS
SELECT
  * EXCEPT(dataframe)
FROM
  `census.input_view`
WHERE
  dataframe = 'training'

[모델 예측 코드 with Explain_predict]

-- 일반 predict
#standardSQL
SELECT
  *
FROM
  ML.PREDICT (MODEL `census.census_model`,
    (
    SELECT
      *
    FROM
      `census.input_view`
    WHERE
      dataframe = 'prediction'
     )
  )
  
-- predict & 설명 특성 포함
#standardSQL
SELECT
*
FROM
ML.EXPLAIN_PREDICT(MODEL `census.census_model`,
  (
  SELECT
    *
  FROM
    `census.input_view`
  WHERE
    dataframe = 'evaluation'),
  STRUCT(3 as top_k_features))

top_k_features가 3으로 설정되었기 때문에 제공된 테이블의 행당 특성 기여 항목 3개를 출력한다.

ML.EXPLAIN_PREDICT 만으로 쉽게 쿼리내에서 모델의 설명력을 확인할 수 있다.

https://cloud.google.com/bigquery-ml/docs/reference/standard-sql/bigqueryml-syntax-xai-overview

https://cloud.google.com/bigquery-ml/docs/reference/standard-sql/bigqueryml-syntax-explain-predict

https://cloud.google.com/bigquery-ml/docs/logistic-regression-prediction

728x90
반응형
LIST
Comments