【发布时间】:2018-10-17 16:22:21
【问题描述】:
我有大约 50,000 名客户,其中 10,000 名按年龄组(65 岁以下和 65 岁以上)是已知的。我有每个客户购买品牌的历史。我想建立一个模型来根据购买历史预测客户属于哪个年龄段。我运行该模型,它显示了一些错误(下文详述)。
问题:
我可以使用 naiveBayes 模型来预测客户属于哪个年龄组吗?
如何理解我的模型为什么不起作用
如果我有客户的年龄,使用哪个模型来预测年龄,而不是 age_group?
提前非常感谢
# building train and test sets
set.seed(100)
train_set_indexes <- sample (1:nrow(demand_by_customer_brand_year_2018_row), size = 5000)
train_set <- demand_by_customer_brand_year_2018_row [train_set_indexes, ]
test_set <- demand_by_customer_brand_year_2018_row [-train_set_indexes, ]
# Applying a model (naiveBayes) on train set
library(e1071)
model_age <- naiveBayes(Customer_Age_Group ~ ., data = train_set)
# Predicting the class labels of the train set
predicted_labels <- predict(model_age, test_set)
summary(model_age)
True_labels <- test_set[,1]
head(True_labels)
table1 <- table (True_labels,predicted_labels)
table1
# output of summary(model_age)
Length Class Mode
apriori 2 table numeric
tables 741 -none- list
levels 0 -none- NULL
call 4 -none- call
# Output when processing table1 <- table (True_labels,predicted_labels)
Error in table(True_labels, predicted_labels) : object 'True_labels' not found
【问题讨论】:
-
Brian,将其迁移到 CrossValidated 的投票越来越多。我相信您无需采取任何行动。这不是对这个问题的投票,更多的是迁移到像这样的学术讨论更合适的地方。 (SO 更多的是关于编程问题,这似乎不是。)祝你好运!
-
你运行后应该也有错误
True_labels <- test_set[,1],你能检查一下吗? -
True_labels
-
没有错误,运行正常
-
这里显示的是真实标签:[1]“妈妈”“妈妈”“妈妈”“妈妈”“高级”“高级”“高级”“高级”“高级”“高级”“妈妈” ”“前辈”“前辈”“前辈”“前辈”“前辈”“前辈”“前辈”“前辈”“前辈”“前辈”[22]“前辈”“妈妈”“前辈”