ランダムな行の選択
この演習では、pandas の DataFrame から復元抽出でランダムな行(レコード)を選ぶ2つの方法を比較します。
- 組み込みの
pandas関数.random() NumPyの乱数生成器np.random.randint()
一般に、統計や Machine Learning の分野では、アルゴリズムを訓練する際に、利用可能なデータの75%で学習し、残りの25%で性能を評価します。
この演習では、上記の各方法を使って、利用可能なポーカーのハンドのうち75%をランダムサンプリングし、どちらの方法が速度の面でより効率的かを確認します。
この演習はコースの一部です
pandasで効率的にコードを書く
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Extract number of rows in dataset
N=poker_hands.shape[0]
# Select and time the selection of the 75% of the dataset's rows
rand_start_time = time.time()
poker_hands.iloc[np.random.randint(____=0, high=____, ____=int(0.75 * N))]
print("Time using Numpy: {} sec".format(time.time() - rand_start_time))