Watson Studio

 View Only

Deployment creation failed - Sklearn

  • 1.  Deployment creation failed - Sklearn

    Posted Mon November 14, 2022 09:37 AM

    I  am trying to deploy the scikit learn model in watson - ML, in Python

    but i got this error

    Deployment creation failed

    Model loading through joblib failed with exception: KeyError and message: 0. The model object provided for deployment is either invalid or trained using a version of scikit-learn other than: 1.0

    Versions : Python - 3.9.15, scikit-learn - 1.0

    code

        model = RandomForestClassifier(n_estimators=69, class_weight='balanced')
        model.fit(x_train, y_train)
    
        watson_cred = {
                        "apikey":"...",
                        "url":"https://eu-gb.ml.cloud.ibm.com",
                        }
    
        client = APIClient(watson_cred)
        client.set.default_space(space_id)
    
        software_spec_uid = client.software_specifications.get_id_by_name('runtime-22.1-py3.9')
    
    
        model_properties = {
                            client.repository.ModelMetaNames.NAME: model_name,
                            client.repository.ModelMetaNames.TYPE: 'scikit-learn_1.0',
                            client.repository.ModelMetaNames.SOFTWARE_SPEC_UID: software_spec_uid,
                            }
    
        model_details = client.repository.store_model(
                        model=model,
                        meta_props=model_properties,
                        )
    
        model_uid = client.repository.get_model_id(rf_model_details)
    
        deployment_properties = {
                                client.deployments.ConfigurationMetaNames.NAME:deployment_name,
                                client.deployments.ConfigurationMetaNames.ONLINE: {},
                                }
    
        deployment = client.deployments.create(
                    model_uid,
                    meta_props=deployment_properties
                    )
    
    the rf_model_details -
    {'entity': {'hybrid_pipeline_software_specs': [], 'software_spec': {'id': 'xxx', 'name': 'runtime-22.1-py3.9'}, 'type': 'scikit-learn_1.0'}, 'metadata': {'created_at': '2022-11-13T07:11:51.480Z', 'id': 'xxx', 'modified_at': '2022-11-13T07:11:59.610Z', 'name': 'Prediction', 'owner': 'IBMid-QQQ, 'resource_key': 'yyy', 'space_id': 'zzz'}, 'system': {'warnings': []}}

    the error is happened on the deployment after storing the model -
    '''Model loading through joblib failed with exception: KeyError and message: 0. The model object provided for deployment is either invalid or trained using a version of scikit-learn other than: 1.0'''



    I created virtual envrionment with python 3.9.15 and installed scikit-learn 1.0


    Why this issue is happening and how to solve this, thanks




    ------------------------------
    Shanmugaraj Kamaraj
    ------------------------------

    #WatsonStudio