ロジスティック回帰

Pythonで学ぶ確率の基礎

Alexander A. Ramírez M.

CEO @ Synergy Vision

元データ

学習時間とスコアのデータ

Pythonで学ぶ確率の基礎

新しいデータ

合否データのプロット

Pythonで学ぶ確率の基礎

どこに線を引きますか?

どこに境界線を引くかのアニメーション

Pythonで学ぶ確率の基礎

確率に基づく解法

モデルでの確率計算

Pythonで学ぶ確率の基礎

ロジスティック関数

ロジスティック関数のプロット

$$ logistic(t) = logistic(slope*x + intercept) $$

Pythonで学ぶ確率の基礎

傾きの変更

傾きでシグモイドが急になるアニメーション

Pythonで学ぶ確率の基礎

切片の変更

切片でシグモイドが移動するプロット

Pythonで学ぶ確率の基礎

データから確率へ

ロジスティックモデルでの確率計算

Pythonで学ぶ確率の基礎

結果

ロジスティックモデルの結果プロット

Pythonで学ぶ確率の基礎

誤分類

確率計算と誤分類

Pythonで学ぶ確率の基礎

ロジスティック回帰

# Import LogisticRegression
from sklearn.linear_model import LogisticRegression
# sklearn logistic model
model = LogisticRegression(C=1e9)
model.fit(hours_of_study, outcomes)
# Get parameters
beta1 = model.coef_[0][0]
beta0 = model.intercept_[0]
# Print parameters
print(beta1, beta0)
(1.3406531235010786, -15.05906237996095)
Pythonで学ぶ確率の基礎

学習時間に基づく結果の予測

hours_of_study_test = [[10]]
outcome = model.predict(hours_of_study_test)
print(outcome)
array([False])
Pythonで学ぶ確率の基礎

確率の計算

$$ $$

# Put value in an array
value = np.asarray(9).reshape(-1,1)
# Calculate the probability for 9 hours of study
print(model.predict_proba(value)[:,1])
array([0.04773474])
Pythonで学ぶ確率の基礎

Ayo berlatih!

Pythonで学ぶ確率の基礎

Preparing Video For Download...