asharma567 commited on
Commit
d7e7aed
1 Parent(s): 1c7e53a
Files changed (3) hide show
  1. Untitled.ipynb +89 -0
  2. app.py +17 -4
  3. ppl_labels.joblib +0 -0
Untitled.ipynb ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "8841693e",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import joblib"
11
+ ]
12
+ },
13
+ {
14
+ "cell_type": "code",
15
+ "execution_count": 2,
16
+ "id": "44508d4e",
17
+ "metadata": {},
18
+ "outputs": [],
19
+ "source": [
20
+ "explainer = joblib.load('explainer.joblib')"
21
+ ]
22
+ },
23
+ {
24
+ "cell_type": "code",
25
+ "execution_count": 5,
26
+ "id": "1b4565fa",
27
+ "metadata": {},
28
+ "outputs": [
29
+ {
30
+ "ename": "FileNotFoundError",
31
+ "evalue": "[Errno 2] No such file or directory: 'ppl_labels.joblib'",
32
+ "output_type": "error",
33
+ "traceback": [
34
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
35
+ "\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
36
+ "\u001b[0;32m<ipython-input-5-67089289c8c9>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mppl_labels\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mjoblib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mload\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'ppl_labels.joblib'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
37
+ "\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/joblib/numpy_pickle.py\u001b[0m in \u001b[0;36mload\u001b[0;34m(filename, mmap_mode)\u001b[0m\n\u001b[1;32m 575\u001b[0m \u001b[0mobj\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_unpickle\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfobj\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 576\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 577\u001b[0;31m \u001b[0;32mwith\u001b[0m \u001b[0mopen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfilename\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'rb'\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 578\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0m_read_fileobject\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfilename\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmmap_mode\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mfobj\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 579\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfobj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
38
+ "\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'ppl_labels.joblib'"
39
+ ]
40
+ }
41
+ ],
42
+ "source": [
43
+ "ppl_labels = joblib.load('ppl_labels.joblib')"
44
+ ]
45
+ },
46
+ {
47
+ "cell_type": "code",
48
+ "execution_count": 4,
49
+ "id": "62b796d3",
50
+ "metadata": {},
51
+ "outputs": [
52
+ {
53
+ "data": {
54
+ "text/plain": [
55
+ "shap.explainers._tree.Tree"
56
+ ]
57
+ },
58
+ "execution_count": 4,
59
+ "metadata": {},
60
+ "output_type": "execute_result"
61
+ }
62
+ ],
63
+ "source": [
64
+ "type(explainer)"
65
+ ]
66
+ }
67
+ ],
68
+ "metadata": {
69
+ "kernelspec": {
70
+ "display_name": "Python 3",
71
+ "language": "python",
72
+ "name": "python3"
73
+ },
74
+ "language_info": {
75
+ "codemirror_mode": {
76
+ "name": "ipython",
77
+ "version": 3
78
+ },
79
+ "file_extension": ".py",
80
+ "mimetype": "text/x-python",
81
+ "name": "python",
82
+ "nbconvert_exporter": "python",
83
+ "pygments_lexer": "ipython3",
84
+ "version": "3.8.8"
85
+ }
86
+ },
87
+ "nbformat": 4,
88
+ "nbformat_minor": 5
89
+ }
app.py CHANGED
@@ -9,6 +9,7 @@ import streamlit as st
9
  import streamlit.components.v1 as components
10
  import pickle
11
  import xgboost
 
12
 
13
 
14
 
@@ -56,10 +57,24 @@ st.title("Boba Leaderboard")
56
 
57
  #load joblib
58
  df_M_character = pickle.load(open('df_M_character.pickle', 'rb'))
59
- explainer = pickle.load(open('explainer.pickle', 'rb'))
60
- shap_values = pickle.load(open('shap_values.pickle', 'rb'))
61
  df_M_character_scale = scale_and_standardize(df_M_character)
62
  author_idx_lookup = dict([(name, idx) for idx, name in enumerate(df_M_character.index)])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
  X = pd.DataFrame(
65
  df_M_character_scale,
@@ -71,8 +86,6 @@ df_leaderboard.rename(columns = {'Unnamed: 0':'Rank', 'author':'member'}, inplac
71
  selection = aggrid_interactive_table(df=df_leaderboard)
72
 
73
 
74
-
75
-
76
  if selection:
77
  try:
78
  auth = selection["selected_rows"][0]['member']
 
9
  import streamlit.components.v1 as components
10
  import pickle
11
  import xgboost
12
+ import joblib
13
 
14
 
15
 
 
57
 
58
  #load joblib
59
  df_M_character = pickle.load(open('df_M_character.pickle', 'rb'))
60
+ # explainer = pickle.load(open('explainer.pickle', 'rb'))
61
+ # shap_values = pickle.load(open('shap_values.pickle', 'rb'))
62
  df_M_character_scale = scale_and_standardize(df_M_character)
63
  author_idx_lookup = dict([(name, idx) for idx, name in enumerate(df_M_character.index)])
64
+ ppl_labels = joblib.load('ppl_labels.joblib')
65
+ # train XGBoost model
66
+ X, y = pd.DataFrame(
67
+ df_M_character_scale,
68
+ columns=df_M_character.columns
69
+ ), ppl_labels
70
+
71
+ bst = xgboost.train({"learning_rate": 0.01}, xgboost.DMatrix(X, label=y), 100)
72
+
73
+ # explain the model's predictions using SHAP values
74
+ explainer = shap.TreeExplainer(bst)
75
+ shap_values = explainer.shap_values(X)
76
+ # shap.summary_plot(shap_values, X)
77
+
78
 
79
  X = pd.DataFrame(
80
  df_M_character_scale,
 
86
  selection = aggrid_interactive_table(df=df_leaderboard)
87
 
88
 
 
 
89
  if selection:
90
  try:
91
  auth = selection["selected_rows"][0]['member']
ppl_labels.joblib ADDED
Binary file (9.46 kB). View file