开始使用免费开始使用

编码技术

在幻灯片中,我们讨论了两种编码技术:标签编码(label encoding)和独热编码(one-hot encoding)。 在实际应用中,您选择哪种技术取决于具体场景。话虽如此,在面试中,最好两种方法都能熟练使用。

在本练习中,您将把这两种技术都应用到同一个 laptop prices 数据集上。该数据集已预加载到变量 laptops 中。

本练习是课程的一部分

用 Python 练习统计学面试题

查看课程

交互式实操练习

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

from sklearn import preprocessing

# Create the encoder and print our encoded new_vals
encoder = preprocessing.LabelEncoder()
new_vals = encoder.fit_transform(____)
print(____)
编辑并运行代码