<jupyter_start><jupyter_text>Use scikit-learn to predict diabetes progression with Watson Machine Learning REST API This notebook contains steps and code to demonstrate support of external machine learning models in Watson Machine Learning Service. This notebook introduces `cURL` calls for publishing, deploying (Web Service) and scoring ML scikit model.Some familiarity with cURL is helpful. This notebook uses cURL examples.This example was made based on `diabetes` dataset and trained scikit ML model that could be found inside the same repository under as follows: - `/data/diabetes/`- `/models/scikit/diabetes/` Learning goalsThe learning goals of this notebook are:-  Working with Watson Machine Learning repository, deployment and scoring. ContentsThis notebook contains the following parts:1.	[Setup](setup)  2.	[WML Repository](wml_repository)   3.	[Model Deployment and Scoring](deploy_and_score)   4.  [Persist new version of the model](update_model)5.  [Redeploy and score new version of the model](redeploy)6.	[Cleaning](cleaning)  7.	[Summary](summary)    1. Set up the environmentBefore you use the sample code in this notebook, you must perform the following setup tasks:-  Contact with your Cloud Pack for Data administrator and ask him for your account credentials  Connection to WMLAuthenticate the Watson Machine Learning service on IBM Cloud Pack for Data. You need to provide platform `url`, your `username` and `password`.<jupyter_code>%env USERNAME=
%env PASSWORD=
%env DATAPLATFORM_URL=

%env SPACE_ID=<jupyter_output><empty_output><jupyter_text>Getting WML authorization token for further cURL calls Example of cURL call to get WML token<jupyter_code>%%bash --out token

curl -sk -X GET \
    --user $USERNAME:$PASSWORD \
    --header "Accept: application/json" \
    "$DATAPLATFORM_URL/v1/preauth/validateAuth" \
    | cut -d '"' -f 44
%env TOKEN=$token<jupyter_output>env: TOKEN=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwicm9sZSI6IkFkbWluIiwicGVybWlzc2lvbnMiOlsiYWRtaW5pc3RyYXRvciIsImNhbl9wcm92aXNpb24iLCJtYW5hZ2VfY2F0YWxvZyIsImFjY2Vzc19jYXRhbG9nIl0sImdyb3VwcyI6WzEwMDAwXSwic3ViIjoiYWRtaW4iLCJpc3MiOiJLTk9YU1NPIiwiYXVkIjoiRFNYIiwidWlkIjoiMTAwMDMzMDk5OSIsImF1dGhlbnRpY2F0b3IiOiJkZWZhdWx0IiwiaWF0IjoxNjA3NDM1ODE2LCJleHAiOjE2MDc0Nzg5ODB9.MGVWAw21zCtckxVBjRWcKcJyjWlGnPEvR_D1S5zgNx3gsKGlww0mH5cnJyhbTKlGF2bb-Rdi3Kp3ZrJ7FqMutnef_9CoS02tm-KTKUWRnMXc9mcFobjS3mjzTq99ssFCaPMgwBTlrKQe7UfFzS346p199lAbEmed43tVDGkDbykvSKkyMT5ILoGWdfjCquXEtqiIczGpWTjcCgKa6k9Pkj3bG7lAMO-ny2G3tl25CMbVRkBYXfYNmQG7mJ0_y85ER2qx-T712ehdH8Jx-4t9MhhBpgr78KaaQbFJLOBEDxKJElTrRAzBlb6EIfi6wO7EesuGBO_J2jYfUrEkANurmA<jupyter_text>Space creation**Tip:** If you do not have `space` already created, please convert below three cells to `code` and run them.First of all, you need to create a `space` that will be used in all of your further cURL calls. If you do not have `space` already created, below is the cURL call to create one. <a href="https://cpd-spaces-api.eu-gb.cf.appdomain.cloud//Spaces/spaces_create" target="_blank" rel="noopener no referrer">Space creation<jupyter_code>%%bash --out space_id

curl -sk -X POST \
    --header "Authorization: Bearer $TOKEN" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data '{"name": "curl_DL"}' \
    "$DATAPLATFORM_URL/v2/spaces" \
     | grep '"id": ' | awk -F '"' '{ print $4 }'
