当前位置:网站首页>R language universalbank CSV "data analysis

R language universalbank CSV "data analysis

2022-06-22 20:53:00 Mrrunsen

(10 branch ) Take the data set used in the second operation ( flight delay Flightdelayscsv And loan receipt Universal Bank. csv Choose any one of ) For example , Comprehensive use of a variety of classification supervised learning methods , Include ,kNN, glmnet, Regression classification tree , Random forest and so on , Set your own training set ( Estimate the optimal model ) And test set ( Evaluation model ), Compare the classification accuracy of different methods ( Or misclassification error rate, and give the selection results of important characteristic variables by different model methods .

set.seed(123)
df = read.csv("UniversalBank.csv",stringsAsFactors = TRUE)
#  Remove ID 
df = df[,-1]
df$CreditCard <- as.factor(df$CreditCard )
#  Divide the training set and the test set 
train <- sample(nrow(df), 0.9*nrow(df)) 
df.train <- df[train,] 
df.validate <- df[-train,] 
# kNN
library(kknn)
knn <- kknn(CreditCard ~ .,df.train,df.validate)
# Predict on the test set 
pre_knn <- fitted(knn)
# Output obfuscation matrix 
library(caret)
confusionMatrix(df.validate$CreditCard, pre_knn)

 Insert picture description here

be based on KNN Model Of The accuracy is 0.698

Logical regression

log <- glm(CreditCard ~ .,  data = df.train, family=binomial()) 
prob <- predict(log, df.validate, ty
原网站

版权声明
本文为[Mrrunsen]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206221917182240.html