-
Notifications
You must be signed in to change notification settings - Fork 3
/
feature-eng-agerisk.R
68 lines (64 loc) · 1.78 KB
/
feature-eng-agerisk.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
# The 18 - 29 age group has an average credit score of 637.
# The 30 - 39 age group has an average score of 654.
# The 40 - 49 age group has an average score of 675.
# The 50 - 59 age group has an average score of 697.
# The 60 - 69 age group has an average score of 722.
# The 70 plus age group has an average score of 747.
# Agerisk = 1 - (CreditScore / 850)
setwd('F:/Miaozhi/Academic/Data_Science/Bootcamp/Project_Capstone/nycdsa-capstone')
data = read.csv('./data/cs-training-outlier-f10.csv', header =T)
test = read.csv('./data/cs-test-outlier-f10.csv', header = T)
AgeRisk=1:150000
AgeRisk=1:101503
for(i in 1:150000){
if(data$age[i]<29){
AgeRisk[i]= 1-637/850
}else{
if(data$age[i]<39){
AgeRisk[i]=1-654/850
}else{
if(data$age[i]<49){
AgeRisk[i]=1-675/850
}else{
if(data$age[i]<59){
AgeRisk[i]=1-697/850
}else{
if(data$age[i]<69){
AgeRisk[i]=1-722/850
}else{
AgeRisk[i]=1-747/850
}
}
}
}
}
}
for(i in 1:101503){
if(test$age[i]<29){
AgeRisk[i]= 1-637/850
}else{
if(test$age[i]<39){
AgeRisk[i]=1-654/850
}else{
if(test$age[i]<49){
AgeRisk[i]=1-675/850
}else{
if(test$age[i]<59){
AgeRisk[i]=1-697/850
}else{
if(test$age[i]<69){
AgeRisk[i]=1-722/850
}else{
AgeRisk[i]=1-747/850
}
}
}
}
}
}
data = data[,-4]
test = test[,-4]
data = as.data.frame(cbind(data,AgeRisk))
test = as.data.frame(cbind(test,AgeRisk))
write.csv(data,'cs-training-outlier-agerisk-f10.csv')
write.csv(test,'cs-test-outlier-agerisk-f10.csv')