ランダムモデル
この演習では、累積ゲイン曲線のベースライン、つまりランダムモデルの累積ゲイン曲線を再現します。
そのために、ランダムな予測を作成します。plot_cumulative_gain メソッドは、各予測についてターゲットが 0 の確率と 1 の確率の2つの値を必要とします。これらは合計で 1 になる必要があるため、有効な予測のリストは [(0.02,0.98),(0.27,0.73),...,(0.09,0.91)] のようになります。
Python では、a と b の間の乱数を次のように生成できます。
import random
random_value = random.uniform(a,b)
この演習はコースの一部です
Pythonで学ぶ予測分析入門
演習の手順
random、matplotlib、scikitplotモジュールをインポートします。- 0〜1の乱数を含むリスト
random_predictionsを作成します。 - リスト
random_predictionsを、各要素が(r,a)のタプル(元の値をrとし、\(r+a=1\) を満たすa)になるように整形します。 - 正解ラベルは
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()