Last active
April 14, 2021 00:03
-
-
Save AviSoori1x/b9f5a1d6ac5f07b053e4f46179cc82fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shapvals = s.linearExplainer( | |
table = {"name" : 'hmeqTest','caslib':'public'}, | |
query = {"name" : 'realtime','caslib':'public'}, | |
modelTable = {"name" :"hmeqTestAstore",'caslib':'public'}, | |
modelTableType = "ASTORE", | |
predictedTarget = 'P_BAD1', | |
seed = 1234, | |
preset = "KERNELSHAP", | |
inputs = ['LOAN','MORTDUE','VALUE','YOJ','DEROG','DELINQ','CLAGE','NINQ','CLNO','DEBTINC','REASON', 'JOB','BAD'], | |
nominals = ['REASON', 'JOB','BAD'] | |
) | |
shap1 = shapvals['ParameterEstimates'] | |
shap = shap1[['Variable','Estimate']][0:10] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = CAS(host, port, username, password) | |
s.loadActionSet('autotune') | |
s.loadactionset('aStore') | |
s.loadactionset('decisionTree') | |
s.loadactionset("explainModel") | |
s.loadactionset('table') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dicttopd(datadict): | |
for key in datadict: | |
datadict[key] = [datadict[key]] | |
return pd.DataFrame.from_dict(datadict) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s.table.promote(name="hmeqTest", caslib='public',target="hmeqTest",targetLib='public') | |
modelAstore = s.decisionTree.dtreeExportModel(modelTable = {"caslib":"public","name":"gradboosthmeqtest" }, | |
casOut = {"caslib":"public","name":'hmeqTestAstore','replace':True}) | |
s.table.promote(name='hmeqTestAstore', caslib='public',target='hmeqTestAstore',targetLib='public') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hmeq = pd.read_csv('hmeq.csv') | |
hmeq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
result = s.autotune.tuneGradientBoostTree( | |
trainOptions = { | |
"table" : {"name":'hmeqTest', 'caslib' : 'public'}, | |
"inputs" : {'LOAN','MORTDUE','VALUE','YOJ','DEROG','DELINQ','CLAGE','NINQ','CLNO','DEBTINC','REASON', 'JOB'}, | |
"target" : 'BAD', | |
"nominal" : {'BAD','REASON', 'JOB'}, | |
"casout" : {"name":"gradboosthmeqtest", "caslib":"public",'replace':True}, | |
"varImp" : True | |
}, | |
tunerOptions={"seed":12345, "maxTime":60} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!pip install swat | |
from swat import CAS, options | |
import pandas as pd | |
import numpy as np |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
samplepd = dicttopd(datadict) | |
s.upload(samplepd,casout={'name' : 'realtime', 'caslib' : 'public','replace' : True}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
datadict = {'LOAN':140,'MORTDUE':3000, 'VALUE':40000, 'REASON':'HomeImp','JOB':'Other','YOJ':12, | |
'DEROG':0.0,'DELINQ':0.0, 'CLAGE':89,'NINQ':1.0, 'CLNO':10.0, 'DEBTINC':0.05} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s.aStore.score(rstore = {"caslib":"public","name":"hmeqTestAstore"}, | |
table = {"caslib":'public',"name":'realtime'}, | |
out = {"caslib":'public',"name":'realscore', 'replace':True}) | |
scoredData = s.CASTable(name='realscore',caslib='public') | |
datasetDict = scoredData.to_dict() | |
scores = pd.DataFrame(datasetDict, index=[0]) | |
scores |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def score(samplepd): | |
s.upload(samplepd,casout={'name' : 'realtime', 'caslib' : 'public','replace' : True}) | |
s.aStore.score(rstore = {"caslib":"public","name":"hmeqTestAstore"}, | |
table = {"caslib":'public',"name":'realtime'}, | |
out = {"caslib":'public',"name":'realscore', 'replace':True}) | |
scoredData = s.CASTable(name='realscore',caslib='public') | |
datasetDict = scoredData.to_dict() | |
scores = pd.DataFrame(datasetDict, index=[0]) | |
return scores | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s.upload(hmeq,casout={'name' : 'hmeqTest', 'caslib' : 'public','replace' : True}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!pip install altair | |
import altair as alt | |
alt.Chart(shap).mark_bar().encode( | |
x='Variable', | |
y='Estimate' | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
samplepd['BAD'] = scores.I_BAD.to_list() | |
s.upload(samplepd,casout={'name' : 'realtime', 'caslib' : 'public','replace' : True}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment