model_id = "88"

# Get the various Model CRN details
HOST = os.getenv("CDSW_API_URL").split(":")[0] + "://" + os.getenv(
    "CDSW_DOMAIN")
USERNAME = os.getenv("CDSW_PROJECT_URL").split("/")[
    6]  # args.username  # "vdibia"
API_KEY = os.getenv("CDSW_API_KEY")
PROJECT_NAME = os.getenv("CDSW_PROJECT")

cml = CMLBootstrap(HOST, USERNAME, API_KEY, PROJECT_NAME)

latest_model = cml.get_model({
    "id": model_id,
    "latestModelDeployment": True,
    "latestModelBuild": True
})

Model_CRN = latest_model["crn"]
Deployment_CRN = latest_model["latestModelDeployment"]["crn"]

# Read in the model metrics dict.
model_metrics = cdsw.read_metrics(model_crn=Model_CRN,
                                  model_deployment_crn=Deployment_CRN)

# This is a handy way to unravel the dict into a big pandas dataframe.
metrics_df = pd.io.json.json_normalize(
    model_metrics["metrics"])  # [metric_start_index:])
metrics_df.tail().T
Example #2
0
    "memoryMb":
    2048,
    "nvidiaGPUs":
    0,
    "replicationPolicy": {
        "type": "fixed",
        "numReplicas": 1
    },
    "environment": {}
}

new_model_details = cml.create_model(create_model_params)
access_key = new_model_details["accessKey"]  # todo check for bad response
print("New model created with access key", access_key)

# Wait for the model to deploy.
is_deployed = False
while is_deployed == False:
    model = cml.get_model({
        "id": str(new_model_details["id"]),
        "latestModelDeployment": True,
        "latestModelBuild": True
    })
    if model["latestModelDeployment"]["status"] == 'deployed':
        print("Model is deployed")
        break
    else:
        print("Model deployment status .....",
              model["latestModelDeployment"]["status"])
        time.sleep(10)
Example #3
0
USERNAME = os.getenv("CDSW_PROJECT_URL").split("/")[6]
API_KEY = os.getenv("CDSW_API_KEY")
PROJECT_NAME = os.getenv("CDSW_PROJECT")

cml = CMLBootstrap(HOST, USERNAME, API_KEY, PROJECT_NAME)

# Get newly deployed churn model details using cmlbootstrapAPI
models = cml.get_models({})
churn_model_details = [
    model for model in models
    if model["name"] == "Churn Model API Endpoint" and model["creator"]
    ["username"] == USERNAME and model["project"]["slug"] == PROJECT_NAME
][0]
latest_model = cml.get_model({
    "id": churn_model_details["id"],
    "latestModelDeployment": True,
    "latestModelBuild": True,
})

Model_CRN = latest_model["crn"]
Deployment_CRN = latest_model["latestModelDeployment"]["crn"]
model_endpoint = (HOST.split("//")[0] + "//modelservice." +
                  HOST.split("//")[1] + "/model")


# This will randomly return True for input and increases the likelihood of returning
# true based on `percent`
def churn_error(item, percent):
    if random.random() < percent:
        return True
    else: