逻辑回归

Python 概率基础

Alexander A. Ramírez M.

CEO @ Synergy Vision

原始数据

学习时长与分数数据

Python 概率基础

新数据

通过或不通过的测试图

Python 概率基础

你会把线画在哪里?

在哪划分界线的动画图

Python 概率基础

基于概率的解法

使用模型计算概率

Python 概率基础

逻辑函数

逻辑函数图

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

Python 概率基础

调整斜率

斜率参数使S形函数更陡的动画

Python 概率基础

调整截距

截距参数的S形函数图

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 概率基础

Passons à la pratique !

Python 概率基础

Preparing Video For Download...