1 import numpy as np
2 import matplotlib.pyplot as plt
3 import pandas as pd
4
5
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
19 dataset.isnull().any()
20
21
22
23 X = dataset.iloc[:, [2, 3]].values
24 y = dataset.iloc[:, 4].values
25
26
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
32
33 from sklearn.tree import DecisionTreeClassifier
34 classifier = DecisionTreeClassifier(criterion = 'entropy', random_state = 0)
35 classifier.fit(X_train, y_train)
36
37
38 y_pred = classifier.predict(X_test)
39
40
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
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