我正在尝试使用scikit-learn的LabelEncoder将类别变量转换为数字变量:
from sklearn.preprocessing import LabelEncoder
var_mod = ['Gender', 'Married', 'Dependents', 'Education', 'Self_Employed', 'Property_Area', 'Loan_Status']
le = LabelEncoder()
for i in var_mod:
data_train[i] = le.fit_transform(data_train[i])
data_train.dtypes
我正在使用Python 3.6.4在Jupyter中运行它。它给了我以下python错误:
TypeError:“ str”和“ int”的实例之间不支持“ <”
我尝试使用不同的方法和排列方式(fit vs fit_transform),但仍然遇到相同的Python错误。
这些是我数据框的dtypes
Loan_ID object
Gender int64
Married int64
Dependents object
Education object
Self_Employed object
ApplicantIncome int64
CoapplicantIncome float64
LoanAmount float64
Loan_Amount_Term float64
Credit_History float64
Property_Area object
Loan_Status object
LoanAmount_log float64
TotalIncome float64
TotalIncome_log float64
dtype: object