space_id = space_id.split('\n')[1]
%env SPACE_ID=$space_id<jupyter_output><empty_output><jupyter_text>Space creation is asynchronous. This means that you need to check space creation status after creation call.Make sure that your newly created space is `active`. <a href="https://cpd-spaces-api.eu-gb.cf.appdomain.cloud//Spaces/spaces_get" target="_blank" rel="noopener no referrer">Get space information<jupyter_code>%%bash

curl -sk -X GET \
    --header "Authorization: Bearer $TOKEN" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    "$DATAPLATFORM_URL/v2/spaces/$SPACE_ID"<jupyter_output><empty_output><jupyter_text>---  2. Manage WML RepositoryIn this section you will learn how to upload your ML model, list your models stored in repository, delete your model and update it.  Model storingStore information about your model to WML repository. <a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html/Models/models_create" target="_blank" rel="noopener no referrer">Model storing<jupyter_code>%%bash --out model_payload

MODEL_PAYLOAD='{"space_id": "'"$SPACE_ID"'","name": "scikit_diabetes_model","description": "This is description","type": "scikit-learn_0.23", "software_spec": {"name": "default_py3.7"}}'
echo $MODEL_PAYLOAD | python -m json.tool
%env MODEL_PAYLOAD=$model_payload
%%bash --out model_id -s "$model_payload"

curl -sk -X POST \
    --header "Authorization: Bearer $TOKEN" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data "$MODEL_PAYLOAD" \
    "$DATAPLATFORM_URL/ml/v4/models?version=2020-08-01" | grep '"id": ' | awk -F '"' '{ print $4 }' | sed -n 2p
%env MODEL_ID=$model_id<jupyter_output>env: MODEL_ID=7b69ff44-f158-4125-a41e-ae2eb48feee5<jupyter_text>Create model revision for further update <a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html/Models/models_create_revision" target="_blank" rel="noopener no referrer">Model revision<jupyter_code>%%bash --out revision_payload

REVISION_PAYLOAD='{"space_id": "'"$SPACE_ID"'", "commit_message": "Initial model."}'
echo $REVISION_PAYLOAD | python -m json.tool
%env REVISION_PAYLOAD=$revision_payload
%%bash

curl -sk -X POST \
    --header "Authorization: Bearer $TOKEN" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data "$REVISION_PAYLOAD" \
    "$DATAPLATFORM_URL/ml/v4/models/$MODEL_ID/revisions?version=2020-08-01" \
    | python -m json.tool<jupyter_output>{
    "entity": {
        "software_spec": {
            "id": "e4429883-c883-42b6-87a8-f419d64088cd",
            "name": "default_py3.7"
        },
        "type": "scikit-learn_0.23"
    },
    "metadata": {
        "commit_info": {
            "commit_message": "Initial model.",
            "committed_at": "2020-12-08T13:57:12.002Z"
        },
        "created_at": "2020-12-08T13:57:03.381Z",
        "description": "This is description",
        "id": "7b69ff44-f158-4125-a41e-ae2eb48feee5",
        "modified_at": "2020-12-08T13:57:03.381Z",
        "name": "scikit_diabetes_model",
        "owner": "1000330999",
        "rev": "1",
        "space_id": "cc59083a-923f-4c35-8947-10c126343bd0"
    },
    "system": {
        "warnings": []
    }
}<jupyter_text>Model content uploadNow you need to upload your model content into the WML repository.<jupyter_code>!wget https://github.com/IBM/watson-machine-learning-samples/raw/master/cpd3.5/models/scikit/diabetes/model/diabetes_model.tar.gz \
    -O diabetes_model.tar.gz<jupyter_output>--2020-12-08 14:57:14--  https://github.com/IBM/watson-machine-learning-samples/raw/master/cpd3.5/models/scikit/diabetes/model/diabetes_model.tar.gz
