SVM-Based Supervised Classification Example
This example uses SVM-based classification. The steps are essentially the same as the Decision Tree example, except for the following differences:
-
Set the
SVM_CLASSIFIERpreference withCTX_DDL.CREATE_PREFERENCErather than setting it inCTX_CLS.TRAIN.(You can do it either way.) -
Include category descriptions in the category table. (You can do it either way.)
-
Because rules are opaque to the user, use fewer arguments in
CTX_CLS.TRAIN.
To create a SVM-based supervised classification:
-
Create and populate the training document table.
create table doc (id number primary key, text varchar2(2000)); insert into doc values(1,'1 2 3 4 5 6'); insert into doc values(2,'3 4 7 8 9 0'); insert into doc values(3,'a b c d e f'); insert into doc values(4,'g h i j k l m n o p q r'); insert into doc values(5,'g h i j k s t u v w x y z'); -
Create and populate the category table.
create table testcategory ( doc_id number, cat_id number, cat_name varchar2(100) ); insert into testcategory values (1,1,'number'); insert into testcategory values (2,1,'number'); insert into testcategory values (3,2,'letter'); insert into testcategory values (4,2,'letter'); insert into testcategory values (5,2,'letter'); -
Create the
CONTEXTindex on the document table without populating it.create index docx on doc(text) indextype is ctxsys.context parameters('nopopulate'); -
Set the
SVM_CLASSIFIER.You can also set it in
CTX.CLS_TRAIN.exec ctx_ddl.create_preference('my_classifier','SVM_CLASSIFIER'); exec ctx_ddl.set_attribute('my_classifier','MAX_FEATURES','100'); -
Create the result (rule) table.
create table restab ( cat_id number, type number(3) not null, rule blob ); -
Perform the training.
exec ctx_cls.train('docx', 'id','testcategory','doc_id','cat_id', 'restab','my_classifier'); -
Create a
CTXRULEindex on the rules table.exec ctx_ddl.create_preference('my_filter','NULL_FILTER'); create index restabx on restab (rule) indextype is ctxsys.ctxrule parameters ('filter my_filter classifier my_classifier');
Now you can classify two unknown documents, as follows:
select cat_id, match_score(1) from restab
where matches(rule, '4 5 6',1)>50;
select cat_id, match_score(1) from restab
where matches(rule, 'f h j',1)>50;
drop table doc;
drop table testcategory;
drop table restab;
exec ctx_ddl.drop_preference('my_classifier');
exec ctx_ddl.drop_preference('my_filter');