Skip to content

Instantly share code, notes, and snippets.

@sigma23
sigma23 / multi_class_sklearn_roc_curves.py
Created November 5, 2018 20:08
Multiclass Roc curves
from sklearn.metrics import roc_curve, auc
# Compute ROC curve and ROC area for each class
fpr = dict()
tpr = dict()
roc_auc = dict()
for i in range(n_classes):
fpr[i], tpr[i], _ = roc_curve(y[:, i], preds[:, i])
roc_auc[i] = auc(fpr[i], tpr[i])
# Compute micro-average ROC curve and ROC area
@sigma23
sigma23 / get_jupyter_notebook_name.py
Created October 23, 2018 21:56
Get jupyter notebook name
import os
from IPython.core.display import Javascript
from IPython.display import display
import datetime
display(Javascript('Jupyter.notebook.kernel.execute(\
"this_notebook = " + "\'"\
+Jupyter.notebook.notebook_name+"\'");'))
@sigma23
sigma23 / sql_join_on_values_and_null.sql
Created October 22, 2018 21:26
To do a join in sql and also keep null values
select B.*, A.*
from B
left outer join A ON
(A.[id1] = B.[id1] or (coalesce(A.[id1],B.[id1]) is null))
@sigma23
sigma23 / rename_or_copy_bulk_aws.py
Created January 25, 2018 18:31
Rename a bulk amount of s3 files using boto3
# matching functions from https://alexwlchan.net/2017/07/listing-s3-keys/
# https://alexwlchan.net/2018/01/listing-s3-keys-redux/
import boto3
import datetime
import os
def get_matching_s3_objects(bucket, prefix='', suffix=''):
@sigma23
sigma23 / covert_json_array_to_jsonlines_jq_or_python.txt
Last active May 15, 2023 19:22
Convert from json array to jsonlines using jq and python
# Run this from the bash command prompt. Make sure that jq is installed https://github.com/stedolan/jq/wiki/Installation
# json_temp.json has the file in the form [{...}, {...}, {...}] and coverts to {...}\n{...}\n
jq -c '.[]' json_temp.json > json_temp.jsonl
# From within python can do this:
pip install jsonlines
import json
import jsonlines
@sigma23
sigma23 / zip_unzip_s3_upload.sh
Created December 19, 2017 17:03
Quickly zip and upload to S3 and unzip there
# From https://stackoverflow.com/questions/14495176/compress-file-on-s3
aws s3 sync s3://your-pics .
for i in `find | grep -E "\.jpg$|\.jpg$"`; do gzip "$i" ; echo $i; done
aws s3 sync . s3://your-pics --content-encoding gzip --dryrun
@sigma23
sigma23 / README.md
Created March 29, 2016 19:22 — forked from ajschumacher/README.md
Interactive D3 view of sklearn decision tree