Resolving github.com... 172.16.17.32
Connecting to github.com|172.16.17.32|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://raw.githubusercontent.com/IBM/watson-machine-learning-samples/master/cpd3.5/models/scikit/diabetes/model/diabetes_model.tar.gz [following]
--2020-12-08 14:57:15--  https://raw.githubusercontent.com/IBM/watson-machine-learning-samples/master/cpd3.5/models/scikit/diabetes/model/diabetes_model.tar.gz
Resolving raw.githubusercontent.com... 192.168.127.12, 192.168.3.11, 192.168.127.12, ...
Connecting to raw.githubusercontent.com|192.168.127.12|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5322360 (5.1M) [application/octet-stream]
Saving to: 'diabetes_model.tar.gz'

diabetes_model.tar. 100%[===================>]   5.08M  1.22MB/s    in 4.5s    

2020-12-08 1[...]<jupyter_text><a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html/Models/models_upload_content" target="_blank" rel="noopener no referrer">Upload model content<jupyter_code>%%bash --out attachment_id

curl -sk -X PUT \
    --header "Authorization: Bearer $TOKEN" \
    --header "Content-Type: application/gzip" \
    --header "Accept: application/json" \
    --data-binary "@diabetes_model.tar.gz" \
    "$DATAPLATFORM_URL/ml/v4/models/$MODEL_ID/content?space_id=$SPACE_ID&version=2020-08-01&content_format=native" \
    | grep "attachment_id" | awk -F '"' '{ print $4 }'
%env ATTACHMENT_ID=$attachment_id<jupyter_output>env: ATTACHMENT_ID=28d7104a-c08a-445b-8953-770cb6a65a8c<jupyter_text>Download modelIf you want to download your saved model, please make the following call. <a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html/Models/models_filtered_download" target="_blank" rel="noopener no referrer">Download model content<jupyter_code>%%bash

curl -sk -X GET \
    --header "Authorization: Bearer $TOKEN" \
    --output "model.tar.gz" \
    "$DATAPLATFORM_URL/ml/v4/models/$MODEL_ID/download?space_id=$SPACE_ID&version=2020-08-01"
!ls -l model.tar.gz<jupyter_output>-rw-r--r--  1 jansoltysik  staff  5322360 Dec  8 14:57 model.tar.gz<jupyter_text>3. Deploy and ScoreIn this section you will learn how to deploy and score pipeline model as webservice using WML instance.  Deployment creationThis example uses scikit-learn model deployment and `S` hardware specification. <a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html/Deployments/deployments_create" target="_blank" rel="noopener no referrer">Create deployment<jupyter_code>%%bash --out deployment_payload

DEPLOYMENT_PAYLOAD='{"space_id": "'"$SPACE_ID"'","name": "Diabetes deployment", "description": "This is description","online": {},"hardware_spec": {"name": "S"},"asset": {"id": "'"$MODEL_ID"'"}}'
echo $DEPLOYMENT_PAYLOAD | python -m json.tool 
%env DEPLOYMENT_PAYLOAD=$deployment_payload
%%bash --out deployment_id

curl -sk -X POST \
    --header "Authorization: Bearer $TOKEN" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data "$DEPLOYMENT_PAYLOAD" \
    "$DATAPLATFORM_URL/ml/v4/deployments?version=2020-08-01" | grep '"id": ' | awk -F '"' '{ print $4 }' | sed -n 3p
%env DEPLOYMENT_ID=$deployment_id<jupyter_output>env: DEPLOYMENT_ID=714bfc1b-08a8-460f-8523-f61341280591<jupyter_text>Get deployment detailsAs deployment API is asynchronous, please make sure your deployment is in `ready` state before going to the next points. <a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html/Deployments/deployments_get" target="_blank" rel="noopener no referrer">Get deployment details<jupyter_code>%%bash

