我无法使功能与下面的示例相同我只返回3分以上的返回值
过滤质量将根据以下公式确定:
q=((TP+TN)/(TP+TN+10*FP+FN))
正面案例(P)是过滤器分类为垃圾邮件的电子邮件,否定案例(N)是过滤器分类为普通电子邮件的电子邮件。因此,FP是错误标记为垃圾邮件的电子邮件数量,FN是未经标记的垃圾邮件数量。
值得注意的是,TP, FP, TN, FN
是频率(案例数),而不是百分比。
您的过滤器将在3个不同的数据集上进行评估。对于每个数据集,您的过滤器可能会得到0到3个点:
q pts
<0, 0.3) 0
<0.3, 0.5) 1
<0.5, 0.7) 2
<0.7, 0.9) 2.5
<0.9, 1> 3
我的代码到目前为止:
def quality_score(TP, TN, FP, FN):
q=(TP+TN//TP+TN+10*FP+FN)
return q
答案 0 :(得分:0)
将质量得分表放入具有范围起始值的列表中。首先,根据公式计算“q”值。然后,在表格中查找q值以获得最终质量点。
<link rel="stylesheet" type="text/css" href="style.css">
<div class="container">
<div class="hook">
<video onended="playNext()" width="640" height="480" id="myVideo" controls autoplay>
</video>
</div>
<div>
<ul>
<li><a id="vid1" href="#"><img src="http://placehold.it/200x100"></a> </li>
<li><a id="vid2" href="#"><img src="http://placehold.it/200x100"></a></li>
<li><a id="vid3" href="#"><img src="http://placehold.it/200x100"></a></li>
</ul>
</div>
<!-- /.hook -->
</div>
<!-- /.container -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min.js"> </script>
<script type="text/javascript">
var conUrlCount = 0;
var myVideo = document.getElementById("myVideo");
//parsedData should be declared outside the function scope since we want it to be accessible from outside
var parsedData;
var callback = function (text) {
parsedData = JSON.parse(text);
console.log('parsed',parsedData)
conUrlCount = 0;
//after load play the first video
playNext();
};
//when page is loaded, data in json file is parsed and returned
function loadFunction() {
//returning json data
//ajax.get("clips.json", callback);
//simulate
getAjax(callback);
};
function playNext() {
if (!parsedData) {
return
}
var myVideo = document.getElementById("myVideo");
myVideo.src = parsedData[conUrlCount]['content-url'];
myVideo.play();
conUrlCount+1;
}
//to simulate
function getAjax(callback) {
setTimeout(function () {
callback(JSON.stringify([{
"id": "vid1",
"name": "#",
"description": "#",
"content-url": "video1.mp4",
"thumb-url": "#"
}, {
"id": "vid2",
"name": "#",
"description": "#",
"content-url": "video2.mp4",
"thumb-url": "#"
}, {
"id": "vid3",
"name": "#",
"description": "#",
"content-url": "video3.mp4",
"thumb-url": "#"
},{
"id": "vid4",
"name": "#",
"description": "#",
"content-url": "video4.mp4",
"thumb-url": "#"
} ]))
}, 100)
}
loadFunction();
document.getElementById("vid1").addEventListener("click", loadFunction);
document.getElementById("vid2").addEventListener("click", loadFunction);
document.getElementById("vid3").addEventListener("click", loadFunction);
</script>
此代码还检查q值是否超出范围[0,1]。
用法:
pointsTable = [
(0, 0),
(0.3, 1),
(0.5, 2),
(0.7, 2.5),
(0.9, 3)
]
def calculate_quality_points(tp, tn, fp, fn):
q = get_quality_score(tp, tn, fp, fn)
return get_quality_points(q)
def get_quality_score(tp, tn, fp, fn):
return float(tp + tn) / (tp + tn + 10 * fp + fn)
def get_quality_points(q):
i = 0
if q < 0 or q > 1:
return -1
for i in range(len(pointsTable) - 1):
if q >= pointsTable[i][0] and q < pointsTable[i + 1][0]:
return pointsTable[i][1]
return pointsTable[len(pointsTable) - 1][1]