3 분위수 (낮음, 중간, 높은 위험)로 구분되는 예측 모델 출력의 데이터 프레임이 있습니다. 관심있는 결과가있는 각 위험 영역에있는 사람들의 비율을 계산하고 싶습니다.
import pandas as pd
data = {'risk_group': ["medium", "low", "high", "low", "high", "high", ....],
'outcome': [1, 0, 1, 0, 1, 1, ....}
df = pd.DataFrame (data, columns = ['risk_group','outcome'])
이론적으로 원하는 출력은
low : 12% w/ outcome
medium : 34% w/ outcome
high: 78% w/ outcome
사용하다:
df.groupby('risk_group').outcome.apply(lambda x: x.sum()/x.size * 100)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다