我用 Python 中的 sklearn 库训练了一个 LinearSVC 模型。目标变量y有 4 个水平 ( 0,1,2,3)。model = LinearSVC()X_train, X_test, y_train, y_test = tts(X, y, test_size = 0.25, random_state = 4)model.fit(X_train, y_train)model.coef_我得到一个这样的 NumPy ndarray:array([[ -1.64280582, -0.49711136, 0. , ..., 0. , -0.50203059, 0. ], [ 0. , 0. , -2.67396495, ..., 2.35298657, 0. , 0. ], [ 1.11471827, 3.76220356, 0. , ..., -11.09758616, 0. , 0. ], [ 0. , -2.7305259 , 0.09663903, ..., 0. , 0. , 0. ]])我需要知道哪个数组匹配每个目标变量级别。我怎么知道?
1 回答

炎炎设计
TA贡献1808条经验 获得超4个赞
首先,这是一个一对一的实现。
从文档:
coef_ : array, shape = [n_features] if n_classes == 2 else [n_classes, n_features] 分配给特征的权重(原始问题中的系数)。这仅在线性内核的情况下可用。
coef_ 是从 raw_coef_ 派生的只读属性,它遵循 liblinear 的内部存储器布局。
在您的情况下,形状是 [n_classes, n_features]。
model.coef_[0,:]
为您提供 class 的功能权重0 vs all
。model.coef_[1,:]
为您提供 class 的功能权重1 vs all
。等等
添加回答
举报
0/150
提交
取消