Skip to content

Instantly share code, notes, and snippets.

View ryan-hill's full-sized avatar

Ryan Hill ryan-hill

View GitHub Profile
@gakuba
gakuba / metrics.py
Last active July 16, 2018 23:32
module to display roc_au of multilabel classifier
import matplotlib.pyplot as plt
import numpy as np
from sklearn.metrics import roc_curve, auc
from scipy import interp
from itertools import cycle
def roc_auc(y_test, y_score, n_classes):
"""Plots ROC curve for micro and macro averaging."""
# Compute ROC curve and ROC area for each class
@gakuba
gakuba / MultiLabelClassification-with-nltk.ipynb
Last active April 1, 2020 16:11
In this Tutorial, I explain how to do Multi label classification of texts using nltk
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@debboutr
debboutr / walk_up.py
Last active October 19, 2017 16:50
recursive function to walk up flow table. NOTE: this will not handle braided flowlines!
from StreamCat_functions import dbf2DF
pre = 'D:/NHDPlusV21/NHDPlusGL/NHDPlus04'
fline = dbf2DF('D%s/NHDSnapshot/Hydrography/NHDFlowline.dbf' % pre)
flow = dbf2DF('%s/NHDPlusAttributes/PlusFlow.dbf' pre)[['TOCOMID','FROMCOMID']]
def recurs(val, ups):
print val
ups = ups + flow.ix[flow.TOCOMID == val].FROMCOMID.tolist()
if 0 in ups:
@mhweber
mhweber / SpatialLinesEndPoints.R
Created February 1, 2016 21:23
Function to build a spatial points data frame of end nodes using a spatial lines data frame - function is a modification of SpatialLinesMidPoints in the R maptools package.
SpatialLinesEndPoints = function(sldf){
Lns <- slot(sldf, "lines")
hash_lns <- sapply(Lns, function(x) length(slot(x, "Lines")))
N <- sum(hash_lns)
endpoints <- matrix(NA, ncol = 2, nrow = N)
Ind <- integer(length = N)
ii <- 1
for (i in 1:length(Lns)) {
Lnsi <- slot(Lns[[i]], "Lines")
for (j in 1:hash_lns[i]) {
@ryan-hill
ryan-hill / float2int.py
Created October 14, 2015 00:35 — forked from bryanluman/float2int.py
Converting a large DEM with rasterio
import numpy as np
import rasterio
"""
2014-02-13
Bryan Luman
Use it however you like at your own risk
Problem:
I have a huge DEM converted from LiDAR LAS points. I'd like to make it slightly
@mhweber
mhweber / Lookup.R
Last active October 1, 2015 19:10
This code takes a lookup table and applies it to a data frame, updating only values for records that occur in the lookup table using indexing and match
# Create data frame 1
x = c("ID1","ID2","ID3","ID4","ID5")
y = c("C1","C2","C3","C4","C5")
d1 = data.frame("SiteID" = x, "Value" = y)
d1
# Create lookup table
x = c("ID2","ID5")
y = c("C5","C2")
lookup = data.frame("SiteID" = x, "Value" = y)
lookup
@bryanluman
bryanluman / float2int.py
Last active December 2, 2020 03:57
Converting a large DEM with rasterio
import numpy as np
import rasterio
"""
2014-02-13
Bryan Luman
Use it however you like at your own risk
Problem:
I have a huge DEM converted from LiDAR LAS points. I'd like to make it slightly