Skip to content

Commit 033aa9c

Browse files
committed
[DOCS] Adds examples to the PUT dfa and the evaluate dfa APIs (#46966)
* [DOCS] Adds examples to the PUT dfa and the evaluate dfa APIs. * [DOCS] Removes extra lines from examples. * Update docs/reference/ml/df-analytics/apis/evaluate-dfanalytics.asciidoc Co-Authored-By: Lisa Cawley <[email protected]> * Update docs/reference/ml/df-analytics/apis/put-dfanalytics.asciidoc Co-Authored-By: Lisa Cawley <[email protected]> * [DOCS] Explains examples.
1 parent 7739938 commit 033aa9c

File tree

2 files changed

+105
-2
lines changed

2 files changed

+105
-2
lines changed

docs/reference/ml/df-analytics/apis/evaluate-dfanalytics.asciidoc

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,79 @@ only.
172172
<3> The ground truth value for the actual house price. This is required in order
173173
to evaluate results.
174174
<4> The predicted value for house price calculated by the {reganalysis}.
175+
176+
177+
The following example calculates the training error:
178+
179+
[source,console]
180+
--------------------------------------------------
181+
POST _ml/data_frame/_evaluate
182+
{
183+
"index": "student_performance_mathematics_reg",
184+
"query": {
185+
"term": {
186+
"ml.is_training": {
187+
"value": true <1>
188+
}
189+
}
190+
},
191+
"evaluation": {
192+
"regression": {
193+
"actual_field": "G3", <2>
194+
"predicted_field": "ml.G3_prediction", <3>
195+
"metrics": {
196+
"r_squared": {},
197+
"mean_squared_error": {}
198+
}
199+
}
200+
}
201+
}
202+
--------------------------------------------------
203+
// TEST[skip:TBD]
204+
205+
<1> In this example, a test/train split (`training_percent`) was defined for the
206+
{reganalysis}. This query limits evaluation to be performed on the train split
207+
only. It means that a training error will be calculated.
208+
<2> The field that contains the ground truth value for the actual student
209+
performance. This is required in order to evaluate results.
210+
<3> The field that contains the predicted value for student performance
211+
calculated by the {reganalysis}.
212+
213+
214+
The next example calculates the testing error. The only difference compared with
215+
the previous example is that `ml.is_training` is set to `false` this time, so
216+
the query excludes the train split from the evaluation.
217+
218+
[source,console]
219+
--------------------------------------------------
220+
POST _ml/data_frame/_evaluate
221+
{
222+
"index": "student_performance_mathematics_reg",
223+
"query": {
224+
"term": {
225+
"ml.is_training": {
226+
"value": false <1>
227+
}
228+
}
229+
},
230+
"evaluation": {
231+
"regression": {
232+
"actual_field": "G3", <2>
233+
"predicted_field": "ml.G3_prediction", <3>
234+
"metrics": {
235+
"r_squared": {},
236+
"mean_squared_error": {}
237+
}
238+
}
239+
}
240+
}
241+
--------------------------------------------------
242+
// TEST[skip:TBD]
243+
244+
<1> In this example, a test/train split (`training_percent`) was defined for the
245+
{reganalysis}. This query limits evaluation to be performed on the test split
246+
only. It means that a testing error will be calculated.
247+
<2> The field that contains the ground truth value for the actual student
248+
performance. This is required in order to evaluate results.
249+
<3> The field that contains the predicted value for student performance
250+
calculated by the {reganalysis}.

docs/reference/ml/df-analytics/apis/put-dfanalytics.asciidoc

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ The API returns the following result:
179179

180180

181181
[[ml-put-dfanalytics-example-r]]
182-
===== {regression-cap} example
182+
===== {regression-cap} examples
183183

184184
The following example creates the `house_price_regression_analysis`
185185
{dfanalytics-job}, the analysis type is `regression`:
@@ -235,4 +235,31 @@ The API returns the following result:
235235
}
236236
----
237237
// TESTRESPONSE[s/1567168659127/$body.$_path/]
238-
// TESTRESPONSE[s/"version": "8.0.0"/"version": $body.version/]
238+
// TESTRESPONSE[s/"version": "8.0.0"/"version": $body.version/]
239+
240+
241+
The following example creates a job and specifies a training percent:
242+
243+
[source,console]
244+
--------------------------------------------------
245+
PUT _ml/data_frame/analytics/student_performance_mathematics_0.3
246+
{
247+
"source": {
248+
"index": "student_performance_mathematics"
249+
},
250+
"dest": {
251+
"index":"student_performance_mathematics_reg"
252+
},
253+
"analysis":
254+
{
255+
"regression": {
256+
"dependent_variable": "G3",
257+
"training_percent": 70 <1>
258+
}
259+
}
260+
}
261+
--------------------------------------------------
262+
// TEST[skip:TBD]
263+
264+
<1> The `training_percent` defines the percentage of the data set that will be used
265+
for training the model.

0 commit comments

Comments
 (0)