开始使用免费开始使用

绘制发生率

预测变量洞察图中最重要的元素是发生率值。针对某个给定变量的人群中每个分组,发生率值表示该分组内目标的百分比。 在本练习中,您将编写一个 Python 函数,在给定预测变量洞察图表(predictor insight graph table)的情况下,绘制某个变量的发生率值。

本练习是课程的一部分

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()
编辑并运行代码