public function test_scenario1() { $data = array(array('filename' => 'data/iris.csv', 'local_file' => 'tmp/exported_iris.csv')); foreach ($data as $item) { print "\nSuccessfully exporting a dataset\n"; print "Given 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 source is ready\n"; $resource = self::$api->_check_resource($source->resource, null, 20000, 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 dataset is ready " . $dataset->resource . " \n"; $resource = self::$api->_check_resource($dataset->resource, null, 20000, 30); $this->assertEquals(BigMLRequest::FINISHED, $resource["status"]); print "And I download the dataset file to " . $item["local_file"] . " \n"; $filename = self::$api->download_dataset($dataset->resource, $item["local_file"]); $this->assertNotNull($filename); print "Then the download dataset file is like " . $item["filename"] . "\n"; $this->assertTrue(compareFiles($item["filename"], $item["local_file"])); } }
public function test_scenario5() { $data = array(array('filename' => 'data/tiny_kdd.csv', 'local_file' => 'tmp/batch_predictions.csv', 'predictions_file' => 'data/batch_predictions_a.csv')); 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, 20000, 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 " . $dataset->resource . " \n"; $resource = self::$api->_check_resource($dataset->resource, null, 20000, 30); $this->assertEquals(BigMLRequest::FINISHED, $resource["status"]); print "Then I create an anomaly detector from a dataset\n"; $anomaly = self::$api->create_anomaly($dataset->resource); print "I wait until the anomaly detector is ready\n"; $resource = self::$api->_check_resource($anomaly->resource, null, 3000, 30); $this->assertEquals(BigMLRequest::FINISHED, $resource["status"]); print "I create a batch anomaly score\n"; $batch_prediction = self::$api->create_batch_anomaly_score($anomaly, $dataset); $this->assertEquals(BigMLRequest::HTTP_CREATED, $batch_prediction->code); print "check a batch_predicion is ready\n"; $resource = self::$api->_check_resource($batch_prediction, null, 50000, 50); $this->assertEquals(BigMLRequest::FINISHED, $resource["status"]); print "download batch predictions file\n"; $filename = self::$api->download_batch_anomaly_score($batch_prediction, $item["local_file"]); $this->assertNotNull($filename); print "i compare the prediction file is correct\n"; $this->assertTrue(compareFiles($item["local_file"], $item["predictions_file"])); } }
public function test_scenario3() { $data = array(array("filename" => "data/spam.csv", "local_file" => "tmp/if_then_rules_spam_textanalysis_1.txt", "expected_file" => "data/model/if_then_rules_spam_textanalysis_1.txt", "options" => array("fields" => array("000001" => array("optype" => "text", "term_analysis" => array("case_sensitive" => true, "stem_words" => true, "use_stopwords" => false, "language" => "en"))))), array("filename" => "data/spam.csv", "local_file" => "tmp/if_then_rules_spam_textanalysis_2.txt", "expected_file" => "data/model/if_then_rules_spam_textanalysis_2.txt", "options" => array("fields" => array("000001" => array("optype" => "text", "term_analysis" => array("case_sensitive" => true, "stem_words" => true, "use_stopwords" => false))))), array("filename" => "data/spam.csv", "local_file" => "tmp/if_then_rules_spam_textanalysis_3.txt", "expected_file" => "data/model/if_then_rules_spam_textanalysis_3.txt", "options" => array("fields" => array("000001" => array("optype" => "text", "term_analysis" => array("case_sensitive" => false, "stem_words" => false, "use_stopwords" => false, "language" => "en"))))), array("filename" => "data/spam.csv", "local_file" => "tmp/if_then_rules_spam_textanalysis_4.txt", "expected_file" => "data/model/if_then_rules_spam_textanalysis_4.txt", "options" => array("fields" => array("000001" => array("optype" => "text", "term_analysis" => array("case_sensitive" => false, "stem_words" => true, "use_stopwords" => true, "language" => "en"))))), array("filename" => "data/spam.csv", "local_file" => "tmp/if_then_rules_spam_textanalysis_5.txt", "expected_file" => "data/model/if_then_rules_spam_textanalysis_5.txt", "options" => array("fields" => array("000001" => array("optype" => "text", "term_analysis" => array("token_mode" => "full_terms_only", "language" => "en")))))); foreach ($data as $item) { print "\nSuccessfully creating a model and translate the tree model into a set of IF-THEN rules\n"; print "Given 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, 10000, 30); $this->assertEquals(BigMLRequest::FINISHED, $resource["status"]); print "And I update the source with options " . json_encode($item["options"]) . "\n"; $source = self::$api->update_source($source->resource, $item["options"]); $this->assertEquals(BigMLRequest::HTTP_ACCEPTED, $source->code); 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, 10000, 30); $this->assertEquals(BigMLRequest::FINISHED, $resource["status"]); print "And I create model\n"; $model = self::$api->create_model($dataset->resource); $this->assertEquals(BigMLRequest::HTTP_CREATED, $model->code); print "And I wait until the model is ready " . $model->resource . "\n"; $resource = self::$api->_check_resource($model->resource, null, 10000, 30); $this->assertEquals(BigMLRequest::FINISHED, $resource["status"]); print "And I create a local model\n"; $local_model = new Model($model->resource, self::$api); print "And I translate the tree into IF_THEN rules\n"; $fp = fopen($item["local_file"], 'w'); $local_model->rules($fp); print " Then I check the output is like " . $item["expected_file"] . " expected file\n"; $this->assertTrue(compareFiles($item["local_file"], $item["expected_file"])); } }
public function test_scenario6() { $data = array(array('filename' => 'data/iris.csv', 'local_file' => 'tmp/batch_predictions.csv', 'predictions_file' => 'data/batch_predictions_lr.csv')); foreach ($data as $item) { print "\nSuccessfully creating a batch prediction for a logistic regression\n"; print "Given 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, 20000, 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 " . $dataset->resource . " \n"; $resource = self::$api->_check_resource($dataset->resource, null, 20000, 30); $this->assertEquals(BigMLRequest::FINISHED, $resource["status"]); print "And I create a logistic regresssion modeld \n"; $logistic_regression = self::$api->create_logistic_regression($dataset->resource); $this->assertEquals(BigMLRequest::HTTP_CREATED, $logistic_regression->code); print "And I wait until the logistic regression model is ready " . $logistic_regression->resource . "\n"; $resource = self::$api->_check_resource($logistic_regression->resource, null, 10000, 30); $this->assertEquals(BigMLRequest::FINISHED, $resource["status"]); print "I create a batch prediction for the dataset with the logistic regression\n"; $batch_prediction = self::$api->create_batch_prediction($logistic_regression, $dataset); $this->assertEquals(BigMLRequest::HTTP_CREATED, $batch_prediction->code); print "And I wait until the batch_predicion is ready\n"; $resource = self::$api->_check_resource($batch_prediction, null, 3000, 50); $this->assertEquals(BigMLRequest::FINISHED, $resource["status"]); print "And I download the created predictions file to " . $item["local_file"] . "\n"; $filename = self::$api->download_batch_prediction($batch_prediction, $item["local_file"]); $this->assertNotNull($filename); print "Then the batch prediction file is like " . $item["predictions_file"] . "\n"; $this->assertTrue(compareFiles($item["local_file"], $item["predictions_file"])); } }