curl -sk -X GET \
    --header "Authorization: Bearer $TOKEN" \
    --header "Content-Type: application/json" \
    "$DATAPLATFORM_URL/ml/v4/deployments/$DEPLOYMENT_ID?space_id=$SPACE_ID&version=2020-08-01" \
    | python -m json.tool<jupyter_output>{
    "entity": {
        "asset": {
            "id": "7b69ff44-f158-4125-a41e-ae2eb48feee5"
        },
        "custom": {},
        "deployed_asset_type": "model",
        "description": "This is description",
        "hardware_spec": {
            "id": "e7ed1d6c-2e89-42d7-aed5-863b972c1d2b",
            "name": "S",
            "num_nodes": 1
        },
        "name": "<NAME>",
        "online": {},
        "space_id": "cc59083a-923f-4c35-8947-10c126343bd0",
        "status": {
            "online_url": {
                "url": "https://wmlgmc-cpd-wmlgmc.apps.wmlautoai.cp.fyre.ibm.com/ml/v4/deployments/714bfc1b-08a8-460f-8523-f61341280591/predictions"
            },
            "state": "initializing"
        }
    },
    "metadata": {
        "created_at": "2020-12-08T13:57:56.804Z",
        "description": "This is description",
        "id": "714bfc1b-08a8-460f-8523-f61341280591",
        "modified_at": "2020-12-08T13:57:56.804Z",
        "name": "Diabetes deployme[...]<jupyter_text>Scoring of a webserviceIf you want to make a `score` call on your deployment, please follow a below method: <a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html/Deployments/deployments_compute_predictions" target="_blank" rel="noopener no referrer">Score your deployment<jupyter_code>%%bash --out scoring_payload

SCORING_PAYLOAD='{"space_id": "$SPACE_ID","input_data": [{"fields": ["age", "sex", "bmi", "bp", "s1", "s2", "s3", "s4", "s5", "s6"], "values": [[-0.00188201652779104, -0.044641636506989, -0.0514740612388061, -0.0263278347173518, -0.00844872411121698, -0.019163339748222, 0.0744115640787594, -0.0394933828740919, -0.0683297436244215, -0.09220404962683], [0.0852989062966783, 0.0506801187398187, 0.0444512133365941, -0.00567061055493425, -0.0455994512826475, -0.0341944659141195, -0.0323559322397657, -0.00259226199818282, 0.00286377051894013, -0.0259303389894746]]}]}'
echo $SCORING_PAYLOAD | python -m json.tool
%env SCORING_PAYLOAD=$scoring_payload
%%bash

curl -sk -X POST \
    --header "Authorization: Bearer $TOKEN" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data "$SCORING_PAYLOAD"\
    "$DATAPLATFORM_URL/ml/v4/deployments/$DEPLOYMENT_ID/predictions?version=2020-08-01" \
    | python -m json.tool<jupyter_output>{
    "predictions": [
        {
            "fields": [
                "prediction"
            ],
            "values": [
                [
                    82.3468335692293
                ],
                [
                    168.2544647515973
                ]
            ]
        }
    ]
}<jupyter_text>Listing all deployments <a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html/Deployments/deployments_list" target="_blank" rel="noopener no referrer">List deployments details<jupyter_code>%%bash

curl -sk -X GET \
    --header "Authorization: Bearer $TOKEN" \
    --header "Content-Type: application/json" \
    "$DATAPLATFORM_URL/ml/v4/deployments?space_id=$SPACE_ID&version=2020-08-01" \
    | python -m json.tool<jupyter_output><empty_output><jupyter_text>4. Persist new version of the model In this section, you'll learn how to store new version of your model in Watson Machine Learning repository.  Model updateBelow you can find how ML model can be updated with new version on WML repository. List model revisions. <a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html/Models/models_list_revisions" target="_blank" rel="noopener no referrer">List revisions<jupyter_code>%%bash

curl -sk -X GET \
    --header "Authorization: Bearer $TOKEN" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    "$DATAPLATFORM_URL/ml/v4/models/$MODEL_ID/revisions?space_id=$SPACE_ID&version=2020-08-01" \
    | python -m json.tool<jupyter_output>{
    "first": {
        "href": "/ml/v4/models/7b69ff44-f158-4125-a41e-ae2eb48feee5/revisions?space_id=cc59083a-923f-4c35-8947-10c126343bd0&limit=100"
    },
    "limit": 100,
    "resources": [
        {
            "metadata": {
                "commit_info": {
                    "commit_message": "Initial model.",
                    "committed_at": "2020-12-08T13:57:12.002Z"
                },
                "created_at": "2020-12-08T13:57:03.381Z",
                "description": "This is description",
                "id": "7b69ff44-f158-4125-a41e-ae2eb48feee5",
                "modified_at": "2020-12-08T13:57:03.381Z",
                "name": "scikit_diabetes_model",
                "owner": "1000330999",
                "rev": "1",
                "space_id": "cc59083a-923f-4c35-8947-10c126343bd0"
            }
        }
    ]
}<jupyter_text>Create second model revision <a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html/Models/models_create_revision" target="_blank" rel="noopener no referrer">Create model revision<jupyter_code>%%bash --out revision_payload

REVISION_PAYLOAD='{"space_id": "'"$SPACE_ID"'", "commit_message": "Updated model."}'
echo $REVISION_PAYLOAD | python -m json.tool
%env REVISION_PAYLOAD=$revision_payload
%%bash

curl -sk -X POST \
    --header "Authorization: Bearer $TOKEN" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data "$REVISION_PAYLOAD" \
    "$DATAPLATFORM_URL/ml/v4/models/$MODEL_ID/revisions?version=2020-08-01" \
    | python -m json.tool<jupyter_output>{
    "entity": {
        "software_spec": {
            "id": "e4429883-c883-42b6-87a8-f419d64088cd",
            "name": "default_py3.7"
        },
        "type": "scikit-learn_0.23"
    },
    "metadata": {
        "commit_info": {
            "commit_message": "Updated model.",
            "committed_at": "2020-12-08T13:58:53.002Z"
        },
        "created_at": "2020-12-08T13:57:03.381Z",
        "description": "This is description",
        "id": "7b69ff44-f158-4125-a41e-ae2eb48feee5",
        "modified_at": "2020-12-08T13:57:44.839Z",
        "name": "scikit_diabetes_model",
        "owner": "1000330999",
        "rev": "2",
        "space_id": "cc59083a-923f-4c35-8947-10c126343bd0"
    },
    "system": {
        "warnings": []
    }
}<jupyter_text>Update model metadata    For example update  model name or description <a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html/Models/models_update" target="_blank" rel="noopener no referrer">Patch model<jupyter_code>%%bash --out update_payload

echo '[{"op": "add", "path": "/name", "value": "updated scikit model"}]' | python -m json.tool
%env UPDATE_PAYLOAD=$update_payload
%%bash

curl -sk -X PATCH \
    --header "Authorization: Bearer $TOKEN" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data "$UPDATE_PAYLOAD" \
    "$DATAPLATFORM_URL/ml/v4/models/$MODEL_ID?space_id=$SPACE_ID&version=2020-08-01" \
    | python -m json.tool<jupyter_output>{
    "entity": {
        "software_spec": {
            "id": "e4429883-c883-42b6-87a8-f419d64088cd",
            "name": "default_py3.7"
        },
        "type": "scikit-learn_0.23"
    },
    "metadata": {
        "commit_info": {
            "committed_at": "2020-12-08T13:58:55.790Z"
        },
        "created_at": "2020-12-08T13:57:03.381Z",
        "description": "This is description",
        "id": "7b69ff44-f158-4125-a41e-ae2eb48feee5",
        "modified_at": "2020-12-08T13:58:55.732Z",
        "name": "updated scikit model",
        "owner": "1000330999",
        "space_id": "cc59083a-923f-4c35-8947-10c126343bd0"
    },
    "system": {
        "warnings": []
    }
}<jupyter_text>Upload new model content<jupyter_code>!wget https://github.com/IBM/watson-machine-learning-samples/raw/master/cpd3.5/models/scikit/diabetes/model/new_diabetes_model.tar.gz \
    -O new_diabetes_model.tar.gz<jupyter_output>--2020-12-08 14:58:57--  https://github.com/IBM/watson-machine-learning-samples/raw/master/cpd3.5/models/scikit/diabetes/model/new_diabetes_model.tar.gz
Resolving github.com... 172.16.17.32
Connecting to github.com|172.16.17.32|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://raw.githubusercontent.com/IBM/watson-machine-learning-samples/master/cpd3.5/models/scikit/diabetes/model/new_diabetes_model.tar.gz [following]
--2020-12-08 14:58:57--  https://raw.githubusercontent.com/IBM/watson-machine-learning-samples/master/cpd3.5/models/scikit/diabetes/model/new_diabetes_model.tar.gz
Resolving raw.githubusercontent.com... 192.168.127.12, 172.16.31.10, 192.168.127.12, ...
Connecting to raw.githubusercontent.com|151.101.128.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5325282 (5.1M) [application/octet-stream]
Saving to: 'new_diabetes_model.tar.gz'

new_diabetes_model. 100%[===================>]   5.08M  2.52MB/s    in 2.0[...]<jupyter_text><a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html/Models/models_upload_content" target="_blank" rel="noopener no referrer">Upload model content<jupyter_code>%%bash

curl -sk -X PUT \
    --header "Authorization: Bearer $TOKEN" \
    --header "Content-Type: application/gzip" \
    --header "Accept: application/json" \
    --data-binary "@new_diabetes_model.tar.gz" \
    "$DATAPLATFORM_URL/ml/v4/models/$MODEL_ID/content?space_id=$SPACE_ID&version=2020-08-01&content_format=native" \
    | python -m json.tool<jupyter_output>{
    "attachment_id": "cd44da87-dbe6-49ab-ae57-1952ea3a4ebf",
    "content_format": "native",
    "persisted": true
}<jupyter_text>List model revisions to see a new one just created <a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html/Models/models_list_revisions" target="_blank" rel="noopener no referrer">List revisions<jupyter_code>%%bash

curl -sk -X GET \
    --header "Authorization: Bearer $TOKEN" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    "$DATAPLATFORM_URL/ml/v4/models/$MODEL_ID/revisions?space_id=$SPACE_ID&version=2020-08-01" \
    | python -m json.tool<jupyter_output>{
    "first": {
        "href": "/ml/v4/models/7b69ff44-f158-4125-a41e-ae2eb48feee5/revisions?space_id=cc59083a-923f-4c35-8947-10c126343bd0&limit=100"
    },
    "limit": 100,
    "resources": [
        {
            "metadata": {
                "commit_info": {
                    "commit_message": "Updated model.",
                    "committed_at": "2020-12-08T13:58:53.002Z"
                },
                "created_at": "2020-12-08T13:57:03.381Z",
                "description": "This is description",
                "id": "7b69ff44-f158-4125-a41e-ae2eb48feee5",
                "modified_at": "2020-12-08T13:57:44.839Z",
                "name": "scikit_diabetes_model",
                "owner": "1000330999",
                "rev": "2",
                "space_id": "cc59083a-923f-4c35-8947-10c126343bd0"
            }
        },
        {
            "metadata": {
                "commit_info": {
                    "commit_message": "Initial model.",
                    "committed_[...]<jupyter_text>Now we have updated model content and model name in repository. <a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html/Models/models_get" target="_blank" rel="noopener no referrer">Get model details<jupyter_code>%%bash

curl -sk -X GET \
    --header "Authorization: Bearer $TOKEN" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    "$DATAPLATFORM_URL/ml/v4/models/$MODEL_ID?space_id=$SPACE_ID&version=2020-08-01" \
    | python -m json.tool<jupyter_output>{
    "entity": {
        "software_spec": {
            "id": "e4429883-c883-42b6-87a8-f419d64088cd",
            "name": "default_py3.7"
        },
        "type": "scikit-learn_0.23"
    },
    "metadata": {
        "commit_info": {
            "committed_at": "2020-12-08T13:59:20.232Z"
        },
        "created_at": "2020-12-08T13:57:03.381Z",
        "description": "This is description",
        "id": "7b69ff44-f158-4125-a41e-ae2eb48feee5",
        "modified_at": "2020-12-08T13:59:18.152Z",
        "name": "updated scikit model",
        "owner": "1000330999",
        "space_id": "cc59083a-923f-4c35-8947-10c126343bd0"
    },
    "system": {
        "warnings": []
    }
}<jupyter_text>5. Redeploy and score new version of the model Below you can see how deployment can be updated with new version of the model without any change for scoring url. <a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html/Deployments/deployments_update" target="_blank" rel="noopener no referrer">Deployment update<jupyter_code>%%bash --out redeploy_payload

echo '[{"op": "replace", "path": "/asset", "value": {"id": "'"$MODEL_ID"'"}}]' \
     | python -m json.tool
%env REDEPLOY_PAYLOAD=$redeploy_payload
%%bash

curl -sk -X PATCH \
    --header "Authorization: Bearer $TOKEN" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data "$REDEPLOY_PAYLOAD" \
    "$DATAPLATFORM_URL/ml/v4/deployments/$DEPLOYMENT_ID?space_id=$SPACE_ID&version=2020-08-01" \
    | python -m json.tool<jupyter_output>{
    "entity": {
        "asset": {
            "id": "7b69ff44-f158-4125-a41e-ae2eb48feee5"
        },
        "custom": {},
        "deployed_asset_type": "model",
        "description": "This is description",
        "hardware_spec": {
            "id": "Not_Applicable",
            "name": "S",
            "num_nodes": 1
        },
        "name": "Diabetes deployment",
        "online": {},
        "space_id": "cc59083a-923f-4c35-8947-10c126343bd0",
        "status": {
            "online_url": {
                "url": "https://wmlgmc-cpd-wmlgmc.apps.wmlautoai.cp.fyre.ibm.com/ml/v4/deployments/714bfc1b-08a8-460f-8523-f61341280591/predictions"
            },
            "state": "ready"
        }
    },
    "metadata": {
        "created_at": "2020-12-08T13:57:56.804Z",
        "description": "This is description",
        "id": "714bfc1b-08a8-460f-8523-f61341280591",
        "modified_at": "2020-12-08T13:59:21.262Z",
        "name": "Diabetes deployment",
        "owner": "100033[...]<jupyter_text>Score updated webservice<jupyter_code>%%bash

curl -sk -X POST \
    --header "Authorization: Bearer $TOKEN" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data "$SCORING_PAYLOAD" \
    "$DATAPLATFORM_URL/ml/v4/deployments/$DEPLOYMENT_ID/predictions?version=2020-08-01" \
    | python -m json.tool<jupyter_output>{
    "predictions": [
        {
            "fields": [
                "prediction"
            ],
            "values": [
                [
                    82.3468335692293
                ],
                [
                    168.2544647515973
                ]
            ]
        }
    ]
}<jupyter_text>6. Cleaning sectionBelow section is useful when you want to clean all of your previous work within this notebook.Just convert below cells into the `code` and run them.  Deleting deployment**Tip:** You can delete existing deployment by calling DELETE method.<jupyter_code>%%bash

curl -sk -X DELETE \
    --header "Authorization: Bearer $TOKEN" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    "$DATAPLATFORM_URL/ml/v4/deployments/$DEPLOYMENT_ID?space_id=$SPACE_ID&version=2020-08-01"<jupyter_output><empty_output><jupyter_text>Delete model from repository**Tip:** If you want to completely remove your stored model and model metadata, just use a DELETE method. <a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html/Models/models_delete" target="_blank" rel="noopener no referrer">Delete model from repository<jupyter_code>%%bash

curl -sk -X DELETE \
    --header "Authorization: Bearer $TOKEN" \
    --header "Content-Type: application/json" \
    "$DATAPLATFORM_URL/ml/v4/models/$MODEL_ID?space_id=$SPACE_ID&version=2020-08-01"<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14611905997479427, 'fraction_numerical': 0.081251390021499, 'mean_word_length': 3.3535581733096658, 'pattern_counts': {'":': 196, '<': 98, '<?xml version=': 0, '>': 100, 'https://': 28, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 12, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '24', 'dir': 'jupyter-structured-clean-dedup', 'id': '159928', 'license': 'Apache-2.0', 'n_tokens_mistral': 11303, 'n_tokens_neox': 9895, 'n_words': 1737, 'path': 'cpd3.5/notebooks/rest_api/curl/deployments/scikit/Use scikit-learn to predict diabetes progression.ipynb', 'repo_name': 'ThoughtVector/watson-machine-learning-samples', 'size': '26995'}