我正在尝试对数据帧执行单热编码,因此我正在关注我找到的在线资源,但我收到的错误消息如下所示。
我曾尝试使用谷歌,但所有内容都指出数据集存在问题,但我无法找到。
> d_train <- sparse.model.matrix(train$Tickets_Resolution ~ .-1, data=train)
Error in model.frame.default(object, data, xlev = xlev) :
invalid type (NULL) for variable 'train$Tickets_Resolution'
这就是train
数据集的样子。
str(tickets)
'data.frame': 71345 obs. of 7 variables:
$ Functional_Area : Factor w/ 24 levels "0","812","APS",..: 12 7 7 3 7 23 23 12 23 7 ...
$ Operating_Company: Factor w/ 28 levels " WS","812","BWI",..: 8 8 8 8 8 8 8 8 8 8 ...
$ Service_Type : Factor w/ 20 levels "APS","CNC","DBA",..: 7 7 7 1 7 17 17 7 17 7 ...
$ Ticket_Category : Factor w/ 5 levels "BULK","CHG","HK",..: 5 5 5 5 5 5 5 5 5 5 ...
$ Ticket_Resolution: Factor w/ 2 levels "Defect","OK": 2 1 2 1 2 2 1 2 2 2 ...
$ Priority : Factor w/ 4 levels "Priority 1","Priority 2",..: 3 3 3 3 3 4 4 3 3 3 ...
$ Quarter : Factor w/ 3 levels "Quarter 1","Quarter 2",..: 1 1 1 1 1 1 1 1 1 1 ...
head(train)
Functional_Area Operating_Company Service_Type Ticket_Category Ticket_Resolution Priority Quarter
2 DCF DCF FUN SR Defect Priority 3 Quarter 1
3 DCF DCF FUN SR OK Priority 3 Quarter 1
4 APS DCF APS SR Defect Priority 3 Quarter 1
5 DCF DCF FUN SR OK Priority 3 Quarter 1
6 SEC DCF SEC SR OK Priority 4 Quarter 1
8 FUN DCF FUN SR OK Priority 3 Quarter 1
Link to the dataset is included here
非常感谢。