public function test_scenario5()
 {
     $data = array(array("filename" => 'data/grades.csv', "number_of_models" => 2, "tlp" => 1, "data_input" => array(), "prediction" => 67.5));
     foreach ($data as $item) {
         print "\nSuccessfully creating a local prediction from an Ensemble\n";
         print "I create a data source uploading a " . $item["filename"] . " file\n";
         $source = self::$api->create_source($item["filename"], $options = array('name' => 'local_test_source', 'project' => self::$project->resource));
         $this->assertEquals(BigMLRequest::HTTP_CREATED, $source->code);
         $this->assertEquals(1, $source->object->status->code);
         print "And I wait until the source is ready\n";
         $resource = self::$api->_check_resource($source->resource, null, 3000, 30);
         $this->assertEquals(BigMLRequest::FINISHED, $resource["status"]);
         print "And I create dataset with local source\n";
         $dataset = self::$api->create_dataset($source->resource);
         $this->assertEquals(BigMLRequest::HTTP_CREATED, $dataset->code);
         $this->assertEquals(BigMLRequest::QUEUED, $dataset->object->status->code);
         print "And I wait until the dataset is ready\n";
         $resource = self::$api->_check_resource($dataset->resource, null, 3000, 30);
         $this->assertEquals(BigMLRequest::FINISHED, $resource["status"]);
         print "And I create a ensemble of " . $item["number_of_models"] . " models and " . $item["tlp"] . " tlp\n";
         $ensemble = self::$api->create_ensemble($dataset->resource, array("number_of_models" => $item["number_of_models"], "tlp" => $item["tlp"], "seed" => 'BigML', 'sample_rate' => 0.7));
         $this->assertEquals(BigMLRequest::HTTP_CREATED, $ensemble->code);
         print "And I wait until the ensemble is ready\n";
         $resource = self::$api->_check_resource($ensemble->resource, null, 3000, 50);
         $this->assertEquals(BigMLRequest::FINISHED, $resource["status"]);
         print "And I create a local ensemble:\n";
         $ensemble = self::$api->get_ensemble($ensemble->resource);
         $local_ensemble = new Ensemble($ensemble, self::$api);
         print "When I create a local ensemble prediction using median with confidence  for " . json_encode($item["data_input"]) . "\n";
         $prediction = $local_ensemble->predict($item["data_input"], array('with_confidence' => true, 'median' => true));
         print "Then the local prediction is " . $item["prediction"] . "\n";
         $this->assertEquals($item["prediction"], round($prediction[0], 4));
     }
 }
 public function test_scenario5()
 {
     $data = array(array("filename" => 'data/grades.csv', "number_of_models" => 2, "tlp" => 1, "data_input" => array(), "prediction" => 67.88160000000001));
     foreach ($data as $item) {
         print "I create a data source uploading a " . $item["filename"] . " file\n";
         $source = self::$api->create_source($item["filename"], $options = array('name' => 'local_test_source'));
         $this->assertEquals(BigMLRequest::HTTP_CREATED, $source->code);
         $this->assertEquals(1, $source->object->status->code);
         print "check local source is ready\n";
         $resource = self::$api->_check_resource($source->resource, null, 3000, 30);
         $this->assertEquals(BigMLRequest::FINISHED, $resource["status"]);
         print "create dataset with local source\n";
         $dataset = self::$api->create_dataset($source->resource);
         $this->assertEquals(BigMLRequest::HTTP_CREATED, $dataset->code);
         $this->assertEquals(BigMLRequest::QUEUED, $dataset->object->status->code);
         print "check the dataset is ready\n";
         $resource = self::$api->_check_resource($dataset->resource, null, 3000, 30);
         $this->assertEquals(BigMLRequest::FINISHED, $resource["status"]);
         print "create a ensemble from ";
         $ensemble = self::$api->create_ensemble($dataset->resource, array("number_of_models" => $item["number_of_models"], "tlp" => $item["tlp"], "seed" => 'BigML', 'sample_rate' => 0.7));
         $this->assertEquals(BigMLRequest::HTTP_CREATED, $ensemble->code);
         print "check the ensemble is ready\n";
         $resource = self::$api->_check_resource($ensemble->resource, null, 3000, 50);
         $this->assertEquals(BigMLRequest::FINISHED, $resource["status"]);
         print "create a local ensemble:\n";
         $ensemble = self::$api->get_ensemble($ensemble->resource);
         $local_ensemble = new Ensemble($ensemble, self::$api);
         print "create prediction for local ensemble using_median_with_confidence  \n";
         $prediction = $local_ensemble->predict($item["data_input"], true, MultiVote::PLURALITY_CODE, true, false, false, false, false, false, false, null, Tree::LAST_PREDICTION, true);
         print "the prediction for local ensemble is equals " . $item["prediction"] . "\n";
         $this->assertEquals($item["prediction"], round($prediction[0], 4));
     }
 }