瀏覽代碼

adding the strict flag

Steve Nyemba 6 年之前
父節點
當前提交
084e7d0fe8
共有 1 個文件被更改,包括 5 次插入3 次删除
  1. 5 3
      risk/risk.py

+ 5 - 3
risk/risk.py

@@ -76,7 +76,7 @@ class deid :
         
         sample = args['sample'] if 'sample' in args else pd.DataFrame(self._df)
         
-        k = sample.columns.size if 'field_count' not in args else int(args['field_count']) + 1
+        k = sample.columns.size if 'field_count' not in args else int(args['field_count']) +1
         if 'id' in args :
             id = args['id']
             columns = list(set(sample.columns.tolist()) - set([id]))
@@ -85,8 +85,10 @@ class deid :
         o = pd.DataFrame()
         
         for i in np.arange(RUNS):
-            n = np.random.randint(2,k)
-            
+            if 'strict' not in args :
+                n = np.random.randint(2,k)
+            else:
+                n = args['field_count']
             cols = np.random.choice(columns,n,replace=False).tolist()            
             params = {'sample':sample,'cols':cols}
             if pop is not None :