相同的LogisticRegression.coef_列表,用于2种不同的LogisticRegression.classes_

时间:2018-04-03 14:19:16

标签: python logistic-regression

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'

的联合主席

0 个答案:

没有答案