Click here to Skip to main content
15,558,870 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Python
  1  import numpy as np
  2  import matplotlib.pyplot as plt
  3  import pandas as pd
  4  
  5  #Insert your dataset here
  6  
  7  dataset = pd.read_csv('https://github.com/gdabhishek/WML-Deploy/blob/master/Social_Network_Ads.csv')
  8  
  9  User ID	Gender	Age	EstimatedSalary	Purchased
 10  0	15624510	Male	19	19000	0
 11  1	15810944	Male	35	20000	0
 12  2	15668575	Female	26	43000	0
 13  3	15603246	Female	27	57000	0
 14  4	15804002	Male	19	76000	0
 15  
 16  
 17  
 18  #Check Missing Values
 19  dataset.isnull().any()
 20  
 21  #Spilt Dependent and Independent Variables
 22  
 23  X = dataset.iloc[:, [2, 3]].values
 24  y = dataset.iloc[:, 4].values
 25  
 26  # Splitting the dataset into the Training set and Test set
 27  
 28  from sklearn.model_selection import train_test_split
 29  X_train, X_test, y_train, y_test = train_test_split(X, y, test_size= 0.25, random_state = 0)
 30  
 31  # Fitting Decision Tree Classification to the Training set
 32  
 33  from sklearn.tree import DecisionTreeClassifier
 34  classifier = DecisionTreeClassifier(criterion = 'entropy', random_state = 0)
 35  classifier.fit(X_train, y_train)
 36  
 37  # Predicting the Test set results
 38  y_pred = classifier.predict(X_test)
 39  
 40  #Finding the accuracy score
 41  
 42  from sklearn.metrics import accuracy_score
 43  print("Accuracy Score: ",accuracy_score(y_test,y_pred)*100,"%")
 44  
 45  from watson_machine_learning_client import WatsonMachineLearningAPIClient
 46  
 47  #
 48  ### here i got error
 49  ##
 50  
 51  wml={
 52      
 53  }
 54  
 55  client = WatsonMachineLearningAPIClient(wml)
 56  
 57  model_props = {client.repository.ModelMetaNames.AUTHOR_NAME: "", 
 58                 client.repository.ModelMetaNames.AUTHOR_EMAIL: "", 
 59                 client.repository.ModelMetaNames.NAME: "MyModel"}
 60  
 61  model_artifact =client.repository.store_model(classifier, meta_props=model_props)
 62  
 63  client.repository.list()
 64  
 65  published_model_uid = client.repository.get_model_uid(model_artifact)
 66  created_deployment = client.deployments.create(published_model_uid, name="MyDeployment")
 67  
 68  
 69  scoring_endpoint = client.deployments.get_scoring_url(created_deployment)
 70  
 71  
 72  print(scoring_endpoint)
 73  
 74  scoring_payload = {"fields": ["Age","Salary"],"values": [[25,50000]]}
 75  predictions = client.deployments.score(scoring_endpoint, scoring_payload)
 76  print(predictions)
 77  
 78  client.deployments.list("de8eebf1-7c57-429d-9831-21c5fd4912a3")


What I have tried:

I am trying to make predictions

Deploy Machine Learning (scikit-learn) Models in IBM Cloud - Watson Studio
Posted
Updated 14-Oct-20 6:14am
v2
Comments
Gerry Schmitz 14-Oct-20 11:02am    
This isn't IBM.
Member 14636305 15-Oct-20 0:50am    
It is about
i am deploying code in IBM Watson environment and
i have an error while using ( import watson-machine-learning-client)
Richard MacCutchan 14-Oct-20 11:12am    
What error?
Member 14636305 15-Oct-20 0:51am    
it is showing that client object is not defined!!
Richard MacCutchan 15-Oct-20 4:31am    
So do you think it might be useful to explain what you mean by "it", what the exact error message is, and which line it occurs on?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900