blib/lib/Algorithm/Classifier/IsolationForest/App/Command/fit.pm

filter: Statementstmt 86.4% 102 / 118 Branchbran 66.6% 68 / 102 Conditioncond 58.3% 14 / 24 MC/DCmcdc 20.0% 3 / 15 Subroutinesub 81.8% 9 / 11 Podpod 100% 5 / 5 totaltotal 73.0% 201 / 275 CC 64 SCAR 38.6
CC
64
Cov
75%
execute
55.3
validate
51.4
abstract
2.0
CRAP 47.5
« blib/lib/Algorithm/Classifier/IsolationForest/App/Command/streamd.pm ↑ Summary blib/lib/Algorithm/Classifier/IsolationForest/App/Command/accel.pm »
1 package Algorithm::Classifier::IsolationForest::App::Command::fit;
2  
3 86 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 86 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 86 ▶use Algorithm::Classifier::IsolationForest ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 86 ▶use Algorithm::Classifier::IsolationForest::App -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 86 ▶use File::Slurp qw(read_file write_file);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 86 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 12 ▶sub opt_spec {
Subroutine opt_spec: called CC=1 SCAR=0.0
Pod documented
11 return (
12 12 [ 'i=s', 'CSV to use.', { completion => 'files' } ],
13 [ 'o=s', 'Output JSON file path/name.', { 'default' => 'iforest_model.json', 'completion' => 'files' } ],
14 [ 'p', 'Print the results instead of saving it.' ],
15 [ 'w', 'Overwrite the file if it already exists.' ],
16 [ 's=i', 'Seed int' ],
17 [ 'extended', 'Use EIF instead of IF.' ],
18 [ 'n=i', 'Number of isolation trees in the ensemble' ],
19 [ 'm=i', 'Sub-sample size used to build each tree... max samples' ],
20 [ 'd=i', 'per-tree height limit... if not defined is set to ceil(log2(psi))' ],
21 [
22 'e=f',
23 'How many features take partin each split. 0 behaves like a single-feature (axis) cut; the maximum (n_features - 1) uses every varying feature. undef => maximum. Clamped to [0, n_features - 1] at fit time. May only be used with -e.'
24 ],
25 [
26 'c=f',
27 'Contamination. Expected fraction of anomalies, in (0, 0.5]. When given, fit() learns a score threshold that flags this fraction of the training set, and predict() uses it by default. undef => no learned threshold (predict() falls back to 0.5).'
28 ],
29 [
30 't=s@',
31 'Feature name tag. Pass once per feature (e.g. -t cpu -t mem -t disk); the count must match the number of CSV columns or the command will die.'
32 ],
33 [
34 'voting=s',
35 "Scoring-time aggregation: 'mean' (classic averaged score, the default) or 'majority' (MVIForest: each tree votes against the decision threshold and the label is the majority vote).",
36 ],
37 [
38 'mungers=s',
39 'JSON file of Algorithm::ToNumberMunger specs, keyed by feature tag. Requires -t. '
40 . 'Munged CSV columns may hold raw (non-numeric) values; they are munged before fitting '
41 . 'and the spec is saved with the model. Scalar mungers only (no into/from lists) for CSV input.',
42 { 'completion' => 'files' }
43 ],
44 [
45 'prototype=s',
46 'JSON prototype file to create the model from: the variable schema (feature names, '
47 . 'descriptions, mungers, missing policy) plus schema_version/schema_description come from it, '
48 . 'and its params supply knob defaults that explicit switches override. May not be combined '
49 . 'with -t or --mungers (the schema is the prototype\'s). See PROTOTYPES in the module POD.',
50 { 'completion' => 'files' }
51 ],
52 );
53 } ## end sub opt_spec
54  
55 0 ▶sub abstract { 'Fits the model using the specified data and save it' }
Subroutine abstract: not called CC=1 SCAR=6.9
Pod documented
56  
57 0 ▶sub description {
Subroutine description: not called CC=1 SCAR=6.9
Pod documented
58 0 'Fits the model using the specified data and save it
59  
60 The input format is expected to be CSV. All columns are used as features;
61 each row becomes one sample. Every row must have the same number of columns
62 and every value must be numeric.
63  
64 Switches to new args are like below...
65  
66 -n -> n_trees
67 -s -> seed
68 -m -> sample_size
69 -e -> extension_level
70 -c -> contamination
71 --voting -> voting
72  
73 With --prototype the schema (feature names, descriptions, mungers,
74 missing policy) and schema_version/schema_description come from the
75 prototype file, its params supply knob defaults, and the switches above
76 override those params. See PROTOTYPES in the module POD for the format.
77  
78 ';
79 } ## end sub description
80  
81 12 ▶sub validate {
Subroutine validate: called CC=24 SCAR=39.4
Pod documented
82 12 my ( $self, $opt, $args ) = @_;
83  
84 12 ▶ if ( !defined( $opt->{'i'} ) ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $opt->{'i'}) { } 0 12 12
elsif (not -f $opt->{'i'}) { } 0 12 12
elsif (not -r $opt->{'i'}) { } 0 12 12
85 0 $self->usage_error('-i has not been specified');
86 } elsif ( !-f $opt->{'i'} ) {
87 0 $self->usage_error( '-i, "' . $opt->{'i'} . '", is not a file' );
88 } elsif ( !-r $opt->{'i'} ) {
89 0 $self->usage_error( '-i, "' . $opt->{'i'} . '", is not readable' );
90 }
91  
92 12 ▶ if ( defined( $opt->{'s'} ) && $opt->{'s'} <= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt->{"s"} and $opt->{"s"} <= 0) 0 12 12
Condition66%2/3
defined $opt->{"s"} and $opt->{"s"} <= 0
!ll&&!rl&&r
390
MC/DC0%0/2
defined $opt->{"s"} and $opt->{"s"} <= 0
defined $opt->{"s"} $opt->{"s"} <= 0
Truth table66%2/3
A and B
A= defined $opt->{"s"}B= $opt->{"s"} <= 0
ABresult
0X0
100
111
93 0 $self->usage_error( '-s, "' . $opt->{'s'} . '", is less than or equal to 0, should be a positive int' );
94 }
95  
96 12 ▶ if ( !defined( $opt->{'extended'} ) && defined( $opt->{'e'} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $opt->{"extended"} and defined $opt->{"e"}) 0 12 12
Condition33%1/3
not defined $opt->{"extended"} and defined $opt->{"e"}
!ll&&!rl&&r
0120
MC/DC0%0/2
not defined $opt->{"extended"} and defined $opt->{"e"}
not defined $opt->{"extended"} defined $opt->{"e"}
Truth table33%1/3
not(A) and B
A= not defined $opt->{"extended"}B= defined $opt->{"e"}
ABresult
0X0
100
111
97 0 $self->usage_error('-e may not be used without --extended');
98 }
99  
100 12 ▶ if ( !$opt->{'p'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opt->{"p"}) 8 4 12
101 8 ▶ if ( -e $opt->{'o'} && !$opt->{'w'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $opt->{"o"} and not $opt->{"w"}) 0 8 8
Condition66%2/3
-e $opt->{"o"} and not $opt->{"w"}
!ll&&!rl&&r
620
MC/DC0%0/2
-e $opt->{"o"} and not $opt->{"w"}
-e $opt->{"o"} not $opt->{"w"}
Truth table66%2/3
A and not(B)
A= -e $opt->{"o"}B= not $opt->{"w"}
ABresult
0X0
100
111
102 0 $self->usage_error( '-o,"' . $opt->{'o'} . '", already exists and -w was not specified' );
103 }
104 }
105  
106 12 ▶ if ( defined( $opt->{'e'} ) && $opt->{'e'} < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt->{"e"} and $opt->{"e"} < 0) 0 12 12
Condition33%1/3
defined $opt->{"e"} and $opt->{"e"} < 0
!ll&&!rl&&r
1200
MC/DC0%0/2
defined $opt->{"e"} and $opt->{"e"} < 0
defined $opt->{"e"} $opt->{"e"} < 0
Truth table33%1/3
A and B
A= defined $opt->{"e"}B= $opt->{"e"} < 0
ABresult
0X0
100
111
107 0 $self->usage_error( '-e, "' . $opt->{'e'} . '", is less than 0... should be a float greater or equal to 0' );
108 }
109  
110 12 ▶ if ( defined( $opt->{'voting'} ) && $opt->{'voting'} !~ /\A(?:mean|majority)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt->{"voting"} and not $opt->{"voting"} =~ /\A(?:mean|majority)\z/) 1 11 12
Condition100%3/3
defined $opt->{"voting"} and not $opt->{"voting"} =~ /\A(?:mean|majority)\z/
!ll&&!rl&&r
831
MC/DC100%2/2
defined $opt->{"voting"} and not $opt->{"voting"} =~ /\A(?:mean|majority)\z/
defined $opt->{"voting"} not $opt->{"voting"} =~ /\A(?:mean|majority)\z/
Truth table100%3/3
A and not(B)
A= defined $opt->{"voting"}B= not $opt->{"voting"} =~ /\A(?:mean|majority)\z/
ABresult
0X0
100
111
111 1 $self->usage_error( '--voting, "' . $opt->{'voting'} . '", must be either mean or majority' );
112 }
113  
114 11 ▶ if ( defined( $opt->{'mungers'} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt->{"mungers"}) 2 9 11
115 2 ▶ if ( !-f $opt->{'mungers'} ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not -f $opt->{'mungers'}) { } 0 2 2
elsif (not -r $opt->{'mungers'}) { } 0 2 2
elsif (not defined $opt->{'t'}) { } 1 1 2
116 0 $self->usage_error( '--mungers, "' . $opt->{'mungers'} . '", is not a file or does not exist' );
117 } elsif ( !-r $opt->{'mungers'} ) {
118 0 $self->usage_error( '--mungers, "' . $opt->{'mungers'} . '", is not readable' );
119 } elsif ( !defined( $opt->{'t'} ) ) {
120 1 $self->usage_error('--mungers requires feature tags (-t) to compile against');
121 }
122 }
123  
124 10 ▶ if ( defined( $opt->{'prototype'} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt->{"prototype"}) 4 6 10
125 4 ▶ if ( !-f $opt->{'prototype'} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not -f $opt->{'prototype'}) { } 0 4 4
elsif (not -r $opt->{'prototype'}) { } 0 4 4
126 0 $self->usage_error( '--prototype, "' . $opt->{'prototype'} . '", is not a file or does not exist' );
127 } elsif ( !-r $opt->{'prototype'} ) {
128 0 $self->usage_error( '--prototype, "' . $opt->{'prototype'} . '", is not readable' );
129 }
130 4 ▶ if ( defined( $opt->{'t'} ) || defined( $opt->{'mungers'} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt->{"t"} or defined $opt->{"mungers"}) 1 3 4
Condition66%2/3
defined $opt->{"t"} or defined $opt->{"mungers"}
l!l&&r!l&&!r
103
MC/DC50%1/2
defined $opt->{"t"} or defined $opt->{"mungers"}
defined $opt->{"t"} defined $opt->{"mungers"}
Truth table66%2/3
A or B
A= defined $opt->{"t"}B= defined $opt->{"mungers"}
ABresult
1X1
011
000
131 1 $self->usage_error(
132 '--prototype may not be combined with -t or --mungers; the schema comes only from the prototype');
133 }
134 } ## end if ( defined( $opt->{'prototype'} ) )
135  
136 9 return 1;
137 } ## end sub validate
138  
139 9 ▶sub execute {
Subroutine execute: called CC=41 SCAR=40.1
Pod documented
140 9 my ( $self, $opt, $args ) = @_;
141  
142 9 my $mode = 'axis';
143 9 ▶ if ( $opt->{'extended'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"extended"}) 0 9 9
144 0 $mode = 'extended';
145 }
146  
147 # Munger spec, decoded up front so a bad file dies before the CSV is
148 # read. With mungers active the per-field numeric check is skipped
149 # during the read (munged columns legitimately hold raw strings) and
150 # re-run after munging instead.
151 9 my $mungers;
152 9 ▶ if ( defined( $opt->{'mungers'} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt->{"mungers"}) 1 8 9
153 1 require JSON::PP;
154 1 $mungers = eval { JSON::PP->new->decode( scalar read_file( $opt->{'mungers'} ) ) };
155 1 ▶ die( '--mungers, "' . $opt->{'mungers'} . '", did not parse as JSON: ' . $@ ) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
156 1 ▶ die( '--mungers, "' . $opt->{'mungers'} . '", must be a JSON object of tag => spec' )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $mungers eq "HASH" 0 1 1
157 unless ref $mungers eq 'HASH';
158 }
159  
160 # A prototype supplies the schema and knob defaults, so the model is
161 # created before the CSV is read (a munger-bearing prototype changes
162 # how the CSV is validated). Explicit tuning switches override the
163 # prototype's params; the schema may not be overridden at all.
164 9 my $iforest;
165 9 ▶ if ( defined( $opt->{'prototype'} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt->{"prototype"}) 3 6 9
166 3 my $proto = eval {
167 3 Algorithm::Classifier::IsolationForest->validate_prototype( scalar read_file( $opt->{'prototype'} ) );
168 };
169 3 ▶ die( '--prototype, "' . $opt->{'prototype'} . '", is not a valid prototype: ' . $@ ) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 3 3
170 die( '--prototype, "' . $opt->{'prototype'} . '", is for an online model; use `iforest stream`' . "\n" )
171 3 ▶ unless $proto->{class} eq 'batch';
Branch: 1 branch
BranchTrueFalseTotal
unless $proto->{"class"} eq "batch" 1 2 3
172  
173 2 my %overrides;
174 2 ▶ $overrides{'n_trees'} = $opt->{'n'} if defined $opt->{'n'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opt->{"n"} 0 2 2
175 2 ▶ $overrides{'seed'} = $opt->{'s'} if defined $opt->{'s'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opt->{"s"} 2 0 2
176 2 ▶ $overrides{'sample_size'} = $opt->{'m'} if defined $opt->{'m'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opt->{"m"} 0 2 2
177 2 ▶ $overrides{'max_depth'} = $opt->{'d'} if defined $opt->{'d'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opt->{"d"} 0 2 2
178 2 ▶ $overrides{'mode'} = 'extended' if $opt->{'extended'};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"extended"} 0 2 2
179 2 ▶ $overrides{'extension_level'} = $opt->{'e'} if defined $opt->{'e'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opt->{"e"} 0 2 2
180 2 ▶ $overrides{'contamination'} = $opt->{'c'} if defined $opt->{'c'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opt->{"c"} 0 2 2
181 2 ▶ $overrides{'voting'} = $opt->{'voting'} if defined $opt->{'voting'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opt->{"voting"} 0 2 2
182  
183 2 $iforest = eval { Algorithm::Classifier::IsolationForest->new_from_prototype( $proto, %overrides ) };
184 2 ▶ die( '--prototype, "' . $opt->{'prototype'} . '", failed to create a model: ' . $@ ) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
185 } ## end if ( defined( $opt->{'prototype'} ) )
186  
187 my $has_mungers
188 = $mungers ? 1
189 0 ▶ : ( $iforest && ref $iforest->{mungers} eq 'HASH' && %{ $iforest->{mungers} } ) ? 1
Branch: 2 branches
BranchTrueFalseTotal
$mungers ? : 1 7 8
$iforest && ref $iforest->{'mungers'} eq 'HASH' && %{$iforest->{'mungers'};} ? : 0 7 7
Condition50%3/6
$iforest and ref $iforest->{"mungers"} eq "HASH" and %{$iforest->{"mungers"};}
!ll&&!rl&&r
700
$iforest and ref $iforest->{"mungers"} eq "HASH"
!ll&&!rl&&r
520
MC/DC0%0/3
$iforest and ref $iforest->{"mungers"} eq "HASH" and %{$iforest->{"mungers"};}
$iforest ref $iforest->{"mungers"} eq "HASH" %{$iforest->{"mungers"};}
Truth table50%2/4
A and B and C
A= $iforestB= ref $iforest->{"mungers"} eq "HASH"C= %{$iforest->{"mungers"};}
ABCresult
0XX0
10X0
1100
1111
190 : 0;
191  
192 8 my @data;
193 my $expected_cols;
194  
195 8 my $line_int = 1;
196 8 foreach my $line ( read_file( $opt->{'i'} ) ) {
197 482 chomp($line);
198 482 ▶ next if $line =~ /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*$/ 0 482 482
199  
200 482 my @fields = split( /,/, $line, -1 );
201  
202 482 ▶ if ( !defined($expected_cols) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $expected_cols) { } 8 474 482
elsif (scalar @fields != $expected_cols) { } 0 474 474
203 8 $expected_cols = scalar @fields;
204 8 ▶ die( 'Line ' . $line_int . ' of "' . $opt->{'i'} . '" has no columns' )
Branch: 1 branch
BranchTrueFalseTotal
if $expected_cols < 1 0 8 8
205 if $expected_cols < 1;
206 } elsif ( scalar @fields != $expected_cols ) {
207 die( 'Line '
208 . $line_int . ' of "'
209 0 . $opt->{'i'}
210 . '" has '
211 . scalar(@fields)
212 . ' columns but expected '
213 . $expected_cols );
214 }
215  
216 482 ▶ if ( !$has_mungers ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($has_mungers) 401 81 482
217 401 my $col_int = 1;
218 401 for my $field (@fields) {
219 die( 'Line '
220 . $line_int . ' of "'
221 1203 ▶ . $opt->{'i'}
Branch: 1 branch
BranchTrueFalseTotal
unless &looks_like_number($field) 0 1203 1203
222 . '" value for column '
223 . $col_int . ',"'
224 . $field
225 . '", does not appear to be a number' )
226 unless looks_like_number($field);
227 1203 $col_int++;
228 } ## end for my $field (@fields)
229 } ## end if ( !$has_mungers )
230  
231 482 push @data, \@fields;
232  
233 482 $line_int++;
234 } ## end foreach my $line ( read_file( $opt->{'i'} ) )
235  
236 # The tag count must match the CSV width whether the tags came from -t
237 # or from a prototype's schema.
238 8 ▶ my $check_tags = defined( $opt->{'t'} ) ? $opt->{'t'} : ( $iforest ? $iforest->feature_names : undef );
Branch: 2 branches
BranchTrueFalseTotal
defined $opt->{'t'} ? : 2 6 8
$iforest ? : 2 4 6
239 8 ▶ if ( defined($check_tags) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $check_tags) 4 4 8
240 4 my $n_tags = scalar @$check_tags;
241 4 ▶ my $n_features = defined($expected_cols) ? $expected_cols : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $expected_cols ? : 4 0 4
242 4 ▶ die( 'Number of feature tags (' . $n_tags . ') does not match number of CSV columns (' . $n_features . ')' )
Branch: 1 branch
BranchTrueFalseTotal
unless $n_tags == $n_features 0 4 4
243 unless $n_tags == $n_features;
244 }
245  
246 8 ▶ if ( !$iforest ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($iforest) 6 2 8
247 $iforest = Algorithm::Classifier::IsolationForest->new(
248 'mode' => $mode,
249 'n_trees' => $opt->{'n'},
250 'seed' => $opt->{'s'},
251 'sample_size' => $opt->{'m'},
252 'max_depth' => $opt->{'d'},
253 'extension_level' => $opt->{'e'},
254 'contamination' => $opt->{'c'},
255 'feature_names' => $opt->{'t'},
256 6 'voting' => $opt->{'voting'},
257 'mungers' => $mungers,
258 );
259 } ## end if ( !$iforest )
260  
261 # Munge the raw rows into numbers, then run the numeric validation
262 # that was skipped at read time -- an unmunged column holding a
263 # string is still an error, just reported post-munge.
264 8 ▶ if ($has_mungers) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_mungers) 1 7 8
265 1 my $munged = $iforest->munge_rows( \@data );
266 1 for my $i ( 0 .. $#$munged ) {
267 81 for my $col ( 0 .. $#{ $munged->[$i] } ) {
268 die( 'Line '
269 . ( $i + 1 ) . ' of "'
270 243 ▶ . $opt->{'i'}
Branch: 2 branches
BranchTrueFalseTotal
unless &looks_like_number($munged->[$i][$col]) 0 243 243
defined $munged->[$i][$col] ? : 0 0 0
271 . '" value for column '
272 . ( $col + 1 ) . ',"'
273 . ( defined $munged->[$i][$col] ? $munged->[$i][$col] : 'undef' )
274 . '", is not a number after munging' )
275 unless looks_like_number( $munged->[$i][$col] );
276 } ## end for my $col ( 0 .. $#{ $munged->[$i] } )
277 } ## end for my $i ( 0 .. $#$munged )
278 1 @data = @$munged;
279 } ## end if ($has_mungers)
280  
281 8 $iforest->fit( \@data );
282  
283 8 my $model = $iforest->to_json;
284  
285 8 ▶ if ( $opt->{'p'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"p"}) 1 7 8
286 1 print $model. "\n";
287 1 exit 0;
288 }
289  
290 7 write_file( $opt->{'o'}, { 'atomic' => 1 }, $model );
291 } ## end sub execute
292  
293 =head1 NAME
294  
295 Algorithm::Classifier::IsolationForest::App::Command::fit - Fits the model using the specified data and save it
296  
297 =head1 DESCRIPTION
298  
299 Trains a model from a CSV and saves it as JSON. Every column is a
300 feature and every row one sample, so all rows need the same column count
301 and every value must be numeric.
302  
303 The tuning switches map onto the constructor arguments:
304  
305 - -n :: n_trees
306 - -s :: seed
307 - -m :: sample_size
308 - -e :: extension_level
309 - -c :: contamination
310 - --voting :: voting
311  
312 With C<--prototype> the schema -- feature names, descriptions, mungers
313 and missing policy -- along with C<schema_version> and
314 C<schema_description> come from the prototype file, its params supply the
315 knob defaults, and the switches above override those params. See
316 PROTOTYPES in L<Algorithm::Classifier::IsolationForest> for the format.
317  
318 Run it as C<iforest fit>; C<iforest help fit> lists every option.
319  
320 =head1 METHODS
321  
322 L<App::Cmd> calls these while dispatching the subcommand. Nothing else
323 should.
324  
325 =head2 opt_spec
326  
327 Returns this command's option specifications, as the list of arrayrefs
328 L<Getopt::Long::Descriptive> expects.
329  
330 =head2 abstract
331  
332 Returns the one-line summary C<iforest commands> prints beside the
333 command name.
334  
335 =head2 description
336  
337 Returns the long help text C<iforest help fit> prints under the option
338 list.
339  
340 =head2 validate
341  
342 Checks the parsed options before anything is read or written, so a
343 mistake costs nothing.
344  
345 Checks that C<-i> names a readable CSV, that the numeric knobs parse,
346 that C<-e> is only used with C<--extended>, that C<--voting> is C<mean>
347 or C<majority>, and that a C<--mungers> spec is readable and accompanied
348 by the feature tags (C<-t>) it compiles against.
349  
350 Takes the parsed options hashref and the arrayref of remaining
351 arguments. Calls C<usage_error>, which prints the usage and exits, on
352 the first problem it finds, and returns 1 when everything checks out.
353  
354 =head2 execute
355  
356 Builds the model from the CSV and writes it to C<-o>.
357  
358 Takes the parsed options hashref and the arrayref of remaining
359 arguments, and returns 1.
360  
361 =cut
362  
363 86 return 1;
« blib/lib/Algorithm/Classifier/IsolationForest/App/Command/streamd.pm ↑ Summary blib/lib/Algorithm/Classifier/IsolationForest/App/Command/accel.pm »