Turi Create  4.0
metrics.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_EVALUATION_H_
7 #define TURI_EVALUATION_H_
8 
9 #include <string>
10 #include <vector>
11 
12 #include <core/storage/sframe_data/sarray.hpp>
13 #include <core/storage/sframe_data/sframe.hpp>
14 #include <core/data/sframe/gl_sarray.hpp>
15 #include <core/data/sframe/gl_sframe.hpp>
16 #include <toolkits/evaluation/evaluation_constants.hpp>
17 #include <toolkits/evaluation/evaluation_interface-inl.hpp>
18 
19 namespace turi {
20 namespace evaluation {
21 
22 
23 
24 /**
25  * Evaluation using the streaming evaluation interface.
26  *
27  * \param[in] targets True values
28  * \param[in] prediction Predicted values
29  * \param[in] metric Name of the metric
30  * See unity/toolkit/evaluation/metrics.hpp.
31  */
32 variant_type _supervised_streaming_evaluator(
33  std::shared_ptr<unity_sarray> unity_targets,
34  std::shared_ptr<unity_sarray> unity_predictions,
35  std::string metric,
36  std::map<std::string, flexible_type> kwargs =
37  std::map<std::string, flexible_type>());
38 
39 /**
40  * Convenience API for computing several classifier metrics simultaneously.
41  *
42  * This function assumes that the class labels are available and that the
43  * default options for each metric suffice. It should be more efficient than
44  * multiple calls to _supervised_streaming_evaluator, insofar as this function
45  * computes the metrics in parallel and uses multiple threads.
46  *
47  * \param metrics The list of metrics to compute. Valid metrics include those
48  * supported by `get_evaluator_metric`, as well as
49  * "report_by_class".
50  * \param input SFrame containing the ground-truth labels and the predicted
51  * class probabilities.
52  * \param target_column_name The name of the column in `input` containing the
53  * ground-truth labels.
54  * \param prediction_probs_column_name The name of the column in `input`
55  * containing the predicted class
56  * probabilities.
57  * \param class_labels The class labels used when training the model being
58  * evaluated. Every prediction probability vector must have
59  * the same length as this list.
60  * \return A map from metric name to the output from the corresponding
61  * evaluation metric.
62  *
63  * \todo Factor out the logic shared with
64  * `supervised_learning_model_base::evaluate`. Compared to that version,
65  * this one requires that all the predictions have been written to an
66  * SArray.
67  */
68 variant_map_type compute_classifier_metrics_from_probability_vectors(
69  std::vector<std::string> metrics, gl_sframe input,
70  std::string target_column_name, std::string prediction_probs_column_name,
71  flex_list class_labels);
72 
73 variant_map_type compute_classifier_metrics(
74  gl_sframe data, std::string target_column_name, std::string metric,
75  gl_sarray predictions, std::map<std::string, flexible_type> opts);
76 
77 variant_map_type compute_object_detection_metrics(
78  gl_sframe data, std::string annotations_column_name,
79  std::string image_column_name, gl_sarray predictions,
80  std::map<std::string, flexible_type> opts);
81 
82 /**
83  * Computes the precision and recall for each user.
84  *
85  * \param validation_data An sframe object containing a user column
86  * and an item column.
87  * \param recommend_output An sframe representing a set of
88  * recommendations. The first column must contain user ids, the second must
89  * contain item ids. For each user, the item ids are expected to be sorted
90  * by importance. (Precision and recall values are sensitive to this ordering.
91  * \param cutoffs A set of cutoffs at which precision and recall should be
92  * computed.
93  * \return An SFrame containing columns for the user, the cutoff, and
94  * precision and recall values.
95  */
96 sframe precision_recall_by_user(
97  const sframe& validation_data,
98  const sframe& recommend_output,
99  const std::vector<size_t>& cutoffs);
100 
101 } // evaluation
102 } // turicreate
103 #endif
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
std::vector< flexible_type > flex_list