This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# x=1: 袋a, x=0: 袋b | |
# y=1: 赤玉, y=0: 白玉 | |
def ball_model_no_if(): | |
x = pyro.sample("x", dist.Bernoulli(0.5)) | |
# xの値に応じてyの割合を変更 | |
y = pyro.sample("y", dist.Bernoulli(2.0/3.0)) * x + pyro.sample("y", dist.Bernoulli(1.0/4.0)) * (1 - x) | |
return y | |
# plateを用いてi.i.dサンプリング | |
with pyro.plate("plate", size=10000): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def var(data): | |
n = len(data) | |
m = 0 | |
s = 0 | |
for k in range(n): | |
x = data[k] | |
old_m = m | |
m += (x - m)/k | |
s += (x - m) * (x - old_m) | |
return s / (n - 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print(rf.feature_importances_) | |
#result | |
#[0.02885416 0.28571966 0.33432064 0.35110554] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2) | |
lr = LinearRegression().fit(X_train, y_train) | |
y_pred_lr = lr.predict(X_test) | |
rf = RandomForestRegressor().fit(X_train, y_train) | |
y_pred_rf = rf.predict(X_test) | |
# 精度評価 | |
fig, ax = plt.subplots() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_toy_dataset(n=100): | |
# 交互作用を含まない変数 | |
ind_vars = np.random.randn(n, 2) | |
# 交互作用のもとになる変数 | |
int_var_src = np.random.randn(n, 2) | |
X = np.hstack([ind_vars, int_var_src]) | |
y = ind_vars[:, 1] + 2 * int_var_src[:, 0] * int_var_src[:, 1] | |
return X, y | |
X, y = create_toy_dataset(2000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo mv /etc/iptables/iptables.rules /var/tmp #iptablesの設定があるとufwが動作しないので移動(参考)。 | |
sudo ufw status #inactiveであること確認 | |
sudo ufw default deny #明示的に全てを遮断 | |
sudo ufw allow 22 #22を許可 | |
sudo ufw allow 80 | |
sudo ufw allow 443 | |
sudo ufw logging on #ログ出力設定 | |
sudo ufw enable | |
sudo ufw status #設定が生きているか確認。 | |
sudo shutdown -r now #設定が生きているか確認。 |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
# ジニ係数の計算 | |
def gini_impurity(datasets): | |
data_all = np.concatenate(datasets, axis=0) # データセットを結合 | |
n_all = len(data_all) # 全サンプル数 | |
class_set = set(data_all) #データセットに含まれているユニークなクラスのセットを取り出し | |
if(len(class_set) == 1): # クラスが1つしか含まれてなければ計算するまでもなくgini係数は0 | |
return 0.0 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###決定木の中身を表示するためのdotファイルの出力 | |
from sklearn.externals.six import StringIO | |
with open("xor_simple.dot", 'w') as f: | |
f = tree.export_graphviz(clf, out_file=f) | |
f.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 決定境界の可視化 | |
import matplotlib.pyplot as plt | |
# Parameters for plot | |
n_classes = 2 | |
plot_colors = "br" | |
plot_step = 0.05 | |
#グラフ描画時の説明変数 x、yの最大値&最小値を算出。 | |
#グラフ描画のメッシュを定義 |
NewerOlder