| Summary | Package variables | Synopsis | Description | General documentation | Methods |
| Summary | Top |
package Clair::Classify |
| Package variables | Top |
| No package variables defined. |
| Included modules | Top |
| Clair::Debug |
| Clair::Features |
| Clair::Learn |
| Data::Dumper |
| File::Path |
| Synopsis | Top |
Use the test data produced by Clair::Feature.pm (in svm_light format), and the model file generated by Clair::Learn.pm to carry out classification on the test data. The underlying algorithm can be either Naive Bayes or Perceptron. (default: perceptron) In case of perceptron, all you have to do is to obtain the dot product between the weight vector (W) and the feature vector (X), and determine whether they are positive or negative. Here, both the "test" and "model" parameter in the constructor is required. use Clair::Classify; my $cla = new Clair::Classify(DEBUG => $DEBUG, test => "test.dat", model => "model.file"); $cla->classify($algo); |
| Description | Top |
The module should provide the ability to choose between different classifier algorithms. |
| Methods | Top |
| _classify_perceptron | Description | Code |
| classify | Description | Code |
| new | Description | Code |
| _classify_perceptron | code | next | Top |
Classifies and then returns the results. Simple algorithm: if wt.f(x) > 0: classify x as positive group (+1) if wt.f(x) < 0: classify x as negative group (-1) |
| classify | code | prev | next | Top |
A wrapper function for the underlying algorithms. |
| new | code | prev | next | Top |
The constructor. Initializes several container hashes for later use. |
| _classify_perceptron | description | prev | next | Top |
sub _classify_perceptron
{
my ($self) = @_;
my $w0 = $self->{model_data}->{intercept};
delete $self->{model_data}->{intercept};
my $w = $self->{model_data};
my $correct_count = 0;
my $total_count = scalar @{ $self->{test_data} };
my @return;
for my $d (@{ $self->{test_data} })
{
my $y = $d->{class};
my $x = $d->{features};
my $com = $d->{comment};
my ($junk, $grp, $path) = split /\s+/, $com;
$com = "$grp:$path";
# dot_product function is in Learn.pm - and we don't want to reimplement the sub.} |
| classify | description | prev | next | Top |
sub classify
{
my ($self, $algo) = @_;
$algo = "_classify_perceptron" unless($algo);
$self->debugmsg("running\$ self->$algo()", 2);
return $self->$algo();} |
| new | description | prev | next | Top |
sub new
{
my ($proto, %args) = @_;
my $class = ref $proto || $proto;
my $self = bless {}, $class;
$DEBUG = $args{DEBUG} || $ENV{MYDEBUG};
$self->{test} = "output.test";
$self->{model} = "model";
# overrides} |
| AUTHOR | Top |
JB Kim jbremnant@gmail.com |