시작하기무료로 시작하기

발생률 그리기

predictor insight graph에서 가장 중요한 요소는 발생률(incidence) 값입니다. 특정 변수에 대해 모집단을 그룹으로 나누면, 각 그룹의 발생률 값은 그 그룹에서 타깃이 발생한 비율(%)을 나타냅니다. 이번 연습에서는 predictor insight graph 테이블이 주어졌을 때, 특정 변수의 발생률 값을 시각화하는 Python 함수를 작성해 보겠습니다.

이 연습은 강의의 일부입니다

Python으로 배우는 예측 분석 입문

강의 보기

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

import matplotlib.pyplot as plt
import numpy as np

# The function to plot a predictor insight graph.
def plot_incidence(pig_table,variable):
    
    # Plot the incidence line
    ____["____"].plot()
    
    # Formatting the predictor insight graph
    plt.xticks(np.arange(len(pig_table)), pig_table[variable])
    plt.xlim([-0.5, len(pig_table) - 0.5])
    plt.ylim([0, max(pig_table["Incidence"] * 2)])
    plt.ylabel("Incidence", rotation=0, rotation_mode="anchor", ha="right")
    plt.xlabel(variable)
    
    # Show the graph
    plt.show()
코드 편집 및 실행