LoginSignup
0
0

Google Colab環境でt分布の確率密度関数を出力する

Last updated at Posted at 2018-11-08

最近話題のGoogle Colabを試してみたかったので、動作確認も兼ねてColab環境でt分布の確率密度関数を描画してみました。

Google Colabでの前準備

Colabにアクセスし、「ファイル」 > 「Python 3 の新しいノートブック」を選択。
あとは実行したいPythonのコードをエディタ上に貼り付けるだけです。

t分布の確率密度関数を出力

import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-6, 6, 1000)
fig,ax = plt.subplots(1,1)

linestyles = [':', '--', '-.', '-']
deg_of_freedom = [1, 3, 10, 30]
for k, ls in zip(deg_of_freedom, linestyles):
  ax.plot(x, stats.t.pdf(x, k), linestyle=ls, label=r'$k=%i$' % k)

plt.xlim(-6, 6)
plt.ylim(0, 0.45)

plt.legend()
plt.show()

実行結果

t_python.png

まとめ

Colabを使うと環境構築のストレスがないので、今回のようにサクッと試してみたい場合に最適ですね。
調べてみるとGPUやTPU環境も試せるとのことなので、TensorFlowやKerasを試す環境としても使えそうです。

参考記事

[社内統計学勉強会]カイ二乗分布とt分布をPythonで描画する
https://techblog.gmo-ap.jp/2018/08/21/%E7%A4%BE%E5%86%85%E7%B5%B1%E8%A8%88%E5%AD%A6%E5%8B%89%E5%BC%B7%E4%BC%9A%E3%82%AB%E3%82%A4%E4%BA%8C%E4%B9%97%E5%88%86%E5%B8%83%E3%81%A8t%E5%88%86%E5%B8%83%E3%82%92python%E3%81%A7%E6%8F%8F%E7%94%BB/

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0