LLH commited on
Commit
086c1e6
·
1 Parent(s): 8d94a86

2024/03/07/22:24

Browse files
analysis/others/shap_model.py CHANGED
@@ -2,8 +2,12 @@ import matplotlib.pyplot as plt
2
  import numpy as np
3
  import shap
4
 
 
 
5
 
6
  def draw_shap_beeswarm(model, x, feature_names, type, paint_object):
 
 
7
  explainer = shap.KernelExplainer(model.predict, x)
8
  shap_values = explainer(x)
9
 
@@ -16,6 +20,8 @@ def draw_shap_beeswarm(model, x, feature_names, type, paint_object):
16
 
17
 
18
  def draw_waterfall(model, x, feature_names, number, paint_object):
 
 
19
  explainer = shap.KernelExplainer(model.predict, x, feature_names=feature_names)
20
  shap_values = explainer(x)
21
 
@@ -28,6 +34,7 @@ def draw_waterfall(model, x, feature_names, number, paint_object):
28
 
29
 
30
  def draw_force(model, x, feature_names, number, paint_object):
 
31
  explainer = shap.KernelExplainer(model.predict, x, feature_names=feature_names)
32
  shap_values = explainer(x[number])
33
 
@@ -40,6 +47,8 @@ def draw_force(model, x, feature_names, number, paint_object):
40
 
41
 
42
  def draw_dependence(model, x, feature_names, col, paint_object):
 
 
43
  explainer = shap.KernelExplainer(model.predict, x, feature_names=feature_names)
44
  shap_values = explainer(x)
45
 
 
2
  import numpy as np
3
  import shap
4
 
5
+ from classes.static_custom_class import StaticValue
6
+
7
 
8
  def draw_shap_beeswarm(model, x, feature_names, type, paint_object):
9
+ plt.clf()
10
+ x = shap.sample(x, min(123, len(x)), random_state=StaticValue.RANDOM_STATE)
11
  explainer = shap.KernelExplainer(model.predict, x)
12
  shap_values = explainer(x)
13
 
 
20
 
21
 
22
  def draw_waterfall(model, x, feature_names, number, paint_object):
23
+ plt.clf()
24
+ x = shap.sample(x, min(123, len(x)), random_state=StaticValue.RANDOM_STATE)
25
  explainer = shap.KernelExplainer(model.predict, x, feature_names=feature_names)
26
  shap_values = explainer(x)
27
 
 
34
 
35
 
36
  def draw_force(model, x, feature_names, number, paint_object):
37
+ plt.clf()
38
  explainer = shap.KernelExplainer(model.predict, x, feature_names=feature_names)
39
  shap_values = explainer(x[number])
40
 
 
47
 
48
 
49
  def draw_dependence(model, x, feature_names, col, paint_object):
50
+ plt.clf()
51
+ x = shap.sample(x, min(123, len(x)), random_state=StaticValue.RANDOM_STATE)
52
  explainer = shap.KernelExplainer(model.predict, x, feature_names=feature_names)
53
  shap_values = explainer(x)
54
 
app.py CHANGED
@@ -1180,10 +1180,10 @@ class Dataset:
1180
  data_copy = cls.data
1181
 
1182
  if cls.assign == MN.classification:
1183
- gr.Info("分类任务请确保目标变量列(第一列)数值为字符型[有限个标签]")
1184
  data_copy.iloc[:, 0] = data_copy.iloc[:, 0].astype(str)
1185
  else:
1186
- gr.Info("回归任务请确保目标变量列(第一列)数值为数值型")
1187
  data_copy.iloc[:, 0] = data_copy.iloc[:, 0].astype(float)
1188
 
1189
  cls.data = data_copy
 
1180
  data_copy = cls.data
1181
 
1182
  if cls.assign == MN.classification:
1183
+ # gr.Info("分类任务请确保目标变量列(第一列)数值为字符型[有限个标签]")
1184
  data_copy.iloc[:, 0] = data_copy.iloc[:, 0].astype(str)
1185
  else:
1186
+ # gr.Info("回归任务请确保目标变量列(第一列)数值为数值型")
1187
  data_copy.iloc[:, 0] = data_copy.iloc[:, 0].astype(float)
1188
 
1189
  cls.data = data_copy
data/notes.md CHANGED
@@ -147,24 +147,28 @@
147
  ·需要选择已训练的模型名称
148
  ·需要选择图像类型
149
  ·特征对模型整体能力的表征程度
 
150
  ```
151
  ##### *vii.特征瀑布图*
152
  ```angular2html
153
  ·需要选择已训练的模型名称
154
  ·需要选择相关特征的变量索引
155
  ·特征对模型整体能力的表征程度
 
