blib/lib/Data/Mining/Apriori.pm

filter: Statementstmt 9.4% 28 / 297 Branchbran 0.0% 0 / 136 Conditioncond 2.2% 1 / 45 MC/DCmcdc 0.0% 0 / 28 Subroutinesub 41.1% 7 / 17 Podpod 63.6% 7 / 11 totaltotal 8.0% 43 / 534 CC 102 SCAR 66.9
CC
102
Cov
6%
association_rules
1722.0
excel
756.0
file
182.0
CRAP 800.3
↑ Summary
1 package Data::Mining::Apriori;
2
3 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use List::PowerSet qw(powerset);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Algorithm::Combinatorics qw(variations);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶no if $] >= 5.017011, warnings => 'experimental::smartmatch';
Subroutine BEGIN: called CC=1 SCAR=0.0
9
10 1 our $VERSION = 0.18;
11
12 1 my$self;
13
14 1 $" = ', ';
15 1 $| = 1;
16 1 $SIG{'INT'} = \&stop;
17
18 1 ▶sub new{
Subroutine new: called CC=2 SCAR=7.2
Pod documented
19 1 my $type = shift;
20 1 ▶ my $class = ref($type)||$type;
Condition33%1/3
ref $type || $type
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $type || $type
ref $type $type
Truth table33%1/3
A || B
A= ref $typeB= $type
ABresult
1X1
011
000
21 1 $self = {
22 totalTransactions => 0,
23 metrics => {
24 minSupport => 0.01,
25 minConfidence => 0.10,
26 minLift => undef,
27 minLeverage => undef,
28 minConviction => undef,
29 minCoverage => undef,
30 minCorrelation => undef,
31 minCosine => undef,
32 minLaplace => undef,
33 minJaccard => undef
34 },
35 precision => 3,
36 output => undef,
37 pathOutputFiles => "",
38 messages => undef,
39 keyItemsDescription => undef,
40 keyItemsTransactions => undef,
41 limitRules => undef,
42 limitSubsets => undef,
43 numberSubsets => 0,
44 frequentItemset => [],
45 associationRules => undef,
46 implications => undef,
47 largeItemsetLength => 2,
48 rule => 0
49 };
50 1 bless($self,$class);
51 1 return $self;
52 }
53
54 0 ▶sub validate_data{
Subroutine validate_data: not called CC=5 SCAR=34.0
Pod undocumented
55 (defined $self->{keyItemsDescription})
56 0 ▶ or die('Error: $apriori->{keyItemsDescription} is not defined!');
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"keyItemsDescription"} or die "Error: \$apriori->{keyItemsDescription} is not defined!" 0 0 0
57 (defined $self->{keyItemsTransactions})
58 0 ▶ or die('Error: $apriori->{keyItemsTransactions} is not defined!');
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"keyItemsTransactions"} or die "Error: \$apriori->{keyItemsTransactions} is not defined!" 0 0 0
59 (defined $self->{metrics}{minSupport})
60 0 ▶ or die('Error: $apriori->{metrics}{minSupport} is not defined!');
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"metrics"}{"minSupport"} or die "Error: \$apriori->{metrics}{minSupport} is not defined!" 0 0 0
61 (defined $self->{metrics}{minConfidence})
62 0 ▶ or die('Error: $apriori->{metrics}{minConfidence} is not defined!');
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"metrics"}{"minConfidence"} or die "Error: \$apriori->{metrics}{minConfidence} is not defined!" 0 0 0
63 }
64
65 0 ▶sub insert_key_items_transaction{
Subroutine insert_key_items_transaction: not called CC=4 SCAR=30.0
Pod documented
66 0 ▶ (scalar(@_)==2)
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ == 2 or die "Error: \$apriori->insert_key_items_transaction(\\\@items) missing parameter key items to array reference!" 0 0 0
67 or die('Error: $apriori->insert_key_items_transaction(\@items) missing parameter key items to array reference!');
68 0 ▶ (ref($_[1]) eq "ARRAY")
Branch: 1 branch
BranchTrueFalseTotal
ref $_[1] eq "ARRAY" or die "Error: \$apriori->insert_key_items_transaction(\\\@items) parameter key items is not an array reference!" 0 0 0
69 or die('Error: $apriori->insert_key_items_transaction(\@items) parameter key items is not an array reference!');
70 0 my@items=sort(@{$_[1]});
71 0 my $itemsets=powerset(@items);
72 0 foreach my$itemset(@{$itemsets}){
73 0 $self->{keyItemsTransactions}{"@{$itemset}"}++;
74 }
75 0 $self->{totalTransactions}++;
76 }
77
78 0 ▶sub input_data_file{
Subroutine input_data_file: not called CC=8 SCAR=42.8
Pod documented
79 0 ▶ (scalar(@_)==3)
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ == 3 or die "Error: \$apriori->input_data_file(\"datafile.txt\",\",\") missing parameters path to data file and/or item separator!" 0 0 0
80 or die('Error: $apriori->input_data_file("datafile.txt",",") missing parameters path to data file and/or item separator!');
81 0 my$file=$_[1];
82 0 my$separator=$_[2];
83 0 ▶ (-e $file)
Branch: 1 branch
BranchTrueFalseTotal
-e $file or die qq[Error: the file "$file" does not exists!] 0 0 0
84 or die("Error: the file \"$file\" does not exists!");
85 0 ▶ (-r $file)
Branch: 1 branch
BranchTrueFalseTotal
-r $file or die qq[Error: the file "$file" is not readable!] 0 0 0
86 or die("Error: the file \"$file\" is not readable!");
87 0 ▶ (-T $file)
Branch: 1 branch
BranchTrueFalseTotal
-T $file or die qq[Error: the file "$file" is not a text file!] 0 0 0
88 or die("Error: the file \"$file\" is not a text file!");
89 0 ▶ open(FILE,"<$file")
Branch: 1 branch
BranchTrueFalseTotal
open FILE, "<$file" or die "Error: $!" 0 0 0
90 or die("Error: $!");
91 0 ▶ while(my$line=<FILE>){
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline FILE)) 0 0 0
92 0 $line=~s/\r\n|\n//;
93 0 my@items=split($separator,$line);
94 0 ▶ if(scalar(@items)>=2){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @items >= 2) 0 0 0
95 0 $self->insert_key_items_transaction(\@items);
96 }
97 }
98 0 close(FILE);
99 }
100
101 0 ▶sub quantity_possible_rules{
Subroutine quantity_possible_rules: not called CC=1 SCAR=6.9
Pod documented
102 0 $self->validate_data;
103 0 return ((3**scalar(keys(%{$self->{keyItemsDescription}})))-(2**(scalar(keys(%{$self->{keyItemsDescription}}))+1))+1);
104 }
105
106 0 ▶sub generate_rules{
Subroutine generate_rules: not called CC=2 SCAR=17.9
Pod documented
107 0 $self->validate_data;
108 0 ▶ if($self->{messages}){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"messages"}) 0 0 0
109 0 print "\n${\scalar(keys(%{$self->{keyItemsDescription}}))} items, ${\$self->quantity_possible_rules} possible rules";
110 }
111 0 my @largeItemsetLengthOne = grep{(($self->{keyItemsTransactions}{$_}/$self->{totalTransactions})*100)>=$self->{metrics}{minSupport}}keys(%{$self->{keyItemsDescription}});
112 0 $self->association_rules(\@largeItemsetLengthOne);
113 }
114
115 0 ▶sub association_rules{
Subroutine association_rules: not called CC=41 SCAR=74.5
Pod documented
116 0 my @largeItemset = @{$_[1]};
117 0 my @variations = variations(\@largeItemset,$self->{largeItemsetLength});
118 0 my @frequentItemset;
119 0 ▶ if($self->{messages}){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"messages"}) 0 0 0
120 0 print "\nLarge itemset of length $self->{largeItemsetLength}, ${\scalar(@largeItemset)} items ";
121 0 print "\nProcessing ...";
122 }
123 VARIATIONS:
124 0 foreach my$variation(@variations){
125 0 my@candidateItemset=@{$variation};
126 0 my@antecedent;
127 my@consequent;
128 0 ▶ for(my$antecedentLength=0;$antecedentLength<$#candidateItemset;$antecedentLength++){
Branch: 1 branch
BranchTrueFalseTotal
if ($antecedentLength < $#candidateItemset) 0 0 0
129 0 push@antecedent,$candidateItemset[$antecedentLength];
130 0 @consequent=();
131 0 ▶ for(my$consequentLength=($antecedentLength+1);$consequentLength<=$#candidateItemset;$consequentLength++){
Branch: 1 branch
BranchTrueFalseTotal
if ($consequentLength <= $#candidateItemset) 0 0 0
132 0 push@consequent,$candidateItemset[$consequentLength];
133 }
134 0 @antecedent=sort@antecedent;
135 0 @consequent=sort@consequent;
136 0 ▶ next if("@consequent"~~@{$self->{implications}{"@antecedent"}});
Branch: 1 branch
BranchTrueFalseTotal
if join($", @consequent) ~~ \@{$self->{"implications"}{join $", @antecedent};} 0 0 0
137 0 ▶ last VARIATIONS if(defined $self->{limitSubsets} && $self->{numberSubsets} == $self->{limitSubsets});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"limitSubsets"} and $self->{"numberSubsets"} == $self->{"limitSubsets"} 0 0 0
Condition0%0/3
defined $self->{"limitSubsets"} and $self->{"numberSubsets"} == $self->{"limitSubsets"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"limitSubsets"} and $self->{"numberSubsets"} == $self->{"limitSubsets"}
defined $self->{"limitSubsets"} $self->{"numberSubsets"} == $self->{"limitSubsets"}
Truth table0%0/3
A and B
A= defined $self->{"limitSubsets"}B= $self->{"numberSubsets"} == $self->{"limitSubsets"}
ABresult
0X0
100
111
138 0 $self->{numberSubsets}++;
139 0 push @{$self->{implications}{"@antecedent"}},"@consequent";
140 0 my@implication;
141 0 push@implication,@antecedent,@consequent;
142 0 @implication=sort(@implication);
143 0 ▶ next unless $self->{keyItemsTransactions}{"@antecedent"};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"keyItemsTransactions"}{join $", @antecedent} 0 0 0
144 0 my$supportAntecedent=($self->{keyItemsTransactions}{"@antecedent"}/$self->{totalTransactions});
145 0 ▶ next unless $self->{keyItemsTransactions}{"@implication"};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"keyItemsTransactions"}{join $", @implication} 0 0 0
146 0 my$supportConsequent=($self->{keyItemsTransactions}{"@implication"}/$self->{totalTransactions});
147 0 my $support = $supportConsequent;
148 0 ▶ next if($support < $self->{metrics}{minSupport});
Branch: 1 branch
BranchTrueFalseTotal
if $support < $self->{"metrics"}{"minSupport"} 0 0 0
149 0 my $confidence = ($supportConsequent/$supportAntecedent);
150 0 ▶ next if(defined $self->{metrics}{minConfidence} && $confidence < $self->{metrics}{minConfidence});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"metrics"}{"minConfidence"} and $confidence < $self->{"metrics"}{"minConfidence"} 0 0 0
Condition0%0/3
defined $self->{"metrics"}{"minConfidence"} and $confidence < $self->{"metrics"}{"minConfidence"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"metrics"}{"minConfidence"} and $confidence < $self->{"metrics"}{"minConfidence"}
defined $self->{"metrics"}{"minConfidence"} $confidence < $self->{"metrics"}{"minConfidence"}
Truth table0%0/3
A and B
A= defined $self->{"metrics"}{"minConfidence"}B= $confidence < $self->{"metrics"}{"minConfidence"}
ABresult
0X0
100
111
151 0 my $lift = ($support/($supportAntecedent*$supportConsequent));
152 0 ▶ next if(defined $self->{metrics}{minLift} && $lift < $self->{metrics}{minLift});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"metrics"}{"minLift"} and $lift < $self->{"metrics"}{"minLift"} 0 0 0
Condition0%0/3
defined $self->{"metrics"}{"minLift"} and $lift < $self->{"metrics"}{"minLift"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"metrics"}{"minLift"} and $lift < $self->{"metrics"}{"minLift"}
defined $self->{"metrics"}{"minLift"} $lift < $self->{"metrics"}{"minLift"}
Truth table0%0/3
A and B
A= defined $self->{"metrics"}{"minLift"}B= $lift < $self->{"metrics"}{"minLift"}
ABresult
0X0
100
111
153 0 my $leverage = ($support-($supportAntecedent*$supportConsequent));
154 0 ▶ next if(defined $self->{metrics}{minLeverage} && $leverage < $self->{metrics}{minLeverage});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"metrics"}{"minLeverage"} and $leverage < $self->{"metrics"}{"minLeverage"} 0 0 0
Condition0%0/3
defined $self->{"metrics"}{"minLeverage"} and $leverage < $self->{"metrics"}{"minLeverage"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"metrics"}{"minLeverage"} and $leverage < $self->{"metrics"}{"minLeverage"}
defined $self->{"metrics"}{"minLeverage"} $leverage < $self->{"metrics"}{"minLeverage"}
Truth table0%0/3
A and B
A= defined $self->{"metrics"}{"minLeverage"}B= $leverage < $self->{"metrics"}{"minLeverage"}
ABresult
0X0
100
111
155 0 ▶ my $conviction = ((1-$supportConsequent)==0)?"NaN":((1-$confidence)==0)?"NaN":((1-$supportConsequent)/(1-$confidence));
Branch: 2 branches
BranchTrueFalseTotal
1 - $supportConsequent == 0 ? : 0 0 0
1 - $confidence == 0 ? : 0 0 0
156 0 ▶ next if(defined $self->{metrics}{minConviction} && $conviction < $self->{metrics}{minConviction});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"metrics"}{"minConviction"} and $conviction < $self->{"metrics"}{"minConviction"} 0 0 0
Condition0%0/3
defined $self->{"metrics"}{"minConviction"} and $conviction < $self->{"metrics"}{"minConviction"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"metrics"}{"minConviction"} and $conviction < $self->{"metrics"}{"minConviction"}
defined $self->{"metrics"}{"minConviction"} $conviction < $self->{"metrics"}{"minConviction"}
Truth table0%0/3
A and B
A= defined $self->{"metrics"}{"minConviction"}B= $conviction < $self->{"metrics"}{"minConviction"}
ABresult
0X0
100
111
157 0 my $coverage = $supportAntecedent;
158 0 ▶ next if(defined $self->{metrics}{minCoverage} && $coverage < $self->{metrics}{minCoverage});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"metrics"}{"minCoverage"} and $coverage < $self->{"metrics"}{"minCoverage"} 0 0 0
Condition0%0/3
defined $self->{"metrics"}{"minCoverage"} and $coverage < $self->{"metrics"}{"minCoverage"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"metrics"}{"minCoverage"} and $coverage < $self->{"metrics"}{"minCoverage"}
defined $self->{"metrics"}{"minCoverage"} $coverage < $self->{"metrics"}{"minCoverage"}
Truth table0%0/3
A and B
A= defined $self->{"metrics"}{"minCoverage"}B= $coverage < $self->{"metrics"}{"minCoverage"}
ABresult
0X0
100
111
159 0 my $correlation = (($support-($supportAntecedent*$supportConsequent))/sqrt($supportAntecedent*(1-$supportAntecedent)*$supportConsequent*(1-$supportConsequent)));
160 0 ▶ next if(defined $self->{metrics}{minCorrelation} && $correlation < $self->{metrics}{minCorrelation});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"metrics"}{"minCorrelation"} and $correlation < $self->{"metrics"}{"minCorrelation"} 0 0 0
Condition0%0/3
defined $self->{"metrics"}{"minCorrelation"} and $correlation < $self->{"metrics"}{"minCorrelation"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"metrics"}{"minCorrelation"} and $correlation < $self->{"metrics"}{"minCorrelation"}
defined $self->{"metrics"}{"minCorrelation"} $correlation < $self->{"metrics"}{"minCorrelation"}
Truth table0%0/3
A and B
A= defined $self->{"metrics"}{"minCorrelation"}B= $correlation < $self->{"metrics"}{"minCorrelation"}
ABresult
0X0
100
111
161 0 my $cosine = ($support/sqrt($supportAntecedent*$supportConsequent));
162 0 ▶ next if(defined $self->{metrics}{minCosine} && $cosine < $self->{metrics}{minCosine});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"metrics"}{"minCosine"} and $cosine < $self->{"metrics"}{"minCosine"} 0 0 0
Condition0%0/3
defined $self->{"metrics"}{"minCosine"} and $cosine < $self->{"metrics"}{"minCosine"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"metrics"}{"minCosine"} and $cosine < $self->{"metrics"}{"minCosine"}
defined $self->{"metrics"}{"minCosine"} $cosine < $self->{"metrics"}{"minCosine"}
Truth table0%0/3
A and B
A= defined $self->{"metrics"}{"minCosine"}B= $cosine < $self->{"metrics"}{"minCosine"}
ABresult
0X0
100
111
163 0 my $laplace = (($support+1)/($supportAntecedent+2));
164 0 ▶ next if(defined $self->{metrics}{minLaplace} && $laplace < $self->{metrics}{minLaplace});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"metrics"}{"minLaplace"} and $laplace < $self->{"metrics"}{"minLaplace"} 0 0 0
Condition0%0/3
defined $self->{"metrics"}{"minLaplace"} and $laplace < $self->{"metrics"}{"minLaplace"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"metrics"}{"minLaplace"} and $laplace < $self->{"metrics"}{"minLaplace"}
defined $self->{"metrics"}{"minLaplace"} $laplace < $self->{"metrics"}{"minLaplace"}
Truth table0%0/3
A and B
A= defined $self->{"metrics"}{"minLaplace"}B= $laplace < $self->{"metrics"}{"minLaplace"}
ABresult
0X0
100
111
165 0 my $jaccard = ($support/($supportAntecedent+$supportConsequent-$support));
166 0 ▶ next if(defined $self->{metrics}{minJaccard} && $jaccard < $self->{metrics}{minJaccard});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"metrics"}{"minJaccard"} and $jaccard < $self->{"metrics"}{"minJaccard"} 0 0 0
Condition0%0/3
defined $self->{"metrics"}{"minJaccard"} and $jaccard < $self->{"metrics"}{"minJaccard"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"metrics"}{"minJaccard"} and $jaccard < $self->{"metrics"}{"minJaccard"}
defined $self->{"metrics"}{"minJaccard"} $jaccard < $self->{"metrics"}{"minJaccard"}
Truth table0%0/3
A and B
A= defined $self->{"metrics"}{"minJaccard"}B= $jaccard < $self->{"metrics"}{"minJaccard"}
ABresult
0X0
100
111
167 0 $self->{rule}++;
168 0 $support = sprintf("%.$self->{precision}f", $support);
169 0 $confidence = sprintf("%.$self->{precision}f", $confidence);
170 0 $lift = sprintf("%.$self->{precision}f", $lift);
171 0 $leverage = sprintf("%.$self->{precision}f", $leverage);
172 0 ▶ $conviction = sprintf("%.$self->{precision}f", $conviction)if($conviction ne "NaN");
Branch: 1 branch
BranchTrueFalseTotal
if $conviction ne "NaN" 0 0 0
173 0 $coverage = sprintf("%.$self->{precision}f", $coverage);
174 0 $correlation = sprintf("%.$self->{precision}f", $correlation);
175 0 $cosine = sprintf("%.$self->{precision}f", $cosine);
176 0 $laplace = sprintf("%.$self->{precision}f", $laplace);
177 0 $jaccard = sprintf("%.$self->{precision}f", $jaccard);
178 $self->{associationRules}{$self->{rule}} = {
179 0 implication => "{ @antecedent } => { @consequent }",
180 support => $support,
181 confidence => $confidence,
182 lift => $lift,
183 leverage => $leverage,
184 conviction => $conviction,
185 coverage => $coverage,
186 correlation => $correlation,
187 cosine => $cosine,
188 laplace => $laplace,
189 jaccard => $jaccard,
190 items => [@antecedent, @consequent]
191 };
192 0 my@items=grep{!($_~~@frequentItemset)}@implication;
193 0 push@frequentItemset,@items;
194 0 ▶ last VARIATIONS if(defined $self->{limitRules} && $self->{rule} == $self->{limitRules});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"limitRules"} and $self->{"rule"} == $self->{"limitRules"} 0 0 0
Condition0%0/3
defined $self->{"limitRules"} and $self->{"rule"} == $self->{"limitRules"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"limitRules"} and $self->{"rule"} == $self->{"limitRules"}
defined $self->{"limitRules"} $self->{"rule"} == $self->{"limitRules"}
Truth table0%0/3
A and B
A= defined $self->{"limitRules"}B= $self->{"rule"} == $self->{"limitRules"}
ABresult
0X0
100
111
195 }
196 }
197 0 ▶ if($self->{messages}){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"messages"}) 0 0 0
198 0 print "\nFrequent itemset: { @frequentItemset }, ${\scalar(@frequentItemset)} items ";
199 }
200 0 ▶ if(defined $self->{associationRules}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"associationRules"}) 0 0 0
201 0 @{$self->{frequentItemset}}=@frequentItemset;
202 0 $self->output;
203 }
204 return if((defined $self->{limitRules} && $self->{rule} == $self->{limitRules})
205 0 ▶ ||(defined $self->{limitSubsets} && $self->{numberSubsets} == $self->{limitSubsets}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"limitRules"} and $self->{"rule"} == $self->{"limitRules"} or defined $self->{"limitSubsets"} and $self->{"numberSubsets"} == $self->{"limitSubsets"} 0 0 0
Condition0%0/9
defined $self->{"limitRules"} and $self->{"rule"} == $self->{"limitRules"} or defined $self->{"limitSubsets"} and $self->{"numberSubsets"} == $self->{"limitSubsets"}
l!l&&r!l&&!r
000
defined $self->{"limitRules"} and $self->{"rule"} == $self->{"limitRules"}
!ll&&!rl&&r
000
defined $self->{"limitSubsets"} and $self->{"numberSubsets"} == $self->{"limitSubsets"}
!ll&&!rl&&r
000
MC/DC0%0/4
defined $self->{"limitRules"} and $self->{"rule"} == $self->{"limitRules"} or defined $self->{"limitSubsets"} and $self->{"numberSubsets"} == $self->{"limitSubsets"}
defined $self->{"limitRules"} $self->{"rule"} == $self->{"limitRules"} defined $self->{"limitSubsets"} $self->{"numberSubsets"} == $self->{"limitSubsets"}
Truth table0%0/7
A and B or C and D
A= defined $self->{"limitRules"}B= $self->{"rule"} == $self->{"limitRules"}C= defined $self->{"limitSubsets"}D= $self->{"numberSubsets"} == $self->{"limitSubsets"}
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
206 0 ▶ if(scalar(@frequentItemset)>=($self->{largeItemsetLength}+1)){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @frequentItemset >= $self->{"largeItemsetLength"} + 1) 0 0 0
207 0 $self->{largeItemsetLength}++;
208 0 $self->{associationRules} = undef;
209 0 $self->association_rules(\@frequentItemset);
210 }
211 }
212
213 0 ▶sub stop{
Subroutine stop: not called CC=5 SCAR=34.0
Pod undocumented
214 0 ▶ if($self->{messages}){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'messages'}) { } 0 0 0
215 0 print "\nStopping ...";
216 0 ▶ $self->output if $self->{associationRules};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"associationRules"} 0 0 0
217 0 print "\nExit? (Y/N): ";
218 0 my $answer = <STDIN>;
219 0 chomp($answer);
220 0 ▶ if($answer =~ /^y$/i){
Branch: 1 branch
BranchTrueFalseTotal
if ($answer =~ /^y$/i) { } 0 0 0
221 0 exit;
222 }
223 else{
224 0 print "Processing ...";
225 }
226 }
227 else{
228 0 ▶ $self->output if $self->{associationRules};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"associationRules"} 0 0 0
229 0 exit;
230 }
231 }
232
233 0 ▶sub output{
Subroutine output: not called CC=4 SCAR=30.0
Pod documented
234 0 ▶ if($self->{output}){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"output"}) 0 0 0
235 0 ▶ if($self->{output}==1){
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'output'} == 1) { } 0 0 0
elsif ($self->{'output'} == 2) { } 0 0 0
236 0 $self->file;
237 }
238 elsif($self->{output}==2){
239 0 $self->excel;
240 }
241 }
242 }
243
244 0 ▶sub file{
Subroutine file: not called CC=13 SCAR=52.0
Pod undocumented
245 0 ▶ if($self->{messages}){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"messages"}) 0 0 0
246 0 print "\nExporting to file $self->{pathOutputFiles}output_large_itemset_length_$self->{largeItemsetLength}.txt ...";
247 }
248 0 ▶ open(FILE,">$self->{pathOutputFiles}output_large_itemset_length_$self->{largeItemsetLength}.txt")
Branch: 1 branch
BranchTrueFalseTotal
open FILE, qq[>$self->{"pathOutputFiles"}output_large_itemset_length_$self->{"largeItemsetLength"}.txt] or die qq[\nError: $self->{"pathOutputFiles"}output_large_itemset_length_$self->{"largeItemsetLength"}.txt $!] 0 0 0
249 or die("\nError: $self->{pathOutputFiles}output_large_itemset_length_$self->{largeItemsetLength}.txt $!");
250 0 print FILE "Rules\tSupport\tConfidence";
251 0 my@headings=('Lift', 'Leverage', 'Conviction', 'Coverage', 'Correlation', 'Cosine', 'Laplace', 'Jaccard');
252 0 my@metrics;
253 0 foreach my$metric(@headings){
254 0 ▶ push@metrics,$metric if defined $self->{metrics}{"min$metric"};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"metrics"}{"min$metric"} 0 0 0
255 }
256 0 foreach my$metric(@metrics){
257 0 print FILE "\t$metric";
258 }
259 0 print FILE "\n";
260 0 foreach my$rule(sort{$a<=>$b}keys(%{$self->{associationRules}})){
261 0 $self->{associationRules}{$rule}{support}=~s/\./,/;
262 0 $self->{associationRules}{$rule}{confidence}=~s/\./,/;
263 0 foreach my$metric(@metrics){
264 0 $self->{associationRules}{$rule}{lc$metric}=~s/\./,/;
265 }
266 0 print FILE "R$rule\t$self->{associationRules}{$rule}{support}\t$self->{associationRules}{$rule}{confidence}";
267 0 foreach my$metric(@metrics){
268 0 print FILE "\t$self->{associationRules}{$rule}{${\lc$metric}}";
269 }
270 0 print FILE "\n";
271 }
272 0 print FILE "\n";
273 0 foreach my$rule(sort{$a<=>$b}keys(%{$self->{associationRules}})){
274 0 print FILE "Rule R$rule: $self->{associationRules}{$rule}{implication}\n";
275 0 print FILE "Support: $self->{associationRules}{$rule}{support}\n";
276 0 print FILE "Confidence: $self->{associationRules}{$rule}{confidence}\n";
277 0 foreach my$metric(@metrics){
278 0 print FILE "$metric: $self->{associationRules}{$rule}{${\lc$metric}}\n";
279 }
280 0 print FILE "Items:\n";
281 0 foreach my$item(@{$self->{associationRules}{$rule}{items}}){
282 0 print FILE "$item $self->{keyItemsDescription}{$item}\n";
283 }
284 0 print FILE "\n";
285 }
286 0 print FILE "Frequent itemset: { @{$self->{frequentItemset}} }\n";
287 0 print FILE "Items:\n";
288 0 foreach my$item(@{$self->{frequentItemset}}){
289 0 print FILE "$item $self->{keyItemsDescription}{$item}\n";
290 }
291 0 close(FILE);
292 }
293
294 0 ▶sub excel{
Subroutine excel: not called CC=27 SCAR=66.3
Pod undocumented
295 0 require Excel::Writer::XLSX;
296 0 ▶ if($self->{messages}){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"messages"}) 0 0 0
297 0 print "\nExporting to excel $self->{pathOutputFiles}output_large_itemset_length_$self->{largeItemsetLength}.xlsx ...";
298 }
299 0 ▶ my $workbook = Excel::Writer::XLSX->new("$self->{pathOutputFiles}output_large_itemset_length_$self->{largeItemsetLength}.xlsx")
Branch: 1 branch
BranchTrueFalseTotal
my $workbook = "Excel::Writer::XLSX"->new(qq[$self->{"pathOutputFiles"}output_large_itemset_length_$self->{"largeItemsetLength"}.xlsx]) or die qq[\nError: $self->{"pathOutputFiles"}output_large_itemset_length_$self->{"largeItemsetLength"}.xlsx $!] 0 0 0
300 or die("\nError: $self->{pathOutputFiles}output_large_itemset_length_$self->{largeItemsetLength}.xlsx $!");
301 0 my $worksheet = $workbook->add_worksheet();
302 0 my $bold = $workbook->add_format(bold => 1);
303 0 my $headings = ['Rules', 'Support', 'Confidence'];
304 0 my@metrics=('Lift', 'Leverage', 'Conviction', 'Coverage', 'Correlation', 'Cosine', 'Laplace', 'Jaccard');
305 0 foreach my$metric(@metrics){
306 0 ▶ push@{$headings},$metric if defined $self->{metrics}{"min$metric"};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"metrics"}{"min$metric"} 0 0 0
307 }
308 0 @metrics=@{$headings}[3..$#{$headings}];
309 0 my(@rules,@support,@confidence,@lift,@leverage,@conviction,@coverage,@correlation,@cosine,@laplace,@jaccard);
310 0 foreach my$rule(sort{$a<=>$b}keys(%{$self->{associationRules}})){
311 0 push @rules,"R$rule";
312 0 push @support,$self->{associationRules}{$rule}{support};
313 0 push @confidence,$self->{associationRules}{$rule}{confidence};
314 0 ▶ push @lift,$self->{associationRules}{$rule}{lift} if defined $self->{metrics}{minLift};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"metrics"}{"minLift"} 0 0 0
315 0 ▶ push @leverage,$self->{associationRules}{$rule}{leverage} if defined $self->{metrics}{minLeverage};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"metrics"}{"minLeverage"} 0 0 0
316 0 ▶ push @conviction,$self->{associationRules}{$rule}{conviction} if defined $self->{metrics}{minConviction};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"metrics"}{"minConviction"} 0 0 0
317 0 ▶ push @coverage,$self->{associationRules}{$rule}{coverage} if defined $self->{metrics}{minCoverage};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"metrics"}{"minCoverage"} 0 0 0
318 0 ▶ push @correlation,$self->{associationRules}{$rule}{correlation} if defined $self->{metrics}{minCorrelation};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"metrics"}{"minCorrelation"} 0 0 0
319 0 ▶ push @cosine,$self->{associationRules}{$rule}{cosine} if defined $self->{metrics}{minCosine};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"metrics"}{"minCosine"} 0 0 0
320 0 ▶ push @laplace,$self->{associationRules}{$rule}{laplace} if defined $self->{metrics}{minLaplace};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"metrics"}{"minLaplace"} 0 0 0
321 0 ▶ push @jaccard,$self->{associationRules}{$rule}{jaccard} if defined $self->{metrics}{minJaccard};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"metrics"}{"minJaccard"} 0 0 0
322 }
323 0 my$line=(scalar(@rules)+1);
324 0 my@data=(\@rules,\@support,\@confidence);
325 0 ▶ push @data,\@lift if defined $self->{metrics}{minLift};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"metrics"}{"minLift"} 0 0 0
326 0 ▶ push @data,\@leverage if defined $self->{metrics}{minLeverage};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"metrics"}{"minLeverage"} 0 0 0
327 0 ▶ push @data,\@conviction if defined $self->{metrics}{minConviction};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"metrics"}{"minConviction"} 0 0 0
328 0 ▶ push @data,\@coverage if defined $self->{metrics}{minCoverage};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"metrics"}{"minCoverage"} 0 0 0
329 0 ▶ push @data,\@correlation if defined $self->{metrics}{minCorrelation};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"metrics"}{"minCorrelation"} 0 0 0
330 0 ▶ push @data,\@cosine if defined $self->{metrics}{minCosine};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"metrics"}{"minCosine"} 0 0 0
331 0 ▶ push @data,\@laplace if defined $self->{metrics}{minLaplace};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"metrics"}{"minLaplace"} 0 0 0
332 0 ▶ push @data,\@jaccard if defined $self->{metrics}{minJaccard};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"metrics"}{"minJaccard"} 0 0 0
333 0 $worksheet->write('A1', $headings, $bold);
334 0 $worksheet->write('A2', \@data);
335 0 my$chart=$workbook->add_chart(type =>'column', embedded=>1);
336 0 my@columns=('B'..'M');
337 0 my$i=0;
338 0 $chart->add_series(
339 name => 'Support',
340 categories => '=Sheet1!$A$2:$A$'.$line,
341 values => '=Sheet1!$'.$columns[$i].'$2:$'.$columns[$i].'$'.$line,
342 );
343 0 $i++;
344 0 $chart->add_series(
345 name => 'Confidence',
346 categories => '=Sheet1!$A$2:$A$'.$line,
347 values => '=Sheet1!$'.$columns[$i].'$2:$'.$columns[$i].'$'.$line,
348 );
349 0 foreach my$metric(@metrics){
350 0 $i++;
351 0 $chart->add_series(
352 name => $metric,
353 categories => '=Sheet1!$A$2:$A$'.$line,
354 values => '=Sheet1!$'.$columns[$i].'$2:$'.$columns[$i].'$'.$line,
355 );
356 }
357 0 $worksheet->insert_chart($columns[($i+2)].'2', $chart);
358 0 $line+=2;
359 0 my $urlFormat = $workbook->add_format(
360 color => 'blue',
361 );
362 0 my$url=2;
363 0 foreach my$rule(sort{$a<=>$b}keys(%{$self->{associationRules}})){
364 0 $worksheet->write_url("A$line","internal:Sheet1!A$url",$urlFormat,"<");
365 0 $line++;
366 0 $worksheet->write_url("A$url","internal:Sheet1!A$line",$urlFormat,"R$rule");
367 0 $worksheet->write("A$line","Rule R$rule: $self->{associationRules}{$rule}{implication}");
368 0 $line++;
369 0 $worksheet->write("A$line","Support: $self->{associationRules}{$rule}{support}");
370 0 $line++;
371 0 $worksheet->write("A$line","Confidence: $self->{associationRules}{$rule}{confidence}");
372 0 $line++;
373 0 foreach my$metric(@metrics){
374 0 $worksheet->write("A$line","$metric: $self->{associationRules}{$rule}{${\lc$metric}}");
375 0 $line++;
376 }
377 0 $worksheet->write("A$line","Items:");
378 0 $line++;
379 0 foreach my$item(@{$self->{associationRules}{$rule}{items}}){
380 0 $worksheet->write("A$line","$item $self->{keyItemsDescription}{$item}");
381 0 $line++;
382 }
383 0 $line++;
384 0 $url++;
385 }
386 0 $worksheet->write("A$line","Frequent itemset: { @{$self->{frequentItemset}} }");
387 0 $line++;
388 0 $worksheet->write("A$line","Items:");
389 0 $line++;
390 0 foreach my$item(@{$self->{frequentItemset}}){
391 0 $worksheet->write("A$line","$item $self->{keyItemsDescription}{$item}");
392 0 $line++;
393 }
394 0 $workbook->close;
395 }
396
397 1 return 1;
398 __END__
↑ Summary