我必须在剪辑中使用TP,TN,FP,FN参数的一些规则来计算一般预测准确度。
我的规则是x1 <=0.58 AND x6 <=0.61 x5
mcg<=0.61 --> Class = cp
。
我编写了代码,但是当我尝试运行代码时,我面临错误消息。可能有一个我找不到的错误。
可以请任何人帮助我???
这是我的代码:
(defrule rule1
(rw6 ?x6)
(rw5 ?x5)
(rw1 ?x1)
(test (<= ?x6 0.58))
(test (<= ?x5 0.61))
(test (<= ?x1 0.61))
?fact1 <- (TP1 ?TP1)
?fact2 <- (FP1 ?FP1)
?fact3 <- (TN2 ?TN2)
?fact4 <- (TN3 ?TN3)
?fact5 <- (TN4 ?TN4)
?fact6 <- (FN2 ?FN2)
?fact7 <- (FN3 ?FN3)
?fact8 <- (FN4 ?FN4)
?fact9 <- (K1 ?K1)
?fact10 <- (K2 ?K2)
?fact11 <- (K3 ?K3)
?fact12 <- (K4 ?K4)
?fact13 <- (row (rw1 ?x1)(rw2 ?x2)(rw3 ?x3)(rw4 ?x4)(rw5 ?x5)(rw6 ?x6)(rw7 ?x7)(class ?c))
=>
(if (= ?c cp) then
(retract ?fact1 ?fact3 ?fact4 ?fact5 ?fact9)
(assert (TP1 (+ ?TP1 1))(TN2 (+ ?TN2 1))(TN3 (+ ?TN3 1))(TN4 (+ ?TN4 1))(K1 (+ ?K1 1))))
else (if (= ?c im) then
(retract ?fact2 ?fact4 ?fact5 ?fact6 ?fact10)
(assert (FP1 (+ ?FP1 1))(TN3 (+ ?TN3 1))(TN4 (+ ?TN4 1))(FN2 (+ ?FN2 1))(K2 (+ ?K2 1))))
else (if (= ?c pp) then
(retract ?fact2 ?fact3 ?fact5 ?fact7 ?fact11)
(assert (FP1 (+ ?FP1 1))(TN2 (+ ?TN2 1))(TN4 (+ ?TN4 1))(FN3 (+ ?FN3 1))(K3 (+ ?K3 1))))
else (if (= ?c om) then
(retract ?fact2 ?fact3 ?fact4 ?fact8 ?fact12)
(assert (FP1 (+ ?FP1 1))(TN2 (+ ?TN2 1))(TN3 (+ ?TN3 1))(FN4 (+ ?FN4 1))(K4 (+ ?K4 1))))
(retract ?fact13))
(defrule rule2
(K1 ?K1)
(K2 ?K2)
(K3 ?K3)
(K4 ?K4)
(TP1 ?TP1)
(FP1 ?FP1)
(FN1 ?FN1)
(TP2 ?TP2)
(FP2 ?FP2)
(FN2 ?FN2)
(TP3 ?TP3)
(FP3 ?FP3)
(FN3 ?FN3)
(TP4 ?TP4)
(FP4 ?FP4)
(FN4 ?FN4)
?fact1 <- (REC1 0)
?fact2 <- (REC2 0)
?fact3 <- (REC3 0)
?fact4 <- (REC4 0)
?fact5 <- (PRE1 0)
?fact6 <- (PRE2 0)
?fact7 <- (PRE3 0)
?fact8 <- (PRE4 0)
?fact9 <- (FMES1 0)
?fact10 <- (FMES2 0)
?fact11 <- (FMES3 0)
?fact12 <- (FMES4 0)
?fact13 <- (waREC 0)
?fact14 <- (waPRE 0)
?fact15 <- (waFMES 0)
?fact13 <- (ACC 0)
=>
(retract ?fact1 ?fact2 ?fact3 ?fact4 ?fact5 ?fact6 ?fact7 ?fact8 ?fact9 ?fact10 ?fact11 ?fact12 ?fact13)
(assert (ACC (bind ?ACC (/ (+ ?TP1 ?TP2 ?TP3 ?TP4)(+ ?TP1 ?TP2 ?TP3 ?TP4 ?FN1 ?FN2 ?FN3 ?FN4)))))
(assert (REC1 (bind ?REC1 (/ ?TP1 (+ ?TP1 ?FN1)))))
(assert (REC2 (bind ?REC2 (/ ?TP2 (+ ?TP2 ?FN2)))))
(assert (REC3 (bind ?REC3 (/ ?TP3 (+ ?TP3 ?FN3)))))
(assert (REC4 (bind ?REC4 (/ ?TP4 (+ ?TP4 ?FN4)))))
(assert (PRE1 (bind ?PRE1 (/ ?TP1 (+ ?TP1 ?FP1)))))
(assert (PRE2 (bind ?PRE2 (/ ?TP2 (+ ?TP2 ?FP2)))))
(assert (PRE3 (bind ?PRE3 (/ ?TP3 (+ ?TP3 ?FP3)))))
(assert (PRE4 (bind ?PRE4 (/ ?TP4 (+ ?TP4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?K4 (+ ?K1 ?K2 ?K3 ?K4)) ?REC4)))))
答案 0 :(得分:0)
有三个问题。
您没有为行事实定义deftemplate。
您正在使用=将变量与rule1中的符号进行比较。如果您要比较非数字参数
,请使用eq在rule2中,事实地址?fact13绑定到两种不同的模式。
CLIPS>
(deftemplate row
(slot rw1)
(slot rw2)
(slot rw3)
(slot rw4)
(slot rw5)
(slot rw6)
(slot rw7)
(slot class))
CLIPS>
(defrule rule1
(rw6 ?x6)
(rw5 ?x5)
(rw1 ?x1)
(test (<= ?x6 0.58))
(test (<= ?x5 0.61))
(test (<= ?x1 0.61))
?fact1 <- (TP1 ?TP1)
?fact2 <- (FP1 ?FP1)
?fact3 <- (TN2 ?TN2)
?fact4 <- (TN3 ?TN3)
?fact5 <- (TN4 ?TN4)
?fact6 <- (FN2 ?FN2)
?fact7 <- (FN3 ?FN3)
?fact8 <- (FN4 ?FN4)
?fact9 <- (K1 ?K1)
?fact10 <- (K2 ?K2)
?fact11 <- (K3 ?K3)
?fact12 <- (K4 ?K4)
?fact13 <- (row (rw1 ?x1)(rw2 ?x2)(rw3 ?x3)(rw4 ?x4)(rw5 ?x5)(rw6 ?x6)(rw7 ?x7)(class ?c))
=>
(if (eq ?c cp) ; was =
then
(retract ?fact1 ?fact3 ?fact4 ?fact5 ?fact9)
(assert (TP1 (+ ?TP1 1))(TN2 (+ ?TN2 1))(TN3 (+ ?TN3 1))(TN4 (+ ?TN4 1))(K1 (+ ?K1 1))))
else
(if (eq ?c im)
then
(retract ?fact2 ?fact4 ?fact5 ?fact6 ?fact10)
(assert (FP1 (+ ?FP1 1))(TN3 (+ ?TN3 1))(TN4 (+ ?TN4 1))(FN2 (+ ?FN2 1))(K2 (+ ?K2 1))))
else
(if (eq ?c pp)
then
(retract ?fact2 ?fact3 ?fact5 ?fact7 ?fact11)
(assert (FP1 (+ ?FP1 1))(TN2 (+ ?TN2 1))(TN4 (+ ?TN4 1))(FN3 (+ ?FN3 1))(K3 (+ ?K3 1))))
else (if (eq ?c om)
then
(retract ?fact2 ?fact3 ?fact4 ?fact8 ?fact12)
(assert (FP1 (+ ?FP1 1))(TN2 (+ ?TN2 1))(TN3 (+ ?TN3 1))(FN4 (+ ?FN4 1))(K4 (+ ?K4 1))))
(retract ?fact13))
CLIPS>
(defrule rule2
(K1 ?K1)
(K2 ?K2)
(K3 ?K3)
(K4 ?K4)
(TP1 ?TP1)
(FP1 ?FP1)
(FN1 ?FN1)
(TP2 ?TP2)
(FP2 ?FP2)
(FN2 ?FN2)
(TP3 ?TP3)
(FP3 ?FP3)
(FN3 ?FN3)
(TP4 ?TP4)
(FP4 ?FP4)
(FN4 ?FN4)
?fact1 <- (REC1 0)
?fact2 <- (REC2 0)
?fact3 <- (REC3 0)
?fact4 <- (REC4 0)
?fact5 <- (PRE1 0)
?fact6 <- (PRE2 0)
?fact7 <- (PRE3 0)
?fact8 <- (PRE4 0)
?fact9 <- (FMES1 0)
?fact10 <- (FMES2 0)
?fact11 <- (FMES3 0)
?fact12 <- (FMES4 0)
?fact13 <- (waREC 0)
?fact14 <- (waPRE 0)
?fact15 <- (waFMES 0)
?fact16 <- (ACC 0)
=>
(retract ?fact1 ?fact2 ?fact3 ?fact4 ?fact5 ?fact6 ?fact7 ?fact8 ?fact9 ?fact10 ?fact11 ?fact12 ?fact13)
(assert (ACC (bind ?ACC (/ (+ ?TP1 ?TP2 ?TP3 ?TP4)(+ ?TP1 ?TP2 ?TP3 ?TP4 ?FN1 ?FN2 ?FN3 ?FN4)))))
(assert (REC1 (bind ?REC1 (/ ?TP1 (+ ?TP1 ?FN1)))))
(assert (REC2 (bind ?REC2 (/ ?TP2 (+ ?TP2 ?FN2)))))
(assert (REC3 (bind ?REC3 (/ ?TP3 (+ ?TP3 ?FN3)))))
(assert (REC4 (bind ?REC4 (/ ?TP4 (+ ?TP4 ?FN4)))))
(assert (PRE1 (bind ?PRE1 (/ ?TP1 (+ ?TP1 ?FP1)))))
(assert (PRE2 (bind ?PRE2 (/ ?TP2 (+ ?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