From 7aa26e0b01bf7cac278fe530a9233c00afdc5c6d Mon Sep 17 00:00:00 2001 From: Jose Ribes Date: Sat, 18 Jul 2015 12:39:19 +0200 Subject: [PATCH 1/4] update properties of initial resources Added some of new properties. Removed properties that not exist anymore. --- CHANGELOG.md | 11 +++++++++++ lib/big_ml/dataset.rb | 13 ++++++++++--- lib/big_ml/ensemble.rb | 14 +++++++------- lib/big_ml/evaluation.rb | 14 ++++++++------ lib/big_ml/model.rb | 18 ++++++++++++------ lib/big_ml/prediction.rb | 13 +++++++++---- lib/big_ml/source.rb | 9 ++++++--- lib/big_ml/version.rb | 2 +- 8 files changed, 64 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71c7ab0..3625b39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## 0.2.0 +- BigML::Anomaly +- BigML::Cluster +- BigML::Centroid +- BigML::Score +- BigML::BatchCentroid +- BigML::BatchScore + +## 0.1.4 +- Update resources properties + ## 0.1.1 - Casting method to_* added - Update and destroy methods in the instances diff --git a/lib/big_ml/dataset.rb b/lib/big_ml/dataset.rb index 4dbd30b..26b0c5e 100644 --- a/lib/big_ml/dataset.rb +++ b/lib/big_ml/dataset.rb @@ -4,9 +4,16 @@ module BigML class Dataset < Base DATASET_PROPERTIES = [ :category, :code, :columns, :created, :credits, - :description, :fields, :locale, :name, :number_of_models, - :number_of_predictions, :private, :resource, :rows, :size, - :source, :source_status, :status, :tags, :updated + :description, :dev, :excluded_fields, :field_types, + :fields, :fields_meta, :input_fields, :locale, :name, + :number_of_batchpredictions, :number_of_ensembles, + :number_of_evaluations, :number_of_models, + :number_of_predictions, :objective_field, :out_of_bag, :price, + :private, :project, :range, :refresh_field_types, + :refresh_preferred, :replacement, :resource, :rows, + :sample_rate, :seed, :shared, :shared_hash, :sharing_key, :size, + :source, :source_status, :status, :subscription, :tags, + :term_limit, :updated ] attr_reader *DATASET_PROPERTIES diff --git a/lib/big_ml/ensemble.rb b/lib/big_ml/ensemble.rb index 8e6a7ab..55d0580 100644 --- a/lib/big_ml/ensemble.rb +++ b/lib/big_ml/ensemble.rb @@ -3,17 +3,17 @@ module BigML class Ensemble < Base ENSEMBLE_PROPERTIES = [ - :category, :code, :columns, :created, :credits, + :category, :code, :columns, :created, :credits, :credits_per_prediction, :dataset, :dataset_status, :description, :dev, :distributions, - :holdout, :error_models, :excluded_fields, :finished_models, - :input_fields, :locale, :max_columns, :max_rows, :model_order, + :error_models, :excluded_fields, :finished_models, :input_fields, + :locale, :max_columns, :max_rows, :missing_splits, :model_order, :models, :name, :node_threshold, :number_of_batchpredictions, :number_of_evaluations, :number_of_models, :number_of_predictions, :number_of_public_predictions, :objective_field, :ordering, - :out_of_bag, :price, :private, :randomize, :random_candidates, - :range, :replacement, :resource, :rows, :sample_rate, :seed, - :shared, :shared_hash, :sharing_key, :size, :source, :source_status, - :status, :subscription, :tags, :tlp, :updated + :out_of_bag, :price, :private, :project, :randomize, :random_candidates, + :random_candidate_ratio, :range, :replacement, :resource, :rows, + :sample_rate, :seed, :shared, :shared_hash, :sharing_key, :size, :source, + :source_status, :status, :subscription, :tags, :tlp, :updated ] attr_reader *ENSEMBLE_PROPERTIES diff --git a/lib/big_ml/evaluation.rb b/lib/big_ml/evaluation.rb index 8c2618f..a237485 100644 --- a/lib/big_ml/evaluation.rb +++ b/lib/big_ml/evaluation.rb @@ -3,12 +3,14 @@ module BigML class Evaluation < Base EVALUATION_PROPERTIES = [ - :category, :code, :combiner, :created, :credits, :dataset, :dataset_status, - :description, :dev, :ensemble, :fields_map, :locale, :max_rows, :missing_strategy, - :model, :model_status, :model_type, :name, :number_of_models, :ordering, - :out_of_bag, :private, :range, :replacement, :resource, :result, :rows, :sample_rate, - :shared, :shared_hash, :sharing_key, :size, :status, :subscription, :tags, - :threshold, :type, :updated + :category, :code, :combiner, :confidence_threshold, :created, :credits, + :dataset, :dataset_status, :description, :dev, :ensemble, :fields_map, + :locale, :max_rows, :missing_strategy, :model, :model_status, + :model_type, :name, :negative_class, :number_of_models, :ordering, + :out_of_bag, :positive_class, :private, :project, :range, :replacement, + :resource, :result, :rows, :sample_rate, :shared, :shared_hash, + :sharing_key, :size, :status, :subscription, :tags, :threshold, :type, + :updated ] attr_reader *EVALUATION_PROPERTIES diff --git a/lib/big_ml/model.rb b/lib/big_ml/model.rb index 51d57aa..0ab12d3 100644 --- a/lib/big_ml/model.rb +++ b/lib/big_ml/model.rb @@ -3,12 +3,18 @@ module BigML class Model < Base MODEL_PROPERTIES = [ - :category, :code, :columns, :created, :credits, - :dataset, :dataset_status, :description, :holdout, - :input_fields, :locale, :max_columns, :max_rows, :model, - :name, :number_of_predictions, :objective_fields, :private, - :range, :resource, :rows, :size, :source, :source_status, - :status, :tags, :updated + :category, :code, :columns, :created, :credits, :credits_per_prediction, + :dataset, :dataset_field_types, :dataset_status, :description, :dev, + :ensemble, :ensemble_id, :ensemble_index, :excluded_fields, :fields_meta, + :input_fields, :locale, :max_columns, :max_rows, :missing_splits, :model, + :name, :node_threshold, :number_of_batchpredictions, + :number_of_evaluations, :number_of_predictions, + :number_of_publicpredictions, :objective_field, :objective_fields, + :ordering, :out_of_bag, :price, :private, :project, :randomize, + :random_candidates, :random_candidate_ratio, :range, :replacement, + :resource, :rows, :sample_rate, :seed, :selective_pruning, :shared, + :shared_hash, :sharing_key, :size, :source, :source_status, + :stat_pruning, :status, :subscription, :tags, :updated, :white_box ] attr_reader *MODEL_PROPERTIES diff --git a/lib/big_ml/prediction.rb b/lib/big_ml/prediction.rb index cb10196..e62790f 100644 --- a/lib/big_ml/prediction.rb +++ b/lib/big_ml/prediction.rb @@ -3,10 +3,15 @@ module BigML class Prediction < Base PREDICTION_PROPERTIES = [ - :category, :code, :created, :credits, :dataset, :dataset_status, - :description, :fields, :input_data, :model, :model_status, :name, - :objective_fields, :prediction, :prediction_path, :private, :resource, - :source, :source_status, :status, :tags, :updated + :category, :code, :combiner, :confidence, :created, :credits, :dataset, + :dataset_status, :description, :dev, :ensemble, :error_predictions, + :fields, :finished_predictions, :input_data, :locale, :missing_strategy, + :model, :models, :model_type, :model_status, :name, :number_of_models, + :objective_field, :objective_fields, :objective_field_name, :output, + :prediction, :predictions, :prediction_path, :private, :project, + :resource, :query_string, :source, :source_status, :status, :subscription, + :tags, :task, :threshold, :tlp, :total_count, :updated, :votes, + :vote_confidence ] attr_reader *PREDICTION_PROPERTIES diff --git a/lib/big_ml/source.rb b/lib/big_ml/source.rb index 6a659f6..aa46ff9 100644 --- a/lib/big_ml/source.rb +++ b/lib/big_ml/source.rb @@ -3,9 +3,12 @@ module BigML class Source < Base SOURCE_PROPERTIES = [ - :code, :content_type, :created, :credits, :fields, :file_name, :md5, - :name, :number_of_datasets, :number_of_models, :number_of_predictions, - :private, :resource, :size, :source_parser, :status, :type, :updated + :category, :code, :content_type, :created, :credits, :description, + :dev, :disable_datetime, :fields, :fields_meta, :file_name, :md5, + :name, :number_of_datasets, :number_of_ensembles, :number_of_models, + :number_of_predictions, :private, :project, :remote, :resource, :shared, + :shared_hash, :sharing_key, :size, :source_parser, :status, + :subscription, :tags, :term_analysis, :type, :updated ] attr_reader *SOURCE_PROPERTIES diff --git a/lib/big_ml/version.rb b/lib/big_ml/version.rb index fd88645..443faaa 100644 --- a/lib/big_ml/version.rb +++ b/lib/big_ml/version.rb @@ -1,3 +1,3 @@ module BigML - VERSION = "0.1.3" + VERSION = "0.1.4" end From e822494dc399a2302918738f0200721d7ea47a59 Mon Sep 17 00:00:00 2001 From: Jose Ribes Date: Sat, 18 Jul 2015 12:46:55 +0200 Subject: [PATCH 2/4] removes reference to changes not commited --- CHANGELOG.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3625b39..9050219 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,5 @@ # Changelog -## 0.2.0 -- BigML::Anomaly -- BigML::Cluster -- BigML::Centroid -- BigML::Score -- BigML::BatchCentroid -- BigML::BatchScore - ## 0.1.4 - Update resources properties From 397f3ea98288cc78f8c6f32d04a283d2e99de8b8 Mon Sep 17 00:00:00 2001 From: Jose Ribes Date: Mon, 20 Jul 2015 10:07:37 +0200 Subject: [PATCH 3/4] Adds a TODO item. Set ensembles and evs in changelog --- CHANGELOG.md | 4 ++++ TODO.md | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9050219..bc3a83f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ ## 0.1.4 - Update resources properties +## 0.1.2 or 0.1.3 +- BigML::Ensemble +- BigML::Evaluation + ## 0.1.1 - Casting method to_* added - Update and destroy methods in the instances diff --git a/TODO.md b/TODO.md index 1033a81..7d27519 100644 --- a/TODO.md +++ b/TODO.md @@ -3,4 +3,5 @@ ## Source - implement creation by url -- implement creation using inline data +- implement creation using inline data +- support VPC (private enviroment for customer) From f597c049c17bb3ed0e34bed8303aa37a0b6a9dbe Mon Sep 17 00:00:00 2001 From: Jose Ribes Date: Wed, 22 Jul 2015 00:13:46 +0200 Subject: [PATCH 4/4] new resources: anomaly, cluster, score and centroid. also allow batch scores and batch centroids --- CHANGELOG.md | 8 ++++++++ big_ml.gemspec | 4 ++-- lib/big_ml/anomaly.rb | 31 ++++++++++++++++++++++++++++ lib/big_ml/batch_centroid.rb | 39 ++++++++++++++++++++++++++++++++++++ lib/big_ml/batch_score.rb | 37 ++++++++++++++++++++++++++++++++++ lib/big_ml/centroid.rb | 22 ++++++++++++++++++++ lib/big_ml/cluster.rb | 32 +++++++++++++++++++++++++++++ lib/big_ml/score.rb | 22 ++++++++++++++++++++ 8 files changed, 193 insertions(+), 2 deletions(-) create mode 100644 lib/big_ml/anomaly.rb create mode 100644 lib/big_ml/batch_centroid.rb create mode 100644 lib/big_ml/batch_score.rb create mode 100644 lib/big_ml/centroid.rb create mode 100644 lib/big_ml/cluster.rb create mode 100644 lib/big_ml/score.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index bc3a83f..5ebb45c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 0.2.0 +- BigML::Anomaly +- BigML::Cluster +- BigML::Centroid +- BigML::Score +- BigML::BatchCentroid +- BigML::BatchScore + ## 0.1.4 - Update resources properties diff --git a/big_ml.gemspec b/big_ml.gemspec index 4c04379..bbaefad 100644 --- a/big_ml.gemspec +++ b/big_ml.gemspec @@ -2,8 +2,8 @@ require File.expand_path('../lib/big_ml/version', __FILE__) Gem::Specification.new do |gem| - gem.authors = ["Vicent Gozalbes", "Felipe Talavera"] - gem.email = ["vigosan@gmail.com", "felipe.talavera@gmail.com"] + gem.authors = ["Vicent Gozalbes", "Felipe Talavera", "Jose Ribes"] + gem.email = ["vigosan@gmail.com", "felipe.talavera@gmail.com", "jobez81@gmail.com"] gem.description = %q{A Ruby wrapper for the BigML REST API} gem.summary = %q{A Ruby wrapper for the BigML REST API} gem.homepage = "http://vigosan.github.com/big_ml" diff --git a/lib/big_ml/anomaly.rb b/lib/big_ml/anomaly.rb new file mode 100644 index 0000000..5f1412e --- /dev/null +++ b/lib/big_ml/anomaly.rb @@ -0,0 +1,31 @@ +require 'big_ml/base' + +module BigML + class Anomaly < Base + ANOMALY_PROPERTIES = [ + :anomaly_seed, :category, :code, :columns, :created, :credits, + :credits_per_prediction, :dataset, :dataset_field_types, + :dataset_status, :description, :dev, :excluded_fields, :fields_meta, + :forest_size, :id_fields, :input_fields, :locale, :max_columns, + :max_rows, :model, :name, :number_of_anomalyscores, + :number_of_batchanomalyscores, :number_of_public_anomalyscores, + :out_of_bag, :price, :private, :project, :range, :replacement, :resource, + :rows, :sample_rate, :seed, :shared, :shared_hash, :sharing_key, :size, + :source, :source_status, :status, :subscription, :tags, :top_n, :updated, + :white_box + ] + + attr_reader *ANOMALY_PROPERTIES + + def to_score(options) + Score.create(resource, options) + end + + class << self + def create(dataset, options = {}) + response = client.post("/#{resource_name}", options, { :dataset => dataset }) + self.new(response) if response.success? + end + end + end +end diff --git a/lib/big_ml/batch_centroid.rb b/lib/big_ml/batch_centroid.rb new file mode 100644 index 0000000..b22f907 --- /dev/null +++ b/lib/big_ml/batch_centroid.rb @@ -0,0 +1,39 @@ +require 'big_ml/base' + +module BigML + class BatchPrediction < Base + BATCH_PREDICTION_PROPERTIES = [ + :category, :code, :created, :credits, :dataset, :dataset_status, + :description, :fields, :dataset, :model, :model_status, :name, + :objective_fields, :prediction, :prediction_path, :private, :resource, + :source, :source_status, :status, :tags, :updated + ] + + attr_reader *BATCH_PREDICTION_PROPERTIES + + class << self + def create(model_or_ensemble, dataset, options = {}) + arguments = { dataset: dataset } + if model_or_ensemble.start_with? 'model' + arguments[:model] = model_or_ensemble + elsif model_or_ensemble.start_with? 'ensemble' + arguments[:ensemble] = model_or_ensemble + else + raise ArgumentError, "Expected model or ensemble, got #{model_or_ensemble}" + end + response = client.post("/#{resource_name}", {}, arguments.merge(options)) + self.new(response) if response.success? + end + + def download(id) + response = client.get("/#{resource_name}/#{id}/download") + response.body if response.success? + end + end + + def download + self.class.download(id) + end + + end +end diff --git a/lib/big_ml/batch_score.rb b/lib/big_ml/batch_score.rb new file mode 100644 index 0000000..3791786 --- /dev/null +++ b/lib/big_ml/batch_score.rb @@ -0,0 +1,37 @@ +require 'big_ml/base' + +module BigML + class BatchScore < Base + BATCH_SCORE_PROPERTIES = [ + :category, :code, :created, :credits, :dataset, :dataset_status, + :description, :fields, :dataset, :model, :model_status, :name, + :objective_fields, :prediction, :prediction_path, :private, :resource, + :source, :source_status, :status, :tags, :updated + ] + + attr_reader *BATCH_SCORE_PROPERTIES + + class << self + def create(anomaly, dataset, options = {}) + arguments = { dataset: dataset } + if cluster.start_with? 'anomaly' + arguments[:anomaly] = anomaly + else + raise ArgumentError, "Expected cluster, got #{anomaly}" + end + response = client.post("/#{resource_name}", {}, arguments.merge(options)) + self.new(response) if response.success? + end + + def download(id) + response = client.get("/#{resource_name}/#{id}/download") + response.body if response.success? + end + end + + def download + self.class.download(id) + end + + end +end diff --git a/lib/big_ml/centroid.rb b/lib/big_ml/centroid.rb new file mode 100644 index 0000000..6b90df6 --- /dev/null +++ b/lib/big_ml/centroid.rb @@ -0,0 +1,22 @@ +require 'big_ml/base' + +module BigML + class Centroid < Base + CENTROID_PROPERTIES = [ + :category, :centroid, :centroid_id, :centroid_name, :cluster, + :cluster_type, :cluster_status, :code, :created, :credits, :dataset, + :dataset_status, :description, :dev, :distance, :input_data, :locale, + :name, :private, :project, :resource, :query_string, :source, + :source_status, :status, :subscription, :tags, :updated + ] + + attr_reader *CENTROID_PROPERTIES + + class << self + def create(cluster, options = {}) + response = client.post("/#{resource_name}", {}, { cluster.split('/').first.to_sym => cluster }.merge!(options)) + self.new(response) if response.success? + end + end + end +end diff --git a/lib/big_ml/cluster.rb b/lib/big_ml/cluster.rb new file mode 100644 index 0000000..a9b1ad5 --- /dev/null +++ b/lib/big_ml/cluster.rb @@ -0,0 +1,32 @@ +require 'big_ml/base' + +module BigML + class Cluster < Base + CLUSTER_PROPERTIES = [ + :balance_fields, :category, :cluster_datasets, :cluster_seed, + :clusters, :code, :columns, :created, :credits, + :credits_per_prediction, :dataset, :dataset_field_types, + :dataset_status, :description, :dev, :excluded_fields, :fields_meta, + :field_scale, :input_fields, :k, :locale, :max_columns, :max_rows, + :model_clusters, :name, :number_of_batchcentroids, :number_of_centroids, + :number_of_public_centroids, :out_of_bag, :price, :private, :project, + :range, :replacement, :resource, :rows, :sample_rate, :scales, :seed, + :shared, :shared_hash, :sharing_key, :size, :source, :source_status, + :status, :subscription, :summary_fields, :tags, :updated, + :wheight_field, :white_box + ] + + attr_reader *CLUSTER_PROPERTIES + + def to_centroid(options) + Centroid.create(resource, options) + end + + class << self + def create(dataset, options = {}) + response = client.post("/#{resource_name}", options, { :dataset => dataset }) + self.new(response) if response.success? + end + end + end +end diff --git a/lib/big_ml/score.rb b/lib/big_ml/score.rb new file mode 100644 index 0000000..9842369 --- /dev/null +++ b/lib/big_ml/score.rb @@ -0,0 +1,22 @@ +require 'big_ml/base' + +module BigML + class Score < Base + SCORE_PROPERTIES = [ + :anomaly, :anomaly_status, :anomaly_type, + :category, :code, :created, :credits, :dataset, :dataset_status, + :description, :dev, :importance, :input_data, :locale, :name, + :private, :project, :resource, :score, :query_string, + :source, :source_status, :status, :subscription, :tags, :updated + ] + + attr_reader *SCORE_PROPERTIES + + class << self + def create(anomaly, options = {}) + response = client.post("/#{resource_name}", {}, { anomaly.split('/').first.to_sym => anomaly }.merge!(options)) + self.new(response) if response.success? + end + end + end +end