model.coef_
具有形状(1,4) - 所以1行4列。 4列中的每一列都是回归系数。我的问题是:为什么model.coef_
只存储一组系数,即系数仅用于model.classes_[1] = 'Survived'
model = LogisticRegression().fit(featureVecs, labels)
for i in range(len(model.coef_)):
print (model.coef_.shape)
print (model.classes_.shape)
print('For label', model.classes_[1])
for j in range(len(model.coef_[0])):
print(' ', Passenger.featureNames[j], '=', model.coef_[0][j])
我为model.coef_
model.classes_[1] = 'Survived'
数组
C2 = -1.08337751448
C3 = -1.92236816902
age = -0.0260808084178
male gender = -2.36271941114
model.classes_
具有形状(2,) - 所以model.classes_ = ['Died' 'Survived']
尝试获取model.classes_[0] = 'Died'
的系数结果时,我将上面的代码稍微更改为:
for i in range(len(model.coef_)):
print (model.coef_.shape)
print (model.classes_.shape)
print('For label', model.classes_[1])
for j in range(len(model.coef_[0])):
print(' ', Passenger.featureNames[j], '=', model.coef_[1][j])
它明显错误,因为model.coef_
是一个形状(1,4)。所以问题就变成了 - 我如何获得model.classes_[0] = 'Died'