在得出基础分和各部分得分后,两者相加即可得出个人总评分,自定义compute_score函数来找到每一行数据根据分箱得出的分数段的得分,最想通过各评分相加得出最终评分,并对最终结果进行输出。
compute_score函数
def compute_score(series, bins, score):
list = []
i = 0
while i < len(series):
value = series[i]
j = len(bins) - 2
m = len(bins) - 2
while j >= 0:
if value >= bins[j]:
j = -1
else:
j -= 1
m -= 1
list.append(score[m])
i += 1
return list
得出各部分评分相加并得到最终评分输出
test1 = pd.read_csv('TestData.csv')
test1['BaseScore'] = Series(np.zeros(len(test1)))+baseScore
test1['RUOUL_score'] = Series(compute_score(test1['RevolvingUtilizationOfUnsecuredLines'], RevolvingUtilizationOfUnsecuredLines_bins, RUOUl_score))
test1['age_score'] = Series(compute_score(test1['age'], age_bins, age_score))
test1['NumberOfTime30-59DaysPastDueNotWorse_score'] = Series(compute_score(test1['NumberOfTime30-59DaysPastDueNotWorse'], NotWorse3059_bins, NotWorse3059_score))
test1['NumberOfTimes90DaysLate_score'] = Series(compute_score(test1['NumberOfTimes90DaysLate'], NumberOfTimes90DaysLate_bins,NumberOfTimes90DaysLate_score))
test1['NumberOfTime60-89DaysPastDueNotWorse_score'] = Series(compute_score(test1['NumberOfTime60-89DaysPastDueNotWorse'], NotWorse6089_bins, NotWorse6089_score))
test1['Score'] = test1['RUOUL_score'] + test1['age_score'] + test1['NumberOfTime30-59DaysPastDueNotWorse_score'] + test1['NumberOfTimes90DaysLate_score'] + test1['NumberOfTime60-89DaysPastDueNotWorse_score'] + baseScore
test1.to_csv('ScoreData.csv', index=False)