Skip to content

Instantly share code, notes, and snippets.

@orleika
Last active December 24, 2017 05:24
Show Gist options
  • Save orleika/365108da63745f6315c17d830d109bc1 to your computer and use it in GitHub Desktop.
Save orleika/365108da63745f6315c17d830d109bc1 to your computer and use it in GitHub Desktop.
DFS(枝刈り込み)による統計的識別手法の最良組み合わせ抽出
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@orleika
Copy link
Author

orleika commented Aug 7, 2017

Timer unit: 1e-06 s

Total time: 0.007946 s
File:
Function: auc at line 1

Line # Hits Time Per Hit % Time Line Contents

 1                                           def auc(y, X):
 2         1         3283   3283.0     41.3      pred = np.mean(X, axis = 1)
 3         1         4498   4498.0     56.6      fpr, tpr, thresholds = metrics.roc_curve(y, pred)
 4         1          165    165.0      2.1      return metrics.auc(fpr, tpr)

@orleika
Copy link
Author

orleika commented Aug 7, 2017

To reduce total processing time by using multiprocessing

import multiprocessing as mp

def roc(v):
    """ calculate one pair, return (index, auc) """
    i, true, pred = v
    fpr, tpr, thresholds = metrics.roc_curve(true, pred, drop_intermediate=True)
    auc = metrics.auc(fpr, tpr)
    return i, auc

pool = mp.Pool(3) 
result = pool.map_async(roc, ((i, true[i], pred[i]) for i in range(2)))
pool.close()
pool.join()
print result.get()

Python is not supported tail call optimization, therforer, recursive call function should transform loop function.
my god!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment