⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dataset.pm

📁 在人工智能中模式识别比较新的分类算法,支持向量机.用于特征分类.
💻 PM
字号:
package Algorithm::SVM::DataSet;use 5.006;use strict;use Carp;use Algorithm::SVM;=head1 NAMEAlgorithm::SVM::DataSet - A DataSet object for the Algorithm::SVM SupportVector Machine.=head1 SYNOPSIS  use Algorithm::SVM::DataSet;  # Create a new dataset.  $ds = new Algorithm::SVM::DataSet(Label => 1,                                    Data  => [ 0.12, 0.25, 0.33, 0.98 ]);  # Retrieve/set the label.  $label = $ds->label();  $ds->label(1976);  # Retrieve/set the attribute with an index of 0.  $attr = $ds->attribute(0);  $ds->attribute(0, 0.2621);=head1 DESCRIPTIONAlgorithm::SVM::DataSet is a representation of the datasets passed toAlgorithm::SVM object for training or classification.  Each dataset hasan associated label, which classifies it as being part of a specific group.A dataset object also has one or more key/value pairs corresponding tothe attributes that will be used for classification.=head1 CONSTRUCTORS $ds = new Algorithm::SVM::DataSet(Label => 1,                                   Data  => [ 0.12, 0.25, 0.33, 0.98 ]);The Algorithm::SVM::DataSet constructor accepts two optional named parameters: Label and Data.  Label is used to set the class to which thedataset belongs, and Data is used to set any initial values.  Datashould be an arrayref of numerical values.  Each value in the arrayrefis assumed to have a key corresponding to its index in the array.  ie) In the above example, 0.12 has a key of 0, 0.25 has a key of 1,      0.33 has a key of 2, etc.=head1 METHODS  $label = $ds->label();  $ds->label(1976);The label method is used to set or retrieve the DataSets label value.Parameters and return values should be numeric values.  $attr = $ds->attribute(0);  $ds->attribute(0, 0.2621);The attribute method is used to set dataset attribute values.  If a singlevalue is provided, the method will return the corresponding value.  Iftwo value are provided, the method will set the first parameter to thevalue of the second.=head1 MAINTAINERMatthew Laird <matt@brinkman.mbb.sfu.ca>=head1 SEE ALSOAlgorithm::SVM=cutsub new {  my ($class, %args) = @_; # Do some quick error checking on the values we've been passed.  croak("No label specified for DataSet") if(! exists($args{Label}));  my $self = _new_dataset($args{Label} + 0);  if(exists($args{Data})) {    croak("Data must be an array ref") if(ref($args{Data}) ne "ARRAY");    for(my $i = 0; $i < @{$args{Data}}; $i++) {      $self->attribute($i, (@{$args{Data}})[$i] + 0);    }  }  return $self;}sub label {  my ($self, $label) = @_;  return (defined($label)) ? _setLabel($self, $label + 0) : _getLabel($self);}sub attribute {  my ($self, $key, $val) = @_;  croak("No key specified") if(! defined($key));  return(defined($val)) ? _setAttribute($self, int($key), $val + 0) :  _getAttribute($self, int($key));}1;__END__

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -