Skip to content

Instantly share code, notes, and snippets.

View AviSoori1x's full-sized avatar

Avinash Sooriyarachchi AviSoori1x

View GitHub Profile
@AviSoori1x
AviSoori1x / app.py
Created April 14, 2021 00:58
app.py file for the streamlit app
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
!pip install altair
import altair as alt
alt.Chart(shap).mark_bar().encode(
x='Variable',
y='Estimate'
)
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']
samplepd['BAD'] = scores.I_BAD.to_list()
s.upload(samplepd,casout={'name' : 'realtime', 'caslib' : 'public','replace' : True})
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
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
@AviSoori1x
AviSoori1x / exml_samplepd.py
Created April 14, 2021 00:41
sample pandas dataframe
samplepd = dicttopd(datadict)
s.upload(samplepd,casout={'name' : 'realtime', 'caslib' : 'public','replace' : True})
def dicttopd(datadict):
for key in datadict:
datadict[key] = [datadict[key]]
return pd.DataFrame.from_dict(datadict)
@AviSoori1x
AviSoori1x / exml_sample.py
Created April 14, 2021 00:38
Sample observation
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}
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')