-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathmodule.py
More file actions
36 lines (31 loc) · 1.35 KB
/
module.py
File metadata and controls
36 lines (31 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import pandas as pd, json, sys
def explain(feature_df: pd.DataFrame, target_col: str, preds):
corr_s = feature_df.corr().get(target_col)
important = []
if corr_s is not None:
important = [c for c in corr_s.abs().sort_values(ascending=False).index if c != target_col][:3]
return {"importantFeatures": important, "method": "corr-proxy"}
if __name__ == "__main__":
# argv[1] = csv_path, argv[2] = target_col
csv, target = sys.argv[1], sys.argv[2]
df = pd.read_csv(csv)
out = explain(df.iloc[:,4:], target, [])
with open("outputs/explain.json","w") as f:
json.dump(out,f)
def risk(feature_df: pd.DataFrame, target_col: str, preds):
series = pd.to_numeric(feature_df[target_col], errors="coerce").dropna()
if series.size < 5:
return {"riskLevel":"unknown","exceedsThreshold":False}
z = (preds[-1] - series.mean())/(series.std() or 1)
if abs(z)>2: level="high"
elif abs(z)>1: level="medium"
else: level="low"
return {"riskLevel":level,"exceedsThreshold":level in ("medium","high")}
if __name__=="__main__":
csv, target = sys.argv[1], sys.argv[2]
df = pd.read_csv(csv)
# preds는 생략: 데모라 랜덤
preds = [float(series.mean()) for series in range(3)]
out = assess(df.iloc[:,4:], target, preds)
with open("outputs/risk.json","w") as f:
json.dump(out,f)