본문 바로가기
Python

[python] regression model의 성능 지표로 쓰일 수 있는 bland altman plot 그리기

by Chandler.j 2021. 1. 15.
반응형

fig1. title

bland altman plot을 이용해서 regression model의 성능을 확인해 볼 수 있다.

 

bland altman 참고 : en.wikipedia.org/wiki/Bland%E2%80%93Altman_plot

 

Bland–Altman plot - Wikipedia

Bland–Altman plot example A Bland–Altman plot (difference plot) in analytical chemistry or biomedicine is a method of data plotting used in analyzing the agreement between two different assays. It is identical to a Tukey mean-difference plot,[1] the na

en.wikipedia.org


두가지 방법으로 그릴 수 있다.

 

#1. statsnodels.api 이용하기

import statsmodels.api as sm

f, ax = plt.subplots(1, figsize = (8,5))
sm.graphics.mean_diff_plot(y_pred, y_test, ax = ax)
plt.show()

fig1. output of #1

 

#1.2 log transformation

 #1에서 plot을 보면 mean과 differencecorrelation이 있어 보인다 이 방법을 log 값으로 변환 후 계산해 보면 경향이 달라 질 수도 있다.

#log transformation bland-althman plot

import math 

y_pred_log = np.log(y_pred)
y_test_log = np.log(y_test)
print(y_pred_log, y_pred)

f, ax = plt.subplots(1, figsize = (8,5))
sm.graphics.mean_diff_plot(y_pred_log, y_test_log, ax = ax)
plt.xlabel('Means (log(a)+log(b))/2')
plt.ylabel('Difference log(a)-log(b)')
plt.show()

fig2. output of log transformation

하지만 이 실험에서는 결과가 크게 달라지지 않았다.

 

#2. pyCompare 이용하여 그리기

 percentage option 을 True로 설정해주면 difference가 A/B인 percentage로 log transformation과 비슷한 효과를 얻을 수 있다.

import pyCompare

pyCompare.blandAltman(y_pred, y_test, percentage=True, 
			title='A/B test analysis, y_pred / y_test')

fig3. output of #2

참고 : towardsdatascience.com/why-how-to-use-the-bland-altman-plot-for-a-b-testing-python-code-78712d28c362

 

Why & How to use the Bland-Altman plot for A/B testing | Python + code

The usage of the Bland-Altman plot is a good way to analyze an A/B Test — Let’s see how to do it in Python.

towardsdatascience.com

 

 

 


TOP

Designed by 티스토리