赞
踩
题目:ROC-AUC是一种常见的模型评价指标,它是ROC曲线下的面积。现在已经知道样本数据的真实值(1是正样本,0是负样本)和某个二分类起在样本数据集的预测值(属于正样本的概率,并且各不相同),求ROC-AUC,精确到小数点后两位。
第一行输入样本数N,然后输入N行,每行输入样本类别和预测概率值,空格隔开(1为正样例,0为负样例),计算AUC的值。
输入:
10
1 0.9
0 0.7
1 0.6
0 0.55
1 0.52
0 0.4
1 0.38
0 0.35
1 0.31
0 0.1
输出:
0.68
代码如下:
N = int(input())
gt, pre = [], []
for _ in range(N):
temp = list(map(float, input().split()))
gt.append(temp[0])
pre.append(temp[-1])
positive, negitive = [], []
for idx, i in enumerate(gt):
if i == 1.:
positive.append(idx)
else:
negitive.append(idx)
total = len(positive) * len(negitive)
fenzi = 0
for i in positive:
for j in negitive:
if pre[i] > pre[j]:
fenzi += 1.
elif pre[i] == pre[j]:
fenzi += 0.5
output = fenzi / total
print('%.2f' % output)
https://blog.csdn.net/jiangjieqazwsx/article/details/52262389
题目描述:
某车站为了方便管理,决定根据目的地以及出发时间的不同对车辆时刻表进行分组管理。要求:给定一个时刻表,
同一个目的地的车辆必须分配在同一组内,分组不能打乱时刻表的车次顺序,即各个分组之间出发时间有序。
请对时刻表尽可能多的分组,按出发时间早晚作为输出顺序。
输入
时刻表内容:aabbcddc,a,b,c,d为目的地,字母出现的先后顺序为出发时间的先后顺序
输出
输出各个分组的长度,以空格相隔,输出顺序与时刻表的出发顺序一致
样例输入
aabbcddc
样例输出
2,2,4
import sys
def fun(line_one):
ans = []
if len(line_one) == 0:
return []
for i in range(len(line_one)):
if line_one[0] == line_one[i]:
ans.append(i)
length = len(line_one[:ans[-1]])+1
return [length] + fun(line_one[ans[-1]+1:])
if __name__ == "__main__":
n = list(input())
answer = list(map(int,fun(n)))
print(' '.join(map(str, answer)))
对于两个字符串,利用字符操作,把字符串A转换成字符串B所需要的最少操作数。其中,字符操作包括:
1.删除一个字符
2.插入一个字符
3.修改一个字符
示例:
输入:
携程欢迎您
欢迎你程里人
输出:6
def strdist(str1, str2):
t = [[0 for x in range(len(str2)+1)] for x in range(len(str1)+1)]
for i in range(len(str1)+1):
for j in range(len(str2)+1):
if i == 0:
t[i][j] = j
elif j == 0:
t[i][j] = i
elif str1[i-1] == str2[j-1]:
t[i][j] = t[i-1][j-1]
else:
t[i][j] = 1 + min(t[i][j-1], t[i-1][j], t[i-1][j-1])
return t[len(str1)][len(str2)]
# str1 = '携程欢迎您'
# str2 = '欢迎你程里人'
str_ = list(map(str, input().split('<ctrip>')))
str1 = str_[0]
str2 = str_[1]
print(strdist(str1, str2))
第一行输入m(数组行数)和n(数组列数),空格隔开,接下来每一行输入n个数字用空格隔开;输出以顺时针顺序的螺旋数组。
示例:
输入:
3 3
1 2 3
4 5 6
7 8 9
输出:
1,2,3,6,9,8,7,4,5
3.给定一个词典W(保证词典的数据不重复),输入一句文本S,使用词典进行分词。如果文本能够根据词典进行分词,则输出YES,否则输出NO
示例:
输入:
我,要,爱,携程,携程旅行网,旅行网,旅行
我爱携程旅行网
输出:
YES
import jieba
w = list(input().split(','))
s = input()
# print(w, s)
seq_list=list(jieba.cut(s, cut_all=False))
# print(seq_list)
count = []
for i in seq_list:
# print(i)
if i in w:
count.append(1)
else:
count.append(0)
if 0 in count:
print('NO')
else:
print('YES')
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。