参考学习:
def score_class(score):
if score < 60:
return "不及格"
elif score >= 60 and score < 70:
return "及格"
elif score >= 70 and score < 80:
return "中等"
elif score >= 80 and score < 90:
return "良好"
elif score >= 90 and score <= 100:
return "优秀"
elif score == 100:
return "满分"
score_list = [82, 70, 90, 0, 100,45]
score_dict = {}
for score in score_list:
score_dict[score] = score_class(score)
print(score_dict)
不知道你这个问题是否已经解决, 如果还没有解决的话:分析五个模型的分词结果,我们发现不管是基于词典的最大匹配法,基于统计的隐式马尔可夫模型,还是二者混合的 Unigram 模型,均无法有效的将时间,数字,人名和地名准确的切分处理。其原因在于最大匹配是基于字典的切分方式,当遇到字典中未出现的词语时,最大匹配法无法正确的切分。
解决方法:因为数字和日期的出现规律较为单一,所以采用人工规定义规则的方式,增加了基于规则的数字,日期匹配算法。将所有的数字单独分做一个词。如果数字末尾有年、月、日,则和其合并为一个词。
缺点是不能覆盖所有的情况,以文字出现的日期和数字情况多样,难以用规则描述。如:上千、一两等等。
通过实验,我们取得了 3%的 F1 值提升。 具体结果如下表所示。
表3 加入日期数字后最大匹配法结果展示
模型 | Precision | Recall | F1 | 速度(字/s) |
---|---|---|---|---|
前向 | 0.907 | 0.931 | 0.919 | 9300+ |
后向 | 0.909 | 0.933 | 0.921 | 17000+ |
双向 | 0.910 | 0.933 | 0.921 | 5700+ |
grade = ["不及格"]*6 + ["及格","中等","良好","优秀","满分"]
scores = [82, 70, 90, 0, 100, 45]
res = {i:grade[i//10] for i in scores}
print(res)
自定义函数实现分数等级判断。:
def toDict(scores):
dict = {}
for score in scores:
if score < 60:
dict[score] = '不及格'
elif score < 70:
dict[score] = '及格'
elif score < 80:
dict[score] = '中等'
elif score < 90:
dict[score] = '良好'
elif score < 100:
dict[score] = '优秀'
else:
dict[score] = '满分'
return dict
scores = [82,70,90,0,100,45]
dict = toDict(scores)
for k,v in dict.items():
print(k,v)
运行结果: