-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path22.21 - Multinomial Logistic Regresyon 2 - Veri Ön İşleme II.R
executable file
·81 lines (54 loc) · 2.02 KB
/
22.21 - Multinomial Logistic Regresyon 2 - Veri Ön İşleme II.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#install.packages("nnet")
library(tidyverse)
library(nnet)
modelData <- read.csv('heart.csv')
View(modelData)
modelData <- modelData[ , -which(names(modelData) == "target")]
table(modelData$cp)
modelData <- modelData[modelData$cp != 3 , ]
table(modelData$cp)
modelData <- modelData %>% mutate(
cp = as.factor(cp),
slope = as.factor(slope),
ca = as.factor(ca),
thal = as.factor(thal),
restecg = as.factor(restecg)
)
table(modelData$restecg)
## Train ve Test Ayrımı
trainTestSplit <- function(data , dvName , seed){
tbl <- table(data[,dvName])
classes <- names(tbl)
minClass <- min(tbl)
lengthClass <- length(tbl)
train <- data.frame()
test <- data.frame()
for(i in 1:lengthClass){
selectedClass <- data[,dvName] == classes[i]
set.seed(seed)
sampleIndex <- sample(1:nrow(data[selectedClass , ]) , size = minClass*0.8)
train <- rbind(train , data[selectedClass , ][sampleIndex , ])
test <- rbind(test , data[selectedClass , ][-sampleIndex , ])
}
return(list(train , test))
}
train <- trainTestSplit(modelData , "cp" , 125)[[1]]
test <- trainTestSplit(modelData , "cp" , 125)[[2]]
table(train$cp)
table(test$cp)
plot(train$age , train$cp , pch = 19 , bty = "L")
plot(train$trestbps , train$cp , pch = 19 , bty = "L")
plot(train$chol , train$cp , pch = 19 , bty = "L")
plot(train$thalach , train$cp , pch = 19 , bty = "L")
plot(train$oldpeak , train$cp , pch = 19 , bty = "L")
plot(as.factor(train$sex) , train$cp)
plot(as.factor(train$slope) , train$cp)
table(train$sex , train$cp)
table(train$cp)
table(train$sex)
levels(train$cp)
par(mfrow=c(2,2))
plot(train$cp , train$age , main = "Age" )
plot(train$cp , train$thalach , main = "Thalach")
plot(train$cp , train$trestbps)
plot(train$cp , train$age)