156
  ```
157
  ##### *viii.特征力图*
158
  ```angular2html
159
  ·需要选择已训练的模型名称
160
  ·需要选择相关特征的变量索引
161
  ·特征对模型整体能力的表征程度
 
162
  ```
163
  ##### *viiii.特征依赖图*
164
  ```angular2html
165
  ·需要选择已训练的模型名称
166
  ·需要选择对应的列
167
  ·特征对模型整体能力的表征程度
 
168
  ```
169
  ##### *图例*
170
  ```angular2html
 
147
  ·需要选择已训练的模型名称
148
  ·需要选择图像类型
149
  ·特征对模型整体能力的表征程度
150
+ ·若样本量大于123,则随机抽样123个作为输入
151
  ```
152
  ##### *vii.特征瀑布图*
153
  ```angular2html
154
  ·需要选择已训练的模型名称
155
  ·需要选择相关特征的变量索引
156
  ·特征对模型整体能力的表征程度
157
+ ·若样本量大于123,则随机抽样123个作为输入
158
  ```
159
  ##### *viii.特征力图*
160
  ```angular2html
161
  ·需要选择已训练的模型名称
162
  ·需要选择相关特征的变量索引
163
  ·特征对模型整体能力的表征程度
164
+ ·若样本量大于123,则随机抽样123个作为输入
165
  ```
166
  ##### *viiii.特征依赖图*
167
  ```angular2html
168
  ·需要选择已训练的模型名称
169
  ·需要选择对应的列
170
  ·特征对模型整体能力的表征程度
171
+ ·若样本量大于123,则随机抽样123个作为输入
172
  ```
173
  ##### *图例*
174
  ```angular2html
visualization/draw_boxplot.py CHANGED
@@ -2,6 +2,7 @@ import matplotlib.pyplot as plt
2
 
3
 
4
  def draw_boxplot(x_data, paint_object, will_rotate=False):
 
5
  plt.figure(figsize=(10, 8), dpi=300)
6
 
7
  plt.grid(True)
 
2
 
3
 
4
  def draw_boxplot(x_data, paint_object, will_rotate=False):
5
+ plt.clf()
6
  plt.figure(figsize=(10, 8), dpi=300)
7
 
8
  plt.grid(True)
visualization/draw_data_fit_total.py CHANGED
@@ -3,6 +3,7 @@ from matplotlib import pyplot as plt
3
 
4
 
5
  def draw_data_fit_total(input_dict, paint_object):
 
6
  plt.figure(figsize=(10, 6), dpi=300)
7
 
8
  for i, input_dict_items in enumerate(input_dict.items()):
 
3
 
4
 
5
  def draw_data_fit_total(input_dict, paint_object):
6
+ plt.clf()
7
  plt.figure(figsize=(10, 6), dpi=300)
8
 
9
  for i, input_dict_items in enumerate(input_dict.items()):
visualization/draw_heat_map.py CHANGED
@@ -4,6 +4,7 @@ import pandas as pd
4
 
5
 
6
  def draw_heat_map(x_data, col_list, paint_object, will_rotate=False):
 
7
  plt.rcParams.update({'figure.autolayout': True})
8
 
9
  plt.figure(figsize=(10, 8), dpi=300)
 
4
 
5
 
6
  def draw_heat_map(x_data, col_list, paint_object, will_rotate=False):
7
+ plt.clf()
8
  plt.rcParams.update({'figure.autolayout': True})
9
 
10
  plt.figure(figsize=(10, 8), dpi=300)
visualization/draw_histogram.py CHANGED
@@ -3,6 +3,7 @@ import numpy as np
3
 
4
 
5
  def draw_histogram(nums, labels, paint_object, will_rotate=False, will_show_text=True):
 
6
  plt.figure(figsize=(10, 8), dpi=300)
7
 
8
  bars = plt.bar(
 
3
 
4
 
5
  def draw_histogram(nums, labels, paint_object, will_rotate=False, will_show_text=True):
6
+ plt.clf()
7
  plt.figure(figsize=(10, 8), dpi=300)
8
 
9
  bars = plt.bar(
visualization/draw_learning_curve_total.py CHANGED
@@ -2,6 +2,7 @@ from matplotlib import pyplot as plt
2
 
3
 
4
  def draw_learning_curve_total(input_dict, paint_object):
 
5
  plt.figure(figsize=(10, 8), dpi=300)
6
 
7
  for i, values in enumerate(input_dict.values()):
 
2
 
3
 
4
  def draw_learning_curve_total(input_dict, paint_object):
5
+ plt.clf()
6
  plt.figure(figsize=(10, 8), dpi=300)
7
 
8
  for i, values in enumerate(input_dict.values()):