-
Notifications
You must be signed in to change notification settings - Fork 0
/
predict.R
48 lines (34 loc) · 1.41 KB
/
predict.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
# This script is used to predict prices from your model.
#
# DO NOT MODIFY.
source("model.R") # Load your code.
# This script expects sys.args arguments for (1) the dataset and (2) the output file.
output_dir = Sys.getenv('OUTPUTS_DIR', '.')
input_dataset = Sys.getenv('DATASET_PATH', 'training.csv') # The default value.
output_claims_file = paste(output_dir, 'claims.csv', sep = '/') # The file where the expected claims should be saved.
output_prices_file = paste(output_dir, 'prices.csv', sep = '/') # The file where the prices should be saved.
args = commandArgs(trailingOnly=TRUE)
if(length(args) >= 1){
input_dataset = args[1]
}
if(length(args) >= 2){
output_claims_file = args[2]
}
if(length(args) >= 3){
output_prices_file = args[3]
}
# Load the dataset.
# Remove the claim_amount column if it is in the dataset.
Xraw = read.csv(input_dataset)
if('claim_amount' %in% colnames(Xraw)){
Xraw = within(Xraw, rm('claim_amount'))
}
# Load the saved model, and run it.
trained_model = load_model()
if(Sys.getenv('WEEKLY_EVALUATION', 'false') == 'true') {
prices = predict_premium(trained_model, Xraw)
write.table(x = prices, file = output_prices_file, row.names = FALSE, col.names=FALSE, sep = ",")
} else {
claims = predict_expected_claim(trained_model, Xraw)
write.table(x = claims, file = output_claims_file, row.names = FALSE, col.names=FALSE, sep = ",")
}