开始使用免费开始使用

随机模型

在本练习中,您将重建累积增益曲线的基线,也就是随机模型的累积增益曲线。

为此,您需要构造随机预测。plot_cumulative_gain 方法要求这些预测包含两个值:目标为 0 的概率和目标为 1 的概率。这两个值之和应为 1,因此一组有效的预测列表例如可以是 [(0.02,0.98),(0.27,0.73),...,(0.09,0.91)]

在 Python 中,您可以按如下方式生成介于 ab 之间的随机数:

import random
random_value = random.uniform(a,b)

本练习是课程的一部分

Python 预测分析入门

查看课程

练习说明

  • 导入 randommatplotlibscikitplot 模块。
  • 构造一个包含 0 到 1 之间随机数的列表 random_predictions
  • 调整列表 random_predictions,使其包含形如 (r,a) 的元组,其中 r 是列表中的原始值,a 满足 $r+a=1$。
  • 目标的真实取值在 targets_test 中。展示您随机模型的累积增益图。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Import the modules
import ____
import ____ as plt
import ____ as skplt

# Generate random predictions
random_predictions = [random.uniform(____,____) for _ in range(len(targets_test))]

# Adjust random predictions
random_predictions = [(r, ____ - ____) for r in random_predictions]

# Plot the cumulative gains graph
skplt.metrics.plot_cumulative_gain(targets_test, ____)
plt.show()
编辑并运行代码