sklearn 中 Logistics Regression 的 coef_ 和 intercept_ 的具体意义
使用sklearn库可以很方便的实现各种基本的机器学习算法,例如今天说的逻辑斯谛回归(Logistic Regression),我在实现完之后,可能陷入代码太久,忘记基本的算法原理了,突然想不到coef_和intercept_具体是代表什么意思了,就是具体到公式中的哪个字母,虽然总体知道代表的是模型参数。
正文
我们使用 sklearn 官方的一个例子来作为说明,源码可以从这里下载,下面我截取其中一小段并做了一些修改:
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import make_blobs
from sklearn.linear_model import LogisticRegression
# 构造一些数据点
centers = [[-5, 0], [0, 1.5], [5, -1]]
X, y = make_blobs(n_samples=1000, centers=centers, random_state=40)
transformation = [[0.4, 0.2], [-0.4, 1.2]]
X = np.dot(X, transformation)
clf = LogisticRegression(solver='sag', max_iter=100, random_state=42, multi_class=multi_class).fit(X, y)
prin