Algorithm-DecisionTree
view release on metacpan or search on metacpan
lib/Algorithm/RegressionTree.pm view on Meta::CPAN
foreach my $i (0 .. scalar(keys %{$self->{_output_for_plots}})) {
if ($i == 0) {
$arg_string .= "\"$temp_file\" index $i using 1:2 notitle with points lt -1 pt 1, ";
} elsif ($i == 1) {
$arg_string .= "\"$temp_file\" index $i using 1:2 title \"linear regression\" with lines lt 1 lw 4, ";
} elsif ($i == 2) {
$arg_string .= "\"$temp_file\" index $i using 1:2 title \"tree regression\" with lines lt 3 lw 4, ";
} else {
$arg_string .= "\"$temp_file\" index $i using 1:2 notitle with lines lt 3 lw 4, ";
}
}
$arg_string = $arg_string =~ /^(.*),[ ]+$/;
$arg_string = $1;
$hardcopy_plot->gnuplot_cmd( "plot $arg_string" );
$gplot->gnuplot_cmd( "plot $arg_string" );
$gplot->gnuplot_pause(-1);
} elsif ($ncols == 3) {
my @dependent_val_vals = $self->{_YVector}->col(0)->as_list;
foreach my $i (0 .. $self->{_XMatrix}->rows - 1) {
my @onerow = $self->{_XMatrix}->row($i)->as_list;
pop @onerow;
print OUTPUT "@onerow $dependent_val_vals[$i]\n";
}
print OUTPUT "\n\n";
foreach my $plot (sort {$a <=> $b} keys %{$self->{_output_for_surface_plots}}) {
my @plot_data = @{$self->{_output_for_surface_plots}->{$plot}};
my @predictors = @{$plot_data[0]};
my @predictions = @{$plot_data[1]};
map {print OUTPUT "$predictors[$_] $predictions[$_]\n"} 0 .. @predictions - 1;
print OUTPUT "\n\n"
}
close OUTPUT;
my $gplot = Graphics::GnuplotIF->new( persist => 1 );
my $hardcopy_plot = Graphics::GnuplotIF->new();
$hardcopy_plot->gnuplot_cmd('set terminal png', "set output \"regression_plots.png\"");
$gplot->gnuplot_cmd( "set noclip" );
$gplot->gnuplot_cmd( "set pointsize 2" );
my $arg_string = "";
foreach my $i (0 .. scalar(keys %{$self->{_output_for_surface_plots}})) {
if ($i == 0) {
$arg_string .= "\"$temp_file\" index $i using 1:2:3 notitle with points lt -1 pt 1, ";
} elsif ($i == 1) {
$arg_string .= "\"$temp_file\" index $i using 1:2:3 title \"linear regression\" with points lt 1 pt 2, ";
} elsif ($i == 2) {
$arg_string .= "\"$temp_file\" index $i using 1:2:3 title \"tree regression\" with points lt 3 pt 3, ";
} else {
$arg_string .= "\"$temp_file\" index $i using 1:2:3 notitle with points lt 3 pt 3, ";
}
}
$arg_string = $arg_string =~ /^(.*),[ ]+$/;
$arg_string = $1;
$hardcopy_plot->gnuplot_cmd( "splot $arg_string" );
$gplot->gnuplot_cmd( "splot $arg_string" );
$gplot->gnuplot_pause(-1);
} else {
die "no visual displays for regression from more then 2 predictor vars";
}
}
sub DESTROY {
unlink glob "__temp_*";
}
############################################## Utility Routines ##########################################
# checks whether an element is in an array:
sub contained_in {
my $ele = shift;
my @array = @_;
my $count = 0;
map {$count++ if $ele eq $_} @array;
return $count;
}
sub minmax {
my $arr = shift;
my ($min, $max);
foreach my $i (0..@{$arr}-1) {
if ( (!defined $min) || ($arr->[$i] < $min) ) {
$min = $arr->[$i];
}
if ( (!defined $max) || ($arr->[$i] > $max) ) {
$max = $arr->[$i];
}
}
return ($min, $max);
}
sub sample_index {
my $arg = shift;
$arg =~ /_(.+)$/;
return $1;
}
sub check_for_illegal_params {
my @params = @_;
my @legal_params = qw / training_datafile
max_depth_desired
dependent_variable_column
predictor_columns
mse_threshold
need_data_normalization
jacobian_choice
csv_cleanup_needed
debug1_r
debug2_r
debug3_r
/;
my $found_match_flag;
foreach my $param (@params) {
foreach my $legal (@legal_params) {
$found_match_flag = 0;
if ($param eq $legal) {
$found_match_flag = 1;
last;
}
}
last if $found_match_flag == 0;
}
return $found_match_flag;
}
( run in 0.815 second using v1.01-cache-2.11-cpan-5a3173703d6 )