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
import streamlit as st | |
import pandas as pd | |
import numpy as np | |
from PIL import Image | |
from swat import CAS, options | |
import json | |
import altair as alt | |
import SessionState | |
import requests | |
import io |
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
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'] |
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}) |
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.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
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
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
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.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') |
NewerOlder