「」不同机器学习模型的决策边界(附代码)( 三 )


####################################################################################################################################################################### params_lightGBM %mutate(modeln = str_c('mod', row_number()))%>%pmap(~{xname = ..1yname = ..2modelname = ..3df %>%select(Species, xname, yname) %>%group_by(grp = 'grp') %>%nest() %>%mutate(models = map(data, ~{list(# Logistic ModelModel_GLM = { glm(Species ~ ., data = http://news.hoteastday.com/a/.x, family = binomial(link='logit'))},# Support Vector Machine (linear)Model_SVM_Linear = {e1071::svm(Species ~ ., data = http://news.hoteastday.com/a/.x,type ='C-classification', kernel = 'linear')},# Support Vector Machine (polynomial)Model_SVM_Polynomial = {e1071::svm(Species ~ ., data = http://news.hoteastday.com/a/.x,type ='C-classification', kernel = 'polynomial')},# Support Vector Machine (sigmoid)Model_SVM_radial = {e1071::svm(Species ~ ., data = http://news.hoteastday.com/a/.x,type ='C-classification', kernel = 'sigmoid')},# Support Vector Machine (radial)Model_SVM_radial_Sigmoid = {e1071::svm(Species ~ ., data = http://news.hoteastday.com/a/.x,type ='C-classification', kernel = 'radial')},# Random ForestModel_RF = {randomForest::randomForest(formula = as.factor(Species) ~ ., data = http://news.hoteastday.com/a/.)},# Extreme Gradient BoostingModel_XGB = {xgboost(objective ='binary:logistic',eval_metric = 'auc',data = http://news.hoteastday.com/a/as.matrix(.x[, 2:3]),label = as.matrix(.x$Species), # binary variablenrounds = 10)},# Kera Neural NetworkModel_Keras = {mod %layer_dense(units = 2, activation ='relu', input_shape = 2) %>%layer_dense(units = 2, activation = 'sigmoid')mod %>% compile(loss = 'binary_crossentropy',optimizer_sgd(lr = 0.01, momentum = 0.9),metrics = c('accuracy'))fit(mod,x = as.matrix(.x[, 2:3]),y = to_categorical(.x$Species, 2),epochs = 5,batch_size = 5,validation_split = 0)print(modelname)assign(modelname, mod)},# Kera Neural NetworkModel_Keras_2 = {mod %layer_dense(units = 2, activation = 'relu', input_shape = 2) %>%layer_dense(units = 2, activation = 'linear', input_shape = 2) %>%layer_dense(units = 2, activation = 'sigmoid')mod %>% compile(loss = 'binary_crossentropy',optimizer_sgd(lr = 0.01, momentum = 0.9),metrics = c('accuracy'))fit(mod,x = as.matrix(.x[, 2:3]),y = to_categorical(.x$Species, 2),epochs = 5,batch_size = 5,validation_split = 0)print(modelname)assign(modelname, mod)},# Kera Neural NetworkModel_Keras_3 = {mod %layer_dense(units = 2, activation = 'relu', input_shape = 2) %>%layer_dense(units = 2, activation = 'relu', input_shape = 2) %>%layer_dense(units = 2, activation = 'linear', input_shape = 2) %>%layer_dense(units = 2, activation = 'sigmoid')mod %>% compile(loss = 'binary_crossentropy',optimizer_sgd(lr = 0.01, momentum = 0.9),metrics = c('accuracy'))fit(mod,x = as.matrix(.x[, 2:3]),y = to_categorical(.x$Species, 2),epochs = 5,batch_size = 5,validation_split = 0)print(modelname)assign(modelname, mod)},# LightGBM modelModel_LightGBM = {lgb.train(data = http://news.hoteastday.com/a/lgb.Dataset(data = as.matrix(.x[, 2:3]), label = .x$Species),objective ='binary',metric = 'auc',min_data = http://news.hoteastday.com/a/1#params = params_lightGBM,#learning_rate = 0.1)})}))}) %>%map(., ~unlist(., recursive = FALSE))校准数据


推荐阅读