line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AI::XGBoost::DMatrix; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
77107
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
5
|
1
|
|
|
1
|
|
4
|
use utf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.008'; # VERSION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: XGBoost class for data |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
429
|
use Moose; |
|
1
|
|
|
|
|
489309
|
|
|
1
|
|
|
|
|
9
|
|
12
|
1
|
|
|
1
|
|
10326
|
use AI::XGBoost::CAPI qw(:all); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use Carp; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has handle => ( is => 'ro', ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub From { |
18
|
|
|
|
|
|
|
my ( $package, %args ) = @_; |
19
|
|
|
|
|
|
|
return __PACKAGE__->FromFile( filename => $args{file}, silent => $args{silent} ) if ( defined $args{file} ); |
20
|
|
|
|
|
|
|
return __PACKAGE__->FromMat( map { $_ => $args{$_} if defined $_ } qw(matrix missing label) ) |
21
|
|
|
|
|
|
|
if ( defined $args{matrix} ); |
22
|
|
|
|
|
|
|
Carp::cluck( "I don't know how to build a " . __PACKAGE__ . " with this data: " . join( ", ", %args ) ); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub FromFile { |
26
|
|
|
|
|
|
|
my ( $package, %args ) = @_; |
27
|
|
|
|
|
|
|
my $handle = XGDMatrixCreateFromFile( @args{qw(filename silent)} ); |
28
|
|
|
|
|
|
|
return __PACKAGE__->new( handle => $handle ); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub FromMat { |
32
|
|
|
|
|
|
|
my ( $package, %args ) = @_; |
33
|
|
|
|
|
|
|
my $handle = XGDMatrixCreateFromMat( @args{qw(matrix missing)} ); |
34
|
|
|
|
|
|
|
my $matrix = __PACKAGE__->new( handle => $handle ); |
35
|
|
|
|
|
|
|
if ( defined $args{label} ) { |
36
|
|
|
|
|
|
|
$matrix->set_label( $args{label} ); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
return $matrix; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub set_float_info { |
42
|
|
|
|
|
|
|
my $self = shift(); |
43
|
|
|
|
|
|
|
my ( $field, $info ) = @_; |
44
|
|
|
|
|
|
|
XGDMatrixSetFloatInfo( $self->handle, $field, $info ); |
45
|
|
|
|
|
|
|
return $self; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub get_float_info { |
49
|
|
|
|
|
|
|
my $self = shift(); |
50
|
|
|
|
|
|
|
my $field = shift(); |
51
|
|
|
|
|
|
|
XGDMatrixGetFloatInfo( $self->handle, $field ); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub set_label { |
55
|
|
|
|
|
|
|
my $self = shift(); |
56
|
|
|
|
|
|
|
my $label = shift(); |
57
|
|
|
|
|
|
|
$self->set_float_info( 'label', $label ); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub get_label { |
61
|
|
|
|
|
|
|
my $self = shift(); |
62
|
|
|
|
|
|
|
$self->get_float_info('label'); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub set_weight { |
66
|
|
|
|
|
|
|
my $self = shift(); |
67
|
|
|
|
|
|
|
my $weight = shift(); |
68
|
|
|
|
|
|
|
$self->set_float_info( 'weight', $weight ); |
69
|
|
|
|
|
|
|
return $self; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub get_weight { |
73
|
|
|
|
|
|
|
my $self = shift(); |
74
|
|
|
|
|
|
|
$self->get_float_info('weight'); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub num_row { |
78
|
|
|
|
|
|
|
my $self = shift(); |
79
|
|
|
|
|
|
|
XGDMatrixNumRow( $self->handle ); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub num_col { |
83
|
|
|
|
|
|
|
my $self = shift(); |
84
|
|
|
|
|
|
|
XGDMatrixNumCol( $self->handle ); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub dims { |
88
|
|
|
|
|
|
|
my $self = shift(); |
89
|
|
|
|
|
|
|
return ( $self->num_row(), $self->num_col() ); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub DEMOLISH { |
93
|
|
|
|
|
|
|
my $self = shift(); |
94
|
|
|
|
|
|
|
XGDMatrixFree( $self->handle ); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
__END__ |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=pod |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=encoding utf-8 |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 NAME |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
AI::XGBoost::DMatrix - XGBoost class for data |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 VERSION |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
version 0.008 |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 SYNOPSIS |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
use aliased 'AI::XGBoost::DMatrix'; |
116
|
|
|
|
|
|
|
my $train_data = DMatrix->FromFile(filename => 'agaricus.txt.train'); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 DESCRIPTION |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
XGBoost DMatrix perl model |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Work In Progress, the API may change. Comments and suggestions are welcome! |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 METHODS |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 From |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Construct a DMatrix from diferent sources. Based on parameters |
129
|
|
|
|
|
|
|
dispatch to the correct From* method |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Refer to From* to see what can be done. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head2 FromFile |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Construct a DMatrix from a file |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head3 Parameters |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=over 4 |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item filename |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
File to read |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item silent |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Supress messages |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=back |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head2 FromMat |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Construct a DMatrix from a bidimensional array |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head3 Parameters |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=over 4 |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=item matrix |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Bidimensional array |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=item label |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Array with the labels of the rows of matrix. Optional |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=item missing |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Value to identify missing values. Optional, default `NaN` |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=back |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 set_float_info |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Set float type property |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head3 Parameters |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=over 4 |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=item field |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Field name of the information |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=item info |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
array with the information |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=back |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head2 get_float_info |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Get float type property |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head3 Parameters |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=over 4 |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item field |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Field name of the information |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=back |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head2 set_label |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Set label of DMatrix. This label is the "classes" in classification problems |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=head3 Parameters |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=over 4 |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=item data |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
Array with the labels |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=back |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head2 get_label |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Get label of DMatrix. This label is the "classes" in classification problems |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head2 set_weight |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Set weight of each instance |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head3 Parameters |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=over 4 |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=item weight |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
Array with the weights |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=back |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=head2 get_weight |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
Get the weight of each instance |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head2 num_row |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
Number of rows |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head2 num_col |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
Number of columns |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=head2 dims |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
Dimensions of the matrix. That is: rows, columns |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=head2 DEMOLISH |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
Free the |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=head1 AUTHOR |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
Pablo RodrÃguez González <pablo.rodriguez.gonzalez@gmail.com> |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
This software is Copyright (c) 2017 by Pablo RodrÃguez González. |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
This is free software, licensed under: |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
The Apache License, Version 2.0, January 2004 |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=cut |