Skip to content

Commit

Permalink
Updated examples to use books themed data, removed output from predic…
Browse files Browse the repository at this point in the history
…t and train_predict API, fixed vale complaints.

Signed-off-by: Nathalie Jonathan <[email protected]>
  • Loading branch information
nathaliellenaa committed Dec 27, 2024
1 parent 3d7f92e commit 461e93a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 53 deletions.
2 changes: 1 addition & 1 deletion spec/schemas/ml._common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ components:
$ref: '#/components/schemas/BoolQuery'
BoolQuery:
type: object
description: The boolean query.
description: The Boolean query.
properties:
filter:
type: array
Expand Down
36 changes: 18 additions & 18 deletions tests/plugins/ml/train_predict/predict.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ prologues:
request:
content_type: application/x-ndjson
payload:
- {index: {_index: iris_data}}
- {sepal_length_in_cm: 5.1, sepal_width_in_cm: 3.5, petal_length_in_cm: 1.4, petal_width_in_cm: 0.2, species: setosa}
- {index: {_index: iris_data}}
- {sepal_length_in_cm: 4.9, sepal_width_in_cm: 3.1, petal_length_in_cm: 1.4, petal_width_in_cm: 0.2, species: setosa}
- {index: {_index: iris_data}}
- {sepal_length_in_cm: 4.7, sepal_width_in_cm: 3.2, petal_length_in_cm: 1.3, petal_width_in_cm: 0.2, species: setosa}
- {index: {_index: iris_data}}
- path: /iris_data/_refresh
- {index: {_index: books_data}}
- {pages: 320, price: 24.99, sales_first_month: 15000, average_rating: 4.5, publication_year: 2022}
- {index: {_index: books_data}}
- {pages: 450, price: 29.99, sales_first_month: 45000, average_rating: 4.8, publication_year: 2022}
- {index: {_index: books_data}}
- {pages: 280, price: 19.99, sales_first_month: 8000, average_rating: 3.9, publication_year: 2022}
- {index: {_index: books_data}}
- {pages: 380, price: 27.99, sales_first_month: 25000, average_rating: 4.2, publication_year: 2022}
- path: /books_data/_refresh
method: POST
- path: _plugins/_ml/_train/{algorithm_name}
id: train_model
Expand All @@ -33,11 +34,12 @@ prologues:
distance_type: COSINE
input_query:
_source:
- petal_length_in_cm
- petal_width_in_cm
- average_rating
- price
- sales_first_month
size: 10000
input_index:
- iris_data
- books_data
output:
model_id: payload.model_id
epilogues:
Expand All @@ -46,12 +48,11 @@ epilogues:
model_id: ${train_model.model_id}
method: DELETE
status: [200, 404]
- path: /iris_data
- path: /books_data
method: DELETE
status: [200, 404]
chapters:
- synopsis: Predict trained model.
id: predict_trained_model
path: /_plugins/_ml/_predict/{algorithm_name}/{model_id}
method: POST
parameters:
Expand All @@ -61,14 +62,13 @@ chapters:
payload:
input_query:
_source:
- petal_length_in_cm
- petal_width_in_cm
- average_rating
- price
- sales_first_month
size: 10000
input_index:
- iris_data
- books_data
response:
status: 200
payload:
status: COMPLETED
output:
prediction: payload.prediction_result
26 changes: 14 additions & 12 deletions tests/plugins/ml/train_predict/train.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,23 @@ prologues:
request:
content_type: application/x-ndjson
payload:
- {index: {_index: iris_data}}
- {sepal_length_in_cm: 5.1, sepal_width_in_cm: 3.5, petal_length_in_cm: 1.4, petal_width_in_cm: 0.2, species: setosa}
- {index: {_index: iris_data}}
- {sepal_length_in_cm: 4.9, sepal_width_in_cm: 3.1, petal_length_in_cm: 1.4, petal_width_in_cm: 0.2, species: setosa}
- {index: {_index: iris_data}}
- {sepal_length_in_cm: 4.7, sepal_width_in_cm: 3.2, petal_length_in_cm: 1.3, petal_width_in_cm: 0.2, species: setosa}
- {index: {_index: iris_data}}
- path: /iris_data/_refresh
- {index: {_index: books_data}}
- {pages: 320, price: 24.99, sales_first_month: 15000, average_rating: 4.5, publication_year: 2022}
- {index: {_index: books_data}}
- {pages: 450, price: 29.99, sales_first_month: 45000, average_rating: 4.8, publication_year: 2022}
- {index: {_index: books_data}}
- {pages: 280, price: 19.99, sales_first_month: 8000, average_rating: 3.9, publication_year: 2022}
- {index: {_index: books_data}}
- {pages: 380, price: 27.99, sales_first_month: 25000, average_rating: 4.2, publication_year: 2022}
- path: /books_data/_refresh
method: POST
epilogues:
- path: /_plugins/_ml/models/{model_id}
parameters:
model_id: ${train_model.model_id}
method: DELETE
status: [200, 404]
- path: /iris_data
- path: /books_data
method: DELETE
status: [200, 404]
chapters:
Expand All @@ -44,11 +45,12 @@ chapters:
distance_type: COSINE
input_query:
_source:
- petal_length_in_cm
- petal_width_in_cm
- average_rating
- price
- sales_first_month
size: 10000
input_index:
- iris_data
- books_data
response:
status: 200
payload:
Expand Down
40 changes: 18 additions & 22 deletions tests/plugins/ml/train_predict/train_and_predict.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@ prologues:
request:
content_type: application/x-ndjson
payload:
- {index: {_index: test_data}}
- {k1: 5.1, k2: 3.5, k3: 1.4}
- {index: {_index: test_data}}
- {k1: 4.9, k2: 3.1, k3: 1.4}
- {index: {_index: test_data}}
- {k1: 4.7, k2: 3.2, k3: 1.3}
- {index: {_index: test_data}}
- path: /test_data/_refresh
- {index: {_index: books_data}}
- {pages: 320, k1: 24.99, sales_first_month: 15000, average_rating: 4.5, publication_year: 2022}
- {index: {_index: books_data}}
- {pages: 450, k1: 29.99, sales_first_month: 45000, average_rating: 4.8, publication_year: 2022}
- {index: {_index: books_data}}
- {pages: 280, k1: 19.99, sales_first_month: 8000, average_rating: 3.9, publication_year: 2022}
- {index: {_index: books_data}}
- {pages: 380, k1: 27.99, sales_first_month: 25000, average_rating: 4.2, publication_year: 2022}
- path: /books_data/_refresh
method: POST
epilogues:
- path: /test_data
- path: /books_data
method: DELETE
status: [200, 404]
chapters:
Expand All @@ -43,17 +44,15 @@ chapters:
filter:
- range:
k1:
gte: 3.9
lte: 4.8
gte: 15.99
lte: 25.99
size: 10
input_index:
- test_data
- books_data
response:
status: 200
payload:
status: COMPLETED
output:
prediction: payload.prediction_result
- synopsis: Train and predict with data directly.
id: train_predict_model
path: /_plugins/_ml/_train_predict/{algorithm_name}
Expand All @@ -70,23 +69,20 @@ chapters:
column_metas:
- name: k1
column_type: DOUBLE
- name: k2
- name: average_rating
column_type: DOUBLE
rows:
- values:
- column_type: DOUBLE
value: 1.01
value: 24.99
- column_type: DOUBLE
value: 2.01
value: 29.99
- values:
- column_type: DOUBLE
value: 3.01
value: 4.5
- column_type: DOUBLE
value: 4.01
value: 4.8
response:
status: 200
payload:
status: COMPLETED
output:
prediction: payload.prediction_result

0 comments on commit 461e93a

Please sign in to comment.