Turi Create  4.0
supervised_learning.hpp
1 /* Copyright © 2017 Apple Inc. All rights reserved.
2  *
3  * Use of this source code is governed by a BSD-3-clause license that can
4  * be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
5  */
6 #ifndef TURI_SUPERVISED_LEARNING_H_
7 #define TURI_SUPERVISED_LEARNING_H_
8 
9 // SFrame
10 #include <core/storage/sframe_data/sarray.hpp>
11 #include <core/storage/sframe_data/sframe.hpp>
12 #include <core/data/sframe/gl_sarray.hpp>
13 #include <core/data/sframe/gl_sframe.hpp>
14 
15 // Interfaces
16 #include <model_server/lib/extensions/ml_model.hpp>
17 
18 // ML-Data Utils
19 #include <ml/ml_data/ml_data.hpp>
20 #include <ml/ml_data/ml_data_iterator.hpp>
21 
22 // Types
23 #include <model_server/lib/variant.hpp>
24 #include <model_server/lib/unity_base_types.hpp>
25 #include <model_server/lib/variant_deep_serialize.hpp>
26 #include <toolkits/coreml_export/mlmodel_wrapper.hpp>
27 
28 #include <Eigen/Core>
29 #include <Eigen/SparseCore>
30 
31 #include <core/export.hpp>
32 
33 #include <model_server/lib/toolkit_class_macros.hpp>
34 
35 // TODO: List of todo's for this file
36 //------------------------------------------------------------------------------
37 // 1. ml_data_example type for predict.
38 //
39 
40 namespace turi {
41 namespace supervised {
42 
43 class supervised_learning_model_base;
44 typedef Eigen::Matrix<double, Eigen::Dynamic,1> DenseVector;
45 typedef Eigen::SparseVector<double> SparseVector;
46 
47 /**
48  * An enumeration over the possible types of prediction that are supported.
49  * \see prediction_type_enum_from_name
50  */
51 enum class prediction_type_enum: char {
52  NA = 0, /**< NA: Default/Not-applicable.*/
53  CLASS = 1,
54  CLASS_INDEX = 2, /**< Index of the class (performance reasons) .*/
55  PROBABILITY = 3,
56  MAX_PROBABILITY = 4, /**< Max probability for classify .*/
57  MARGIN = 5,
58  RANK = 6,
59  PROBABILITY_VECTOR = 7 /** < A vector of probabilities .*/
60 };
61 
62 /**
63  * Given the printable name of a prediction_type_enum type, it returns the name.
64  *
65  * \param[in] name Name of the prediction_type_enum type.
66  * \returns prediction_type_enum
67  */
68 inline prediction_type_enum prediction_type_enum_from_name(const std::string& name) {
69  static std::map<std::string, prediction_type_enum> type_map{
70  {"na", prediction_type_enum::NA},
71  {"", prediction_type_enum::NA},
72  {"class", prediction_type_enum::CLASS},
73  {"class_index", prediction_type_enum::CLASS_INDEX},
74  {"probability", prediction_type_enum::PROBABILITY},
75  {"max_probability", prediction_type_enum::MAX_PROBABILITY},
76  {"margin", prediction_type_enum::MARGIN},
77  {"rank", prediction_type_enum::RANK},
78  {"probability_vector", prediction_type_enum::PROBABILITY_VECTOR},
79  };
80  if (type_map.count(name) == 0) {
81  log_and_throw(std::string("Invalid prediction type name " + name));
82  }
83  return type_map.at(name);
84 }
85 
86 
87 /**
88  * Create a supervised learning model.
89  * ---------------------------------------
90  *
91  * \param[in] X : An SFrame of features.
92  * \param[in] y : An SFrame with a single column containing the target.
93  * \param[in] model_name : Model name to be created (same as model->name())
94  * \param[out] A created supervised learning model.
95  */
96 
97 std::shared_ptr<supervised_learning_model_base> create(
98  sframe X, sframe y, std::string model_name,
99  const variant_map_type& kwargs);
100 
101 /**
102  * Supervised_learning model base class.
103  * ---------------------------------------
104  *
105  * Base class for handling supervised learning class. This class is meant to
106  * be a guide to aid model writing and not a hard and fast rule of how the
107  * code must be structured.
108  *
109  * Each supervised learning C++ toolkit contains the following:
110  *
111  * *) model: This is the key-value map that stores the "model" attributes.
112  * The value is of type "variant_type" which is fully interfaced
113  * with python. You can add basic types, vectors, SFrames etc.
114  *
115  * *) ml_mdata: A globally consistent object with column wise metadata. This
116  * metadata changes with time (even after training). If you
117  * want to freeze the metadata after training, you have to do
118  * so yourself.
119  *
120  * *) train_feature_size: Feature sizes (i.e column sizes) during train time.
121  * Numerical features are of size 1, categorical features
122  * are of size (# categories), vector features are of size
123  * length, and dictionary features are of size # keys.
124  *
125  * *) options: Option manager which keeps track of default options, current
126  * options, option ranges, type etc. This must be initialized only
127  * once in the set_options() function.
128  *
129  *
130  * Functions that should always be implemented. Here are some notes about
131  * each of these functions that may help guide you in writing your model.
132  *
133  *
134  * *) name: Get the name of this model. You might thinks that this is silly but
135  * the name holds the key to everything. The unity_server can construct
136  * model_base objects and they can be cast to a model of this type.
137  * The name determine how the casting happens. The init_models()
138  * function in unity_server.cpp will give you an idea of how
139  * this interface happens.
140  *
141  * *) train: A train function for the model.
142  *
143  * *) predict_single_example: A predict function for the model for single
144  * example. If this is implemented, batch predictions and evaluation
145  * need not be implemented.
146  *
147  * *) predict: A predict function for the model for batch predictions.
148  * The result of this function can be an SArray of predictions.
149  * One for each value of the input SFrame.
150  *
151  * *) evaluate: An evaluattion function for the model for evaluations.
152  * The result of this function must be an updated evaluation_stats
153  * map which can be queried with the get_evaluation_stats().
154  *
155  * *) save: Save the model with the turicreate iarc. Turi is a server-client
156  * module. DO NOT SAVE ANYTHING in the client side. Make sure that
157  * everything is in the server side. For example: You might be tempted
158  * do keep options that the user provides into the server side but
159  * DO NOT do that because save and load will break things for you!
160  *
161  * *) load: Load the model with the turicreate oarc.
162  *
163  * *) init_options: Init the options
164  *
165  *
166  * This class interfaces with the SupervisedLearning class in Python and works
167  * end to end once the following set of fuctions are implemented by the user.
168  *
169  *
170  * Example Class
171  * -----------------------------------------------------------------------------
172  *
173  * See the file supervised_learning_model.cxx for an example of how to use
174  * this class in building your supervised learning method.
175  *
176  *
177  *
178  */
180 
181  protected:
182 
183  std::vector<std::string> metrics; /* Evaluation metric(s). */
184  std::vector<std::string> tracking_metrics; /* Tracking metric(s). */
185  bool show_extra_warnings = true; /* If true, be more verbose.*/
186 
187  public:
188 
189  std::shared_ptr<ml_metadata> ml_mdata; /* ML-Data-2 metadata. */
190 
191  // virtual destructor
192  virtual ~supervised_learning_model_base() { }
193 
194  /**
195  * Methods that must be implemented in a new supervised_learning model.
196  * -------------------------------------------------------------------------
197  */
198 
199 
200  /**
201  * Train a supervised_learning model.
202  */
203  virtual void train() = 0;
204 
205 
206  /**
207  * Get metadata mapping.
208  */
209  std::vector<std::vector<flexible_type>> get_metadata_mapping();
210 
211  /**
212  * Methods with default implementations but are in-flux during the
213  * Trees and NeuralNetworks integration
214  * -------------------------------------------------------------------------
215  */
216 
217  /**
218  * Predict for a single example.
219  *
220  * \param[in] x Single example.
221  * \param[in] output_type Type of prediction.
222  *
223  * \returns Prediction for a single example.
224  *
225  */
227  const ml_data_iterator& it,
228  const prediction_type_enum& output_type=prediction_type_enum::NA) {
229  return 0.0;
230  }
231 
232  /**
233  * Predict for a single example.
234  *
235  * \param[in] x Single example.
236  * \param[in] output_type Type of prediction.
237  *
238  * \returns Prediction for a single example.
239  *
240  */
242  const DenseVector & x,
243  const prediction_type_enum& output_type=prediction_type_enum::NA) {
244  return 0.0;
245  }
246 
247  /**
248  * Predict for a single example.
249  *
250  * \param[in] x Single example.
251  * \param[in] output_type Type of prediction.
252  *
253  * \returns Prediction for a single example.
254  *
255  */
257  const SparseVector & x,
258  const prediction_type_enum& output_type=prediction_type_enum::NA) {
259  return 0.0;
260  }
261 
262  /**
263  * Evaluate the model.
264  *
265  * \param[in] test_data Test data.
266  * \param[in] evaluation_type Evalution type.
267  *
268  * \note Already assumes that data is of the right shape. Test data
269  * must contain target column also.
270  *
271  */
272  virtual std::map<std::string, variant_type> evaluate(const ml_data&
273  test_data, const std::string& evaluation_type="", bool with_prediction=false);
274 
275  /**
276  * Same as evaluate(ml_data), but take SFrame as input.
277  */
278  virtual std::map<std::string, variant_type> evaluate(const sframe& X,
279  const sframe &y, const std::string& evaluation_type="", bool with_prediction=false) {
280  ml_data data = construct_ml_data_using_current_metadata(X, y);
281  return this->evaluate(data, evaluation_type, with_prediction);
282  }
283 
284  /**
285  * Make predictions using a trained supervised_learning model.
286  *
287  * \param[in] test_X Test data (only independent variables)
288  * \param[in] output_type Type of prediction.
289  * \returns ret Shared pointer to an SArray containing predicions.
290  *
291  * \note Already assumes that data is of the right shape.
292  */
293  virtual std::shared_ptr<sarray<flexible_type>> predict(
294  const ml_data& test_data, const std::string& output_type="");
295 
296  /**
297  * Same as predict(ml_data), but takes SFrame as input.
298  */
299  virtual std::shared_ptr<sarray<flexible_type>> predict(
300  const sframe& X, const std::string& output_type="") {
301  ml_data data = construct_ml_data_using_current_metadata(X);
302  return predict(data, output_type);
303  }
304 
305 
306  /**
307  * Extract features!
308  */
309  virtual std::shared_ptr<sarray<flexible_type>> extract_features(
310  const sframe& X, ml_missing_value_action missing_value_action) {
311  log_and_throw("Model does not support feature extraction");
312  }
313 
314  /**
315  * Make multiclass predictions using a trained supervised_learning model.
316  *
317  * \param[in] test_X Test data (only independent variables)
318  * \param[in] output_type Type of prediction.
319  * \param[in] topk Number of classes to return.
320  * \returns ret SFrame containing {row_id, class, output_type}.
321  *
322  * \note Already assumes that data is of the right shape.
323  * \note Default throws error, model supporting this method should override
324  * this function.
325  */
326  virtual sframe predict_topk(const sframe& test_data,
327  const std::string& output_type="",
328  size_t topk=5) {
329  log_and_throw("Predicting multiple classes is not supported by this model.");
330  }
331 
332  /**
333  * Make multiclass predictions using a trained supervised_learning model.
334  *
335  * \param[in] test_X Test data (only independent variables)
336  * \param[in] output_type Type of prediction.
337  * \param[in] topk Number of classes to return.
338  * \returns ret SFrame containing {row_id, class, output_type}.
339  *
340  * \note Already assumes that data is of the right shape.
341  */
342  virtual sframe predict_topk(const ml_data& test_data,
343  const std::string& output_type="",
344  size_t topk=5);
345 
346  /**
347  * Make classification using a trained supervised_learning model.
348  *
349  * \param[in] X Test data (only independent variables)
350  * \param[in] output_type Type of classifcation (future proof).
351  * \returns ret SFrame with "class" and probability (if applicable)
352  *
353  * \note Already assumes that data is of the right shape.
354  */
355  virtual sframe classify(const ml_data& test_data,
356  const std::string& output_type="");
357 
358  /**
359  * Same as classify(ml_data), but takes SFrame as input.
360  */
361  virtual sframe classify(const sframe& X,
362  const std::string& output_type="") {
363 
364  ml_data data = construct_ml_data_using_current_metadata(X);
365  return classify(data, output_type);
366  };
367 
368  /**
369  * Fast path predictions given a row of flexible_types.
370  *
371  * \param[in] rows List of rows (each row is a flex_dict)
372  * \param[in] missing_value_action Missing value action string
373  * \param[in] output_type Output type.
374  */
375  virtual gl_sarray fast_predict(
376  const std::vector<flexible_type>& rows,
377  const std::string& missing_value_action = "error",
378  const std::string& output_type = "");
379 
380  /**
381  * Fast path predictions given a row of flexible_types.
382  *
383  * \param[in] rows List of rows (each row is a flex_dict)
384  * \param[in] missing_value_action Missing value action string
385  * \param[in] output_type Output type.
386  * \param[in] topk Number of classes to return
387  */
389  const std::vector<flexible_type>& rows,
390  const std::string& missing_value_action ="error",
391  const std::string& output_type="",
392  const size_t topk = 5) {
393  log_and_throw("Not implemented yet");
394  }
395 
396  /**
397  * Fast path predictions given a row of flexible_types
398  *
399  * \param[in] rows List of rows (each row is a flex_dict)
400  * \param[in] output_type Output type.
401  */
402  virtual gl_sframe fast_classify(
403  const std::vector<flexible_type>& rows,
404  const std::string& missing_value_action ="error");
405 
406  /**
407  * Methods with already meaningful default implementations.
408  * -------------------------------------------------------------------------
409  */
410 
411 
412  /**
413  * Init the model with the data.
414  *
415  * \param[in] X Predictors
416  * \param[in] y target
417  *
418  * Python side interface
419  * ------------------------
420  * NA.
421  *
422  */
423  virtual void init(
424  const sframe& X, const sframe& y,
425  const sframe& valid_X=sframe(),
426  const sframe& valid_y=sframe(),
427  ml_missing_value_action mva = ml_missing_value_action::ERROR);
428 
429  /**
430  * A setter for models that use Armadillo for model coefficients.
431  */
432  virtual void set_coefs(const DenseVector& coefs) {
433  DASSERT_TRUE(false);
434  }
435 
436  /**
437  * Set the evaluation metric. Set to RMSE by default.
438  */
439  void set_evaluation_metric(std::vector<std::string> _metrics){
440  metrics = _metrics;
441  }
442 
443 
444  /**
445  * Set the evaluation metric. Set to RMSE by default.
446  */
447  void set_tracking_metric(std::vector<std::string> _metrics){
448  tracking_metrics = _metrics;
449  }
450 
451  /**
452  * Set the Extra Warnings output. These warnings include telling the user
453  * about low-variance features, etc...
454  */
455  void set_more_warnings(bool more_warnings){
456  show_extra_warnings = more_warnings;
457  }
458 
459  /**
460  * Set the default evaluation metric during model evaluation.
461  */
463  set_evaluation_metric({"max_error", "rmse"});
464  }
465 
466  /**
467  * Set the default evaluation metric for progress tracking.
468  */
470  set_tracking_metric({"max_error", "rmse"});
471  }
472 
473  /**
474  * Get training stats.
475  *
476  * \returns The training stats map.
477  *
478  * Python side interface
479  * ------------------------
480  * The dictionary returned to the user can be transfered as is to the python
481  * side. You MUST use this to return a dictionary to the object.
482  */
483  std::map<std::string, flexible_type> get_train_stats() const;
484 
485  /**
486  * Impute missing columns with 'None' values.
487  *
488  * \param[in] X Predictors
489  *
490  * \returns An SFrame with 'None' written to all columns that are missing.
491  *
492  */
493  sframe impute_missing_columns_using_current_metadata(const sframe& X) const;
494 
495  /**
496  * Construct ml-data from the predictors and target using the current
497  * value of the metadata.
498  *
499  * \param[in] X Predictors
500  * \param[in] y target
501  * \param[in] new_opts Additional options.
502  *
503  * \returns A constructed ml_data object
504  *
505  */
506  ml_data construct_ml_data_using_current_metadata(
507  const sframe& X, const sframe& y,
508  ml_missing_value_action mva = ml_missing_value_action::ERROR) const;
509 
510  /**
511  * Construct ml-data from the predictors using the current
512  * value of the metadata.
513  *
514  * \param[in] X Predictors
515  * \param[in] new_opts Additional options.
516  *
517  * \returns A constructed ml_data object
518  *
519  */
520  ml_data construct_ml_data_using_current_metadata(
521  const sframe& X,
522  ml_missing_value_action mva = ml_missing_value_action::ERROR) const;
523 
524  /**
525  * Get the number of feature columns in the model
526  *
527  * \returns Number of features.
528  */
529  size_t num_features() const;
530 
531  /**
532  * Get the number of examples in the model
533  *
534  * \returns Number of examples.
535  */
536  size_t num_examples() const;
537 
538  /**
539  * Get the number of features in the model (unpacked)
540  *
541  * \returns Number of features.
542  */
543  size_t num_unpacked_features() const;
544 
545  /**
546  * Get names of predictor variables.
547  *
548  * \returns Names of features (Vector of string names).
549  */
550  std::vector<std::string> get_feature_names() const;
551 
552  /**
553  * Get name of the target column.
554  *
555  * \returns Names of target.
556  */
557  std::string get_target_name() const;
558 
559  /**
560  * Get ml_metadata.
561  *
562  * \returns Get the ml_metadata.
563  */
564  std::shared_ptr<ml_metadata> get_ml_metadata() const {
565  return this->ml_mdata;
566  }
567 
568  /**
569  * Returns true if the model is a classifier.
570  */
571  virtual bool is_classifier() const = 0;
572 
573  /**
574  * Returns true if the model is a classifier.
575  */
576  bool is_dense() {
577  return ((this->ml_mdata)->num_dimensions() <= 3 * num_features()) ? true : false;
578  }
579 
580  /**
581  * Get metrics strings.
582  */
583  std::vector<std::string> get_metrics() const;
584 
585  /**
586  * Get tracking metrics strings.
587  */
588  std::vector<std::string> get_tracking_metrics() const;
589 
590  /**
591  * Get metric display name.
592  */
593  std::string get_metric_display_name(const std::string& metric) const;
594 
595  /**
596  * Display model training data summary for regression.
597  *
598  * \param[in] model_display_name Name to be displayed
599  *
600  */
601  void display_regression_training_summary(std::string model_display_name) const;
602 
603  /**
604  * Display model training data summary for classifier.
605  *
606  * \param[in] model_display_name Name to be displayed
607  *
608  */
609  void display_classifier_training_summary(std::string model_display_name, bool simple_mode = false) const;
610 
611  /**
612  * Methods with no current implementation (or empty implementations)
613  * -------------------------------------------------------------------------
614  */
615 
616  /**
617  * Initialize things that are specific to your model.
618  *
619  * \param[in] data ML-Data object created by the init function.
620  *
621  */
622  virtual void model_specific_init(const ml_data& data,
623  const ml_data& validation_data) { }
624 
625  /**
626  * Returns true if the model can handle missing value
627  */
628  virtual bool support_missing_value() const { return false; }
629 
630  /**
631  * API interface through the unity server.
632  *
633  * Train the model
634  */
635  void api_train(gl_sframe data, const std::string& target,
636  const variant_type& validation_data,
637  const std::map<std::string, flexible_type>& _options);
638 
639  /**
640  * API interface through the unity server.
641  *
642  * Run prediction.
643  */
644  gl_sarray api_predict(gl_sframe data, std::string missing_value_action,
645  std::string output_type); // TODO: This should be const
646 
647  /**
648  * API interface through the unity server.
649  *
650  * Run multiclass prediction.
651  */
652  gl_sframe api_predict_topk(gl_sframe data, std::string missing_value_action,
653  std::string output_type, size_t topk = 5);
654  // TODO: This function should be const.
655 
656  /**
657  * API interface through the unity server.
658  *
659  * Run classification.
660  */
661  // TODO: This function should be const
662  gl_sframe api_classify(gl_sframe data, std::string missing_value_action,
663  std::string output_type); // TODO: This should be const
664 
665  /**
666  * API interface through the unity server.
667  *
668  * Evaluate the model
669  */
670  // TODO: This function should be const
671  variant_map_type api_evaluate(
672  gl_sframe data, std::string missing_value_action, std::string metric, gl_sarray predictions = gl_sarray(), bool with_prediction=false);
673 
674  /**
675  * API interface through the unity server.
676  *
677  * Extract features!
678  */
679  // TODO: This function should be const
680  gl_sarray api_extract_features(
681  gl_sframe data, std::string missing_value_action);
682 
683  /** Export to CoreML.
684  */
685  virtual std::shared_ptr<coreml::MLModelWrapper> export_to_coreml() = 0;
686 
687  std::shared_ptr<coreml::MLModelWrapper> api_export_to_coreml(const std::string& file);
688 
689  //////////////////////////////////////////////////////////////////////////////
690 
692 
694 
696  "train", supervised_learning_model_base::api_train, "data", "target",
697  "validation_data", "options");
698  register_defaults("train",
699  {{"validation_data", to_variant(gl_sframe())},
700  {"options",
701  to_variant(std::map<std::string, flexible_type>())}});
702 
705  "missing_value_action", "output_type");
706 
707  register_defaults("predict", {{"missing_value_action", std::string("auto")},
708  {"output_type", std::string("")}});
709 
711  "fast_predict", supervised_learning_model_base::fast_predict, "rows",
712  "missing_value_action", "output_type");
713 
714  register_defaults("fast_predict",
715  {{"missing_value_action", std::string("auto")},
716  {"output_type", std::string("")}});
717 
719  "predict_topk", supervised_learning_model_base::api_predict_topk, "data",
720  "missing_value_action", "output_type", "topk");
721 
722  register_defaults("predict_topk",
723  {{"missing_value_action", std::string("error")},
724  {"output_type", std::string("")}});
725 
728  "rows", "missing_value_action", "output_type", "topk");
729 
730  register_defaults("fast_predict_topk",
731  {{"missing_value_action", std::string("auto")},
732  {"output_type", std::string("")}});
733 
736  "missing_value_action");
737 
738  register_defaults("classify",
739  {{"missing_value_action", std::string("auto")}});
740 
742  "fast_classify", supervised_learning_model_base::fast_classify, "rows",
743  "missing_value_action");
744 
745  register_defaults("fast_classify",
746  {{"missing_value_action", std::string("auto")}});
747 
750  "missing_value_action", "metric", "predictions", "with_predictions");
751 
752  register_defaults("evaluate",
753  {{"metric", std::string("_report")},
754  {"missing_value_action", std::string("auto")},
755  {"predictions", gl_sarray()},
756  {"with_predictions", false}
757  });
758 
761  "data", "missing_value_action");
762 
763  register_defaults("extract_features",
764  {{"missing_value_action", std::string("auto")}});
765 
770 
772  "export_to_coreml", supervised_learning_model_base::api_export_to_coreml,
773  "filename");
774 
775  register_defaults("export_to_coreml", {{"filename", std::string("")}});
776 
778 
779  protected:
780  ml_missing_value_action get_missing_value_enum_from_string(
781  const std::string& missing_value_str) const;
782 };
783 
784 /**
785  * Obtains the function registration for the toolkit.
786  */
787 std::vector<toolkit_function_specification> get_toolkit_function_registration();
788 
789 /**
790  * Fast prediction path for in-memory predictions on a list of rows.
791  * \param[in] model Supervised learning model.
792  * \param[in] rows List of rows to make a prediction with.
793  */
794 gl_sarray _fast_predict(
795  std::shared_ptr<supervised_learning_model_base> model,
796  const std::vector<flexible_type>& rows,
797  const std::string& missing_value_action = "error",
798  const std::string& output_type = "probability");
799 
800 /**
801  * Fast path for in-memory predictions on a list of rows.
802  *
803  * \param[in] model Supervised learning model.
804  * \param[in] rows List of rows to make a prediction with.
805  */
806 gl_sframe _fast_predict_topk(
807  std::shared_ptr<supervised_learning_model_base> model,
808  const std::vector<flexible_type>& rows,
809  const std::string& missing_value_action = "error",
810  const std::string& output_type = "probability",
811  const size_t topk = 5);
812 
813 /**
814  * Fast path for in-memory predictions on a list of rows.
815  *
816  * \param[in] model Supervised learning model.
817  * \param[in] rows List of rows to make a prediction with.
818  */
819 gl_sframe _fast_classify(
820  std::shared_ptr<supervised_learning_model_base> model,
821  const std::vector<flexible_type>& rows,
822  const std::string& missing_value_action = "error");
823 
824 /**
825  * Get the metadata mapping.
826  *
827  * \param[in] model Supervised learning model.
828  */
829 std::vector<std::vector<flexible_type>> _get_metadata_mapping(
830  std::shared_ptr<supervised_learning_model_base> model);
831 
832 } // supervised
833 } // turicreate
834 
835 #endif
virtual void set_coefs(const DenseVector &coefs)
void api_train(gl_sframe data, const std::string &target, const variant_type &validation_data, const std::map< std::string, flexible_type > &_options)
#define REGISTER_CLASS_MEMBER_FUNCTION(function,...)
virtual void model_specific_init(const ml_data &data, const ml_data &validation_data)
variant_map_type api_evaluate(gl_sframe data, std::string missing_value_action, std::string metric, gl_sarray predictions=gl_sarray(), bool with_prediction=false)
#define BEGIN_BASE_CLASS_MEMBER_REGISTRATION()
std::map< std::string, flexible_type > get_train_stats() const
std::vector< std::string > get_feature_names() const
void set_tracking_metric(std::vector< std::string > _metrics)
virtual flexible_type predict_single_example(const ml_data_iterator &it, const prediction_type_enum &output_type=prediction_type_enum::NA)
virtual flexible_type predict_single_example(const SparseVector &x, const prediction_type_enum &output_type=prediction_type_enum::NA)
#define IMPORT_BASE_CLASS_REGISTRATION(base_class)
boost::make_recursive_variant< flexible_type, std::shared_ptr< unity_sgraph_base >, dataframe_t, std::shared_ptr< model_base >, std::shared_ptr< unity_sframe_base >, std::shared_ptr< unity_sarray_base >, std::map< std::string, boost::recursive_variant_ >, std::vector< boost::recursive_variant_ >, boost::recursive_wrapper< function_closure_info > >::type variant_type
Definition: variant.hpp:24
virtual gl_sframe fast_predict_topk(const std::vector< flexible_type > &rows, const std::string &missing_value_action="error", const std::string &output_type="", const size_t topk=5)
gl_sframe api_predict_topk(gl_sframe data, std::string missing_value_action, std::string output_type, size_t topk=5)
gl_sarray api_extract_features(gl_sframe data, std::string missing_value_action)
#define END_CLASS_MEMBER_REGISTRATION
virtual std::shared_ptr< sarray< flexible_type > > predict(const sframe &X, const std::string &output_type="")
virtual std::shared_ptr< sarray< flexible_type > > extract_features(const sframe &X, ml_missing_value_action missing_value_action)
#define REGISTER_NAMED_CLASS_MEMBER_FUNCTION(name, function,...)
variant_type to_variant(const T &f)
Definition: variant.hpp:308
virtual gl_sarray fast_predict(const std::vector< flexible_type > &rows, const std::string &missing_value_action="error", const std::string &output_type="")
gl_sframe api_classify(gl_sframe data, std::string missing_value_action, std::string output_type)
virtual gl_sframe fast_classify(const std::vector< flexible_type > &rows, const std::string &missing_value_action="error")
virtual std::map< std::string, variant_type > evaluate(const sframe &X, const sframe &y, const std::string &evaluation_type="", bool with_prediction=false)
std::shared_ptr< ml_metadata > get_ml_metadata() const
void set_evaluation_metric(std::vector< std::string > _metrics)
gl_sarray api_predict(gl_sframe data, std::string missing_value_action, std::string output_type)
virtual sframe classify(const sframe &X, const std::string &output_type="")
#define DASSERT_TRUE(cond)
Definition: assertions.hpp:364
virtual flexible_type predict_single_example(const DenseVector &x, const prediction_type_enum &output_type=prediction_type_enum::NA)
virtual sframe predict_topk(const sframe &test_data, const std::string &output_type="", size_t topk=5)