Spaces:
Runtime error
Runtime error
NaokiOkamoto
commited on
Commit
•
cbf25e1
1
Parent(s):
ec74bc1
Update app.py
Browse files
app.py
CHANGED
@@ -90,33 +90,36 @@ def get_model_infomation():
|
|
90 |
|
91 |
return model_info, feature_impact
|
92 |
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
|
|
|
|
|
|
118 |
|
119 |
-
|
120 |
|
121 |
with gr.Blocks() as electoric_ploting:
|
122 |
gr.Markdown(
|
@@ -200,48 +203,49 @@ with gr.Blocks() as electoric_ploting:
|
|
200 |
y_lim=[0, 1.2],
|
201 |
width=400,
|
202 |
height=300)
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
|
243 |
retrain_btn.click(retrain, inputs=None, outputs = [output_model_type, output_acc, output_plot])
|
244 |
|
|
|
245 |
electoric_ploting.load(lambda: datetime.datetime.now(),
|
246 |
None,
|
247 |
# c_time2,
|
|
|
90 |
|
91 |
return model_info, feature_impact
|
92 |
|
93 |
+
def get_featuredrift():
|
94 |
+
deployment = dr.Deployment.get(deployment_id='640d791796a6a52d92c368a0')
|
95 |
+
target_drift = dr.models.TargetDrift.get(deployment.id)
|
96 |
+
feature_drift_list = dr.models.FeatureDrift.list(deployment.id)
|
97 |
+
drift_df = pd.DataFrame(
|
98 |
+
{
|
99 |
+
'feature_name':[target_drift.target_name],
|
100 |
+
'drift_score':[target_drift.drift_score],
|
101 |
+
'feature_impact':[1]
|
102 |
+
}
|
103 |
+
)
|
104 |
+
drift_df = pd.concat([
|
105 |
+
drift_df,
|
106 |
+
pd.DataFrame(
|
107 |
+
[[
|
108 |
+
feature_drift.name,
|
109 |
+
feature_drift.drift_score,
|
110 |
+
feature_drift.feature_impact
|
111 |
+
] for feature_drift in feature_drift_list
|
112 |
+
],
|
113 |
+
columns=[ 'feature_name', 'drift_score', 'feature_impact']
|
114 |
+
)
|
115 |
+
])
|
116 |
+
start_point = (target_drift.period['start']+relativedelta(hours=9)).strftime("%Y / %m / %d %H:%M:%S")
|
117 |
+
end_point = (target_drift.period['end']+relativedelta(hours=9)).strftime("%Y / %m / %d %H:%M:%S")
|
118 |
+
# drift_df.loc[(drift_df['drift_score']>drift_threshold)&(drift_df['feature_impact']>impact_threshold), 'alert'] = '重要性の高く、大きなドリフト'
|
119 |
+
# drift_df.loc[(drift_df['drift_score']>drift_threshold)&(drift_df['feature_impact']<=impact_threshold), 'alert'] = '重要性低いが、大きなドリフト'
|
120 |
+
# drift_df.loc[(drift_df['drift_score']<=drift_threshold), 'alert'] = '正常'
|
121 |
|
122 |
+
return drift_df, start_point, end_point
|
123 |
|
124 |
with gr.Blocks() as electoric_ploting:
|
125 |
gr.Markdown(
|
|
|
203 |
y_lim=[0, 1.2],
|
204 |
width=400,
|
205 |
height=300)
|
206 |
+
with gr.Tab("データドリフト情報"):
|
207 |
+
result = get_featuredrift()
|
208 |
+
with gr.Row():
|
209 |
+
gr.Markdown(
|
210 |
+
"""
|
211 |
+
こちらの図はデータドリフトと特徴量の有用性を表した図になっています。
|
212 |
+
味方は以下の通り
|
213 |
+
* ドリフトスコア:予測データに含まれるデータが、どれぐらい過去のデータに比べてずれが発生しているかを表しており、上に行けば行くほどズレが大きい
|
214 |
+
* 特徴量の有用性:ターゲットの有用性を1とした時に、どれぐらいそれぞれの特徴量の有用性が高いかを表したもので、右に行くほど有用性が高い
|
215 |
+
"""
|
216 |
+
)
|
217 |
+
with gr.Row():
|
218 |
+
drift_df = result[0]
|
219 |
+
start_point = result[1]
|
220 |
+
end_point = result[2]
|
221 |
+
gr.Textbox(f"{start_point}〜{end_point}",label=f'データドリフト確認期間')
|
222 |
+
with gr.Row():
|
223 |
+
if len(drift_df["drift_score"].unique())!=1:
|
224 |
+
gr.ScatterPlot(
|
225 |
+
drift_df,
|
226 |
+
x="feature_impact",
|
227 |
+
y="drift_score",
|
228 |
+
title="データドリフトとデータの有用性",
|
229 |
+
color_legend_title="Species",
|
230 |
+
x_title="特徴量の有用性",
|
231 |
+
y_title="ドリフトスコア",
|
232 |
+
x_lim = [-0.1, drift_df["feature_impact"].max()*1.4],
|
233 |
+
y_lim = [-0.1, drift_df["drift_score"].max()*1.4],
|
234 |
+
tooltip=["feature_name", "feature_impact", "drift_score"],
|
235 |
+
caption="",
|
236 |
+
height=500,
|
237 |
+
width=500
|
238 |
+
)
|
239 |
+
else:
|
240 |
+
gr.Markdown(
|
241 |
+
"""
|
242 |
+
モデルの入れ替え後に予測が実行されていないためdriftは表示できません。
|
243 |
+
"""
|
244 |
+
)
|
245 |
|
246 |
retrain_btn.click(retrain, inputs=None, outputs = [output_model_type, output_acc, output_plot])
|
247 |
|
248 |
+
|
249 |
electoric_ploting.load(lambda: datetime.datetime.now(),
|
250 |
None,
|
251 |
# c_time2,
|