开始使用免费开始使用

Logistic Regression 基线分类器

在前两节课中,您已经了解了特征选择在机器学习面试中的重要性。另一类常见问题与特征工程有关,以及它如何帮助提升模型表现。

在本练习中,您将针对第 1 章中的 loan_data 数据集构造一个新特征。然后,通过比较测试集标签与目标变量 Loan Status 的预测值,分别在特征工程前后训练 Logistic Regression 模型并比较其准确率。

所需的包已为您导入:matplotlib.pyplot 别名为 pltseaborn 别名为 snssklearn.linear_model 中的 LogisticRegressionsklearn.model_selection 中的 train_test_split,以及 sklearn.metrics 中的 accuracy_score

特征工程被视为建模前的预处理步骤: Machine learning pipeline

本练习是课程的一部分

用 Python 练习机器学习面试题

查看课程

交互式实操练习

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

# Create X matrix and y array
X = loan_data.____("____", axis=1)
y = loan_data["____"]

# Train/test split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=123)

# Instantiate
logistic = ____()

# Fit
logistic.____(____, ____)

# Predict and print accuracy
print(____(y_true=____, y_pred=logistic.____(____)))
编辑并运行代码