开始使用免费开始使用

探索逻辑回归系数

现在,您将探索逻辑回归的系数,以了解哪些因素会推动流失率上升或下降。在本练习中,您将从已拟合的模型中提取逻辑回归系数,并计算其指数,使结果更易解释。

已拟合的逻辑回归实例加载为 logreg,标准化后的特征作为名为 train_Xpandas DataFrame 加载。numpypandas 库分别以 nppd 的名称加载。

本练习是课程的一部分

Python 营销中的机器学习

查看课程

练习说明

  • 将特征名和系数合并为一个 pandas DataFrame。
  • 计算逻辑回归系数的指数。
  • 移除等于 0 的系数,并按指数系数排序后打印。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Combine feature names and coefficients into pandas DataFrame
feature_names = pd.DataFrame(___.columns, columns = ['Feature'])
log_coef = pd.DataFrame(np.transpose(logreg.coef_), columns = ['Coefficient'])
coefficients = pd.concat([feature_names, ___], axis = 1)

# Calculate exponent of the logistic regression coefficients
coefficients['Exp_Coefficient'] = np.___(coefficients['Coefficient'])

# Remove coefficients that are equal to zero
coefficients = coefficients[coefficients['Coefficient']!=___]

# Print the values sorted by the exponent coefficient
print(coefficients.sort_values(by=['___']))
编辑并运行代码