Questions tagged «dummy-variable»


4
get_dummies(Pandas)和OneHotEncoder(Scikit-learn)之间的优缺点是什么?
我正在学习将机器学习分类器将分类变量转换为数字的不同方法。我遇到了这种pd.get_dummies方法,sklearn.preprocessing.OneHotEncoder()我想看看它们在性能和用法上有何不同。 我发现关于如何使用教程OneHotEncoder()上https://xgdgsc.wordpress.com/2015/03/20/note-on-using-onehotencoder-in-scikit-learn-to-work-on-categorical-features/自该sklearn文档对该功能的帮助不是很大。我有一种感觉,我做得不正确...但是 有人能解释一下使用pd.dummiesover的利弊sklearn.preprocessing.OneHotEncoder()吗?我知道这OneHotEncoder()为您提供了一个稀疏矩阵,但除此之外,我不确定该如何使用以及该pandas方法有什么好处。我使用效率低下吗? import pandas as pd import numpy as np from sklearn.datasets import load_iris sns.set() %matplotlib inline #Iris Plot iris = load_iris() n_samples, m_features = iris.data.shape #Load Data X, y = iris.data, iris.target D_target_dummy = dict(zip(np.arange(iris.target_names.shape[0]), iris.target_names)) DF_data = pd.DataFrame(X,columns=iris.feature_names) DF_data["target"] = pd.Series(y).map(D_target_dummy) #sepal length (cm) sepal width (cm) …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.