【发布时间】:2016-02-21 01:00:14
【问题描述】:
我正在尝试使用 scikit learn 对我的数据(6 个分类,1 个整数)运行逻辑回归。我正在关注 scikit 学习文档,但是在尝试拟合我的数据时,我收到以下值错误。有人可以帮忙吗?
#Below are the variables of my data.
train_data.dtypes
OUTPUT
TripType category
VisitNumber category
Weekday category
Upc category
ScanCount int64
DepartmentDescription category
FinelineNumber category
dtype: object
X = train_data.loc[:, 'VisitNumber':'FinelineNumber']
Y = train_data.loc[:, 'TripType':'TripType']
logreg = linear_model.LogisticRegression()
logreg.fit(X, Y)
**ValueError: could not convert string to float: GROCERY DRY GOODS**
【问题讨论】:
-
这个错误似乎很有启发性——“DepartmentDescription”是一个字符串吗?
-
@polka DeparmentDescription 是一系列字符串,我使用
train_data.DepartmentDescription = train_data.DepartmentDescription.astype('category')将其转换为分类值
标签: python scikit-learn logistic-regression