我正在使用神经网络包中的神经网络功能来训练神经网络,然后使用公开可用的数据集进行预测,该数据集可以在UCI机器学习库中找到。
在应用模型之前,我将数据集的所有因子变量转换为数字虚拟变量,然后将数据集拆分为训练和测试。
我的代码和收到的消息如下:
library(neuralnet)
class(german_train$Class)
[1] "numeric"
> model_nn1 <- neuralnet(formula = formula_nn, data = german_train, hidden = c(10 , 5),
+ threshold = 0.01, stepmax = 1e+05, rep = 3,
+ startweights = rnorm(80), learningrate.limit = NULL,
+ learningrate.factor = list(minus = 0.5, plus = 1.2),
+ learningrate=NULL, lifesign = "none", lifesign.step = 1000,
+ algorithm = "rprop+", err.fct = "sse", act.fct = "logistic",
+ linear.output = TRUE, exclude = NULL, constant.weights = NULL, likelihood = FALSE)
Warning message:
some weights were randomly generated, because 'startweights' did not contain enough values
> predict_nn <- prediction(model_nn, german_test)
Error in list.glm[[i]]$fitted.values :
$ operator is invalid for atomic vectors
> dim(german_test)
[1] 300 62
> dim(german_train)
[1] 700 62
> names(model_nn1)
[1] "call" "response" "covariate" "model.list" "err.fct"
[6] "act.fct" "linear.output" "data" "net.result" "weights"
[11] "startweights" "generalized.weights" "result.matrix"
> formula_nn
Class ~ D_Status_of_existing_account__between_0_and_200 + D_Status_of_existing_account__greater_equal_to_200 +
D_Status_of_existing_account__less_than_0 + D_Status_of_existing_account__No_Account +
Duration_in_month + D_Credit_history__All_paid_in_this_bank +
D_Credit_history__Delay_in_the_Past + D_Credit_history__No_credits_or_All_paid +
D_Credit_history__Other_Accounts + D_Credit_history__Paid_duly_until_now +
D_Purpose__Appliances + D_Purpose__Business + D_Purpose__Car_new +
D_Purpose__Car_used + D_Purpose__Education + D_Purpose__Furniture_Equipment +
D_Purpose__Other + D_Purpose__Radio_TV + D_Purpose__Repairs +
D_Purpose__Retraining + Credit_amount + D_Savings_account_bonds__between_100_and_500 +
D_Savings_account_bonds__between_500_and_1000 + D_Savings_account_bonds__greater_than_1000 +
D_Savings_account_bonds__less_than_100 + D_Savings_account_bonds__Unknown_or_None +
D_Present_employment_since__between_1_and_4 + D_Present_employment_since__between_4_and_7 +
D_Present_employment_since__greater_than_7 + D_Present_employment_since__less_than_1 +
D_Present_employment_since__Unemployed + Installment_rate_in_percentage_of_disposable_income +
D_Personal_status_and_sex__Female_Non_Single + D_Personal_status_and_sex__Male_Divorced_Separated +
D_Personal_status_and_sex__Male_Married_Widowed + D_Personal_status_and_sex__Male_Single +
D_Other_debtors_guarantors__Co_applicant + D_Other_debtors_guarantors__Guarantor +
D_Other_debtors_guarantors__None + Present_residence_since +
D_Property__Building_Savings_LifeInsurance + D_Property__Car_Other +
D_Property__Real_Estate + D_Property__Unknown_None + Age +
D_Other_installment_plans__Bank + D_Other_installment_plans__None +
D_Other_installment_plans__Stores + D_Housing__For_Free +
D_Housing__Own + D_Housing__Rent + Number_of_existing_credits_at_this_bank +
D_Job__Manager_Professional_Self_Empl + D_Job__Skilled +
D_Job__Unemployed_Unskilled_Non_Resident + D_Job__Unskilled_Non_Resident +
Number_of_people_being_liable_to_provide_maintenance + D_Telephone__No_Telephone +
D_Telephone__Telephone + D_foreign_worker__Foreign_Worker +
D_foreign_worker__Not_Foreign_Worker
正如您所看到的,当我使用经过训练的模型运行predict()函数时,我收到一条错误消息。
您的建议将不胜感激。