-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeToRun.R
More file actions
137 lines (123 loc) · 4.01 KB
/
Copy pathCodeToRun.R
File metadata and controls
137 lines (123 loc) · 4.01 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
library(dplyr)
outcomeId <- 1758 # CCA
cdmDatabaseSchema <- "cdm"
cohortsDatabaseSchema <- "results"
workDatabaseSchema <- cohortsDatabaseSchema
cdmDatabaseName <- "IPCI"
cohortTable <- "cohort"
splitSettings <- createDefaultSplitSetting(splitSeed = 64975L)
sampleSettings <- createSampleSettings(type = 'none')
featureEngineeringSettings <- createFeatureEngineeringSettings(type = 'none')
preprocessSettings <- createPreprocessSettings()
executeSettings <- createExecuteSettings(
runSplitData = TRUE,
runSampleData = TRUE,
runfeatureEngineering = TRUE,
runPreprocessData = TRUE,
runModelDevelopment = TRUE,
runCovariateSummary = TRUE
)
covariateSettings <- FeatureExtraction::createCovariateSettings(
useDemographicsAge = TRUE,
useDemographicsGender = TRUE,
useConditionOccurrenceAnyTimePrior = TRUE
)
populationSettings <- createStudyPopulationSettings(
firstExposureOnly = FALSE,
washoutPeriod = 0,
removeSubjectsWithPriorOutcome = FALSE,
priorOutcomeLookback = 99999,
requireTimeAtRisk = TRUE,
minTimeAtRisk = 1,
riskWindowStart = 0,
startAnchor = 'cohort start',
riskWindowEnd = 365,
endAnchor = 'cohort end'
)
# Load data once
plpData_small <- loadPlpData(file = "/fvereijken/Documents/StudyEvalMetrics/Data/CCA/")
# Define evaluation metrics and folder names
eval_metrics <- c(
computeAuc = "AUC",
averagePrecision = "AvgP",
accuracyScore = "Accuracy",
precisionScore = "Precision",
recallScore = "Recall",
f1Scores = "f1",
logLossScore = "LogLoss",
specificityScore = "Specificity",
mccScore = "MCC",
balancedAccuracyScore = "BalancedAccuracy",
gMeanScore = "GMean",
kappaScore = "Kappa",
f2Score = "f2",
rmseScore = "RMSE",
maeScore = "MAE"
)
# Helper function to run models for all eval metrics
run_all_metrics <- function(analysisId, modelSettings, basePath) {
for (metric in names(eval_metrics)) {
saveDir <- file.path(basePath, eval_metrics[[metric]])
runPlp(
plpData = plpData_small,
outcomeId = outcomeId,
analysisId = analysisId,
populationSettings = populationSettings,
splitSettings = splitSettings,
sampleSettings = sampleSettings,
featureEngineeringSettings = featureEngineeringSettings,
preprocessSettings = preprocessSettings,
modelSettings = modelSettings,
evalmetric = metric,
executeSettings = executeSettings,
saveDirectory = saveDir
)
}
}
# Model settings
modelsettingsDT <- setDecisionTree(
seed = 333L,
criterion = list('gini', 'entropy'),
splitter = list('best', 'random'),
maxDepth = list(as.integer(4), as.integer(10), as.integer(20), NULL),
minSamplesSplit = list(2, 5, 10),
minSamplesLeaf = list(10, 50),
maxFeatures = list('log2', 'sqrt', 100, NULL),
minImpurityDecrease = list(1e-7, 1e-4)
)
modelsettingsAda <- setAdaBoost(
seed = 333L,
nEstimators = list(5, 10, 20, 50, 75, 100, 200, 300),
learningRate = list(1, 0.5, 0.1, 0.01, 0.001)
)
modelsettingsGBM <- setGradientBoostingMachine(
seed = 333L,
ntrees = c(100, 300, 500),
nthread = 20,
earlyStopRound = 25,
maxDepth = c(4, 6, 8, 10),
minChildWeight = c(1, 3, 5),
learnRate = c(0.01, 0.05, 0.1, 0.3),
scalePosWeight = c(1, 10),
lambda = c(0, 0.1, 1, 5, 10),
alpha = c(0, 0.1, 0.5, 1, 5)
)
modelsettingsLGBM <- setLightGBM(
seed = 333L,
nthread = 20,
earlyStopRound = 25,
numIterations = c(100, 300, 500),
numLeaves = c(31, 63, 127),
maxDepth = c(5, 10, 15, -1),
minDataInLeaf = c(20, 50, 100),
learningRate = c(0.01, 0.05, 0.1, 0.3),
lambdaL1 = c(0, 0.5, 1),
lambdaL2 = c(0, 0.5, 1),
scalePosWeight = c(1, 10),
isUnbalance = c(FALSE)
)
# Run all models
run_all_metrics("DecisionTree", modelsettingsDT, "/fvereijken/Documents/StudyEvalMetrics/Models/CCA/DecisionTree")
run_all_metrics("AdaBoost", modelsettingsAda, "/fvereijken/Documents/StudyEvalMetrics/Models/CCA/Adaboost")
run_all_metrics("GBM", modelsettingsGBM, "/fvereijken/Documents/StudyEvalMetrics/Models/CCA/GBM")
run_all_metrics("LGBM", modelsettingsLGBM, "/fvereijken/Documents/StudyEvalMetrics/Models/CCA/LGBM")