Skip to content

Instantly share code, notes, and snippets.

View ofekp's full-sized avatar

Ofek ofekp

View GitHub Profile
@Kingkha
Kingkha / roc_auc_score.py
Created November 20, 2019 08:38
calculate roc_auc_score from two numpy ndarray
# Source: http://ethen8181.github.io/machine-learning/model_selection/auc/auc.html#Implementation
def _binary_clf_curve(y_true, y_score):
"""
Calculate true and false positives per binary classification
threshold (can be used for roc curve or precision/recall curve);
the calcuation makes the assumption that the positive case
will always be labeled as 1
Parameters
----------
@oseiskar
oseiskar / pathos-multiprocessing-example.py
Created March 24, 2018 07:05
Python multiprocessing and exception handling example with pathos
from pathos.multiprocessing import ProcessingPool as Pool
def parallel_map(func, array, n_workers):
def compute_batch(i):
try:
return func(i)
except KeyboardInterrupt:
raise RuntimeError("Keyboard interrupt")
p = Pool(n_workers)
@abalter
abalter / argparse1.md
Last active May 30, 2023 11:51
Python Aargparsing Examples

http://stackoverflow.com/a/30493366/188963

Other answers do mention that argparse is the way to go for new Python, but do not give usage examples. For completeness, here is a short summary of how to use argparse:

1) Initialize

import argparse

# Instantiate the parser

parser = argparse.ArgumentParser(description='Optional app description')

@ofekp
ofekp / bluetoothctl.py
Last active January 24, 2023 10:12 — forked from egorf/bluetoothctl.py
Bluetoothctl wrapper in Python
# ReachView code is placed under the GPL license.
# Written by Egor Fedorov (egor.fedorov@emlid.com)
# Copyright (c) 2015, Emlid Limited
# All rights reserved.
# If you are interested in using ReachView code as a part of a
# closed source project, please contact Emlid Limited (info@emlid.com).
# This file is part of ReachView.
@egorf
egorf / bluetoothctl.py
Created March 22, 2016 10:30
Bluetoothctl wrapper in Python
# ReachView code is placed under the GPL license.
# Written by Egor Fedorov (egor.fedorov@emlid.com)
# Copyright (c) 2015, Emlid Limited
# All rights reserved.
# If you are interested in using ReachView code as a part of a
# closed source project, please contact Emlid Limited (info@emlid.com).
# This file is part of ReachView.