📄 unit2.~pas
字号:
TP,FP:double;
begin
Label20.Caption:='测试集是从原表中随机抽取的';
//┌-----------------------------------------------------------------------┐
//|说明: |
//|本程序的预测部分 |
//| 没有用sepal_length,sepal_width,petal_length,petal_width这四个值来预测 |
//| 而是用petal_length,petal_width两个值来分类. |
//| 这样处理便于计算并且 petal_length,petal_width在划分上较另两个显著 |
//└-----------------------------------------------------------------------┘
//对sepal_length(花瓣长)进行划分,把落在区间[min_pl,min_pl+delta_pl) 的值 标记为 'C1'
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict2 set PL='+' ''C1'' where (petal_length>= '+FloattoStr(min_pl)+' ) and petal_length<'+FloattoStr(delta_pl+min_pl)+'');
adoquery2.execSQL;
//对sepal_length(花瓣长)进行划分,把落在区间[min_pl+delta_pl,min_pl+2*delta_pl) 的值 标记为 'C2'
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict2 set PL='+' ''C2'' where (petal_length>= '+FloattoStr(min_pl+delta_pl)+' ) and petal_length<'+FloattoStr(2*delta_pl+min_pl)+'');
adoquery2.execSQL;
//对sepal_length(花瓣长)进行划分,把落在区间[min_pl+2*delta_pl,min_pl+3*delta_pl] 的值 标记为 'C3'
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict2 set PL='+' ''C3'' where (petal_length>= '+FloattoStr(min_pl+2*delta_pl)+' ) and petal_length<='+FloattoStr(3*delta_pl+min_pl)+'');
adoquery2.execSQL;
// ----------------------------
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict2 set PW='+' ''D1'' where (petal_length>= '+FloattoStr(min_pl)+' ) and petal_length<'+FloattoStr(delta_pl+min_pl)+'');
adoquery2.execSQL;
//
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict2 set PW='+' ''D2'' where (petal_length>= '+FloattoStr(min_pl+delta_pl)+' ) and petal_length<'+FloattoStr(2*delta_pl+min_pl)+'');
adoquery2.execSQL;
//
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict2 set PW='+' ''D3'' where (petal_length>= '+FloattoStr(min_pl+2*delta_pl)+' ) and petal_length<='+FloattoStr(3*delta_pl+min_pl)+'');
adoquery2.execSQL;
//┌-------------------------------------------------------------------------┐
//| C1D1 -> Iris-setosa , C2D1 -> None , C3D1 -> None |
//| C1D2 -> None , C2D2 -> Iris-versicolor , C3D2 -> Iris-versicolor |
//| C1D3 -> None , C2D3 -> Iris-Virginica , C3D3 -> Iris-Virginica |
//└-------------------------------------------------------------------------┘
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('select * from iris_predict2');
adoquery2.Open;
//-------------------------预测C1D1---------------------------
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict2 set predict=''Iris-setosa'' where PL='+'''C1'' and PW='+'''D1'' ');
adoquery2.execSQL;
//-------------------------预测C1D2---------------------------
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict2 set predict='+'''Uknown'' where PL='+'''C1'' and PW='+'''D2'' ');
adoquery2.execSQL;
//-------------------------预测C1D3---------------------------
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict2 set predict='+'''Uknown'' where PL='+'''C1'' and PW='+'''D3'' ');
adoquery2.execSQL;
//-------------------------预测C2D1---------------------------
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict2 set predict='+'''Uknown'' where PL='+'''C2'' and PW='+'''D1''');
adoquery2.execSQL;
//-------------------------预测C2D2---------------------------
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict2 set predict='+'''Iris-versicolor'' where PL='+'''C2'' and PW='+'''D2''');
adoquery2.execSQL;
//-------------------------预测C2D3---------------------------
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict2 set predict='+'''Iris-virginica'' where PL='+'''C2'' and PW='+'''D3''');
adoquery2.execSQL;
//-------------------------预测C3D1---------------------------
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict2 set predict='+'''Uknown'' where PL='+'''C3'' and PW='+'''D1''');
adoquery2.execSQL;
//-------------------------预测C3D2---------------------------
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict2 set predict='+'''Iris-versicolor'' where PL='+'''C3'' and PW='+'''D2''');
adoquery2.execSQL;
//-------------------------预测C3D3---------------------------
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict2 set predict='+'''Iris-virginica'' where PL='+'''C3'' and PW='+'''D3''');
adoquery2.execSQL;
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('select * from iris_predict2 ');
adoquery2.Open;
//计算TP,FP
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('select count(*) 匹配个数 from iris_predict2 i where i.class=i.predict');
adoquery2.Open;
nRight:=adoquery2.FieldByName('匹配个数').AsInteger;
//
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('select count(*) 总个数 from iris_predict2');
adoquery2.Open;
nPredict:=adoquery2.FieldByName('总个数').AsInteger;
TP:= nRight/nPredict;
Edit19.Text:=FloattoStr(TP);
FP:=1-TP;
Edit20.Text:=FloattoStr(FP);
// 显示所有
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('select * from iris_predict2');
adoquery2.Open;
end;
procedure TForm2.BitBtn4Click(Sender: TObject);
var
nRight,nPredict:integer;
TP,FP:double;
begin
Label20.Caption:='测试集3是随机选取的';
//┌-----------------------------------------------------------------------┐
//|说明: |
//|本程序的预测部分 |
//| 没有用sepal_length,sepal_width,petal_length,petal_width这四个值来预测 |
//| 而是用petal_length,petal_width两个值来分类. |
//| 这样处理便于计算并且 petal_length,petal_width在划分上较另两个显著 |
//└-----------------------------------------------------------------------┘
//对sepal_length(花瓣长)进行划分,把落在区间[min_pl,min_pl+delta_pl) 的值 标记为 'C1'
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict3 set PL='+' ''C1'' where (petal_length>= '+FloattoStr(min_pl)+' ) and petal_length<'+FloattoStr(delta_pl+min_pl)+'');
adoquery2.execSQL;
//对sepal_length(花瓣长)进行划分,把落在区间[min_pl+delta_pl,min_pl+2*delta_pl) 的值 标记为 'C2'
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict3 set PL='+' ''C2'' where (petal_length>= '+FloattoStr(min_pl+delta_pl)+' ) and petal_length<'+FloattoStr(2*delta_pl+min_pl)+'');
adoquery2.execSQL;
//对sepal_length(花瓣长)进行划分,把落在区间[min_pl+2*delta_pl,min_pl+3*delta_pl] 的值 标记为 'C3'
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict3 set PL='+' ''C3'' where (petal_length>= '+FloattoStr(min_pl+2*delta_pl)+' ) and petal_length<='+FloattoStr(3*delta_pl+min_pl)+'');
adoquery2.execSQL;
// ----------------------------
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict3 set PW='+' ''D1'' where (petal_length>= '+FloattoStr(min_pl)+' ) and petal_length<'+FloattoStr(delta_pl+min_pl)+'');
adoquery2.execSQL;
//
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict3 set PW='+' ''D2'' where (petal_length>= '+FloattoStr(min_pl+delta_pl)+' ) and petal_length<'+FloattoStr(2*delta_pl+min_pl)+'');
adoquery2.execSQL;
//
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict3 set PW='+' ''D3'' where (petal_length>= '+FloattoStr(min_pl+2*delta_pl)+' ) and petal_length<='+FloattoStr(3*delta_pl+min_pl)+'');
adoquery2.execSQL;
//┌-------------------------------------------------------------------------┐
//| C1D1 -> Iris-setosa , C2D1 -> None , C3D1 -> None |
//| C1D2 -> None , C2D2 -> Iris-versicolor , C3D2 -> Iris-versicolor |
//| C1D3 -> None , C2D3 -> Iris-Virginica , C3D3 -> Iris-Virginica |
//└-------------------------------------------------------------------------┘
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('select * from iris_predict3');
adoquery2.Open;
//-------------------------预测C1D1---------------------------
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict3 set predict=''Iris-setosa'' where PL='+'''C1'' and PW='+'''D1'' ');
adoquery2.execSQL;
//-------------------------预测C1D2---------------------------
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict3 set predict='+'''Uknown'' where PL='+'''C1'' and PW='+'''D2'' ');
adoquery2.execSQL;
//-------------------------预测C1D3---------------------------
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict3 set predict='+'''Uknown'' where PL='+'''C1'' and PW='+'''D3'' ');
adoquery2.execSQL;
//-------------------------预测C2D1---------------------------
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict3 set predict='+'''Uknown'' where PL='+'''C2'' and PW='+'''D1''');
adoquery2.execSQL;
//-------------------------预测C2D2---------------------------
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict3 set predict='+'''Iris-versicolor'' where PL='+'''C2'' and PW='+'''D2''');
adoquery2.execSQL;
//-------------------------预测C2D3---------------------------
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict3 set predict='+'''Iris-virginica'' where PL='+'''C2'' and PW='+'''D3''');
adoquery2.execSQL;
//-------------------------预测C3D1---------------------------
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict3 set predict='+'''Uknown'' where PL='+'''C3'' and PW='+'''D1''');
adoquery2.execSQL;
//-------------------------预测C3D2---------------------------
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict3 set predict='+'''Iris-versicolor'' where PL='+'''C3'' and PW='+'''D2''');
adoquery2.execSQL;
//-------------------------预测C3D3---------------------------
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('update iris_predict3 set predict='+'''Iris-virginica'' where PL='+'''C3'' and PW='+'''D3''');
adoquery2.execSQL;
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('select * from iris_predict3 ');
adoquery2.Open;
//计算TP,FP
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('select count(*) 匹配个数 from iris_predict3 i where i.class=i.predict');
adoquery2.Open;
nRight:=adoquery2.FieldByName('匹配个数').AsInteger;
//
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('select count(*) 总个数 from iris_predict3');
adoquery2.Open;
nPredict:=adoquery2.FieldByName('总个数').AsInteger;
TP:= nRight/nPredict;
Edit19.Text:=FloattoStr(TP);
FP:=1-TP;
Edit20.Text:=FloattoStr(FP);
// 显示所有
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('select * from iris_predict3');
adoquery2.Open;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -