-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolyr.R
More file actions
53 lines (41 loc) · 1009 Bytes
/
Copy pathpolyr.R
File metadata and controls
53 lines (41 loc) · 1009 Bytes
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
library(dplyr)
library(polyreg)
library(scales)
set.seed(237)
# This script fits polynomial of degree to our data
train_df <- (train_df
%>% mutate(diagnosis = as.character(diagnosis))
%>% select(31:1) # Reorder the variables - polyreg
)
test_df <- (test_df
%>% mutate(diagnosis = as.character(diagnosis))
%>% select(31:1)
)
# Cross validation to pick optimal no. of degrees
poly_cv <- xvalPoly(train_df
, maxDeg=2
, use="glm"
)
#print(poly_cv)
# Fit the polynomial
poly_model <- polyFit(train_df
, deg = which.max(poly_cv)
, use = "glm"
)
# Predict
poly_pred <- predict(poly_model, test_df[, -31])
# Proportion of correct predictions - Polyreg
poly_pcp <- data.frame(model = "poly"
, pcp = mean(poly_pred == test_df$diagnosis)
)
# Proportion of correct prediction - NN
caret_pcp <- (obs_pred_df1
%>% group_by(model)
%>% summarise(pcp = mean(pred==obs))
)
# Everything together
pcp_tab <- (bind_rows(caret_pcp, poly_pcp)
%>% arrange(-pcp)
%>% mutate(pcp = percent(pcp))
)
pcp_tab