Skip to content

Instantly share code, notes, and snippets.

View swateek's full-sized avatar
🎯
One Small Step at a Time

Swateek Jena swateek

🎯
One Small Step at a Time
View GitHub Profile
@swateek
swateek / export_to_csv_from_mongo
Last active September 7, 2017 17:37
Export Data from MongoDB to .csv
// export data to csv
print("ap_mac,tags");
db.managedaps.find({}).forEach(function(ap){
print(ap.mac+","+ap.tags);
});
// mongo dbname filename.js > out.csv
@swateek
swateek / histogram.py
Created July 28, 2017 10:17
Plotting a Histogram with bucket sizes
import numpy as np
import matplotlib.pyplot as plt
hist, bin_edges = np.histogram([1, 1, 2, 2, 2, 2, 3], bins = range(5))
plt.bar(bin_edges[:-1], hist, width = 1)
plt.xlim(min(bin_edges), max(bin_edges))
plt.show()
@swateek
swateek / bucket_sizes.py
Created July 28, 2017 10:12
Freedman-Diaconis thumb rule for number of bins of a histogram
import math
def numBins(metric, defaultBins):
h = binWidth(metric)
ulim = max(metric)
llim = min(metric)
if (h <= (ulim - llim) / len(metric)):
return defaultBins or 10
return int(math.ceil((ulim - llim) / h))
@swateek
swateek / bucket_sizes.js
Last active July 28, 2017 10:12
Freedman-Diaconis thumb rule for number of bins of a histogram
// metric = array of real numbers (like > 100 or something)
// IQR = inter-quaartile-range
function numBins(metric, defaultBins) {
var h = binWidth(metric), ulim = Math.max.apply(Math, metric), llim = Math.min.apply(Math, metric);
if (h <= (ulim - llim) / metric.length) {
return defaultBins || 10; // Fix num bins if binWidth yields too small a value.
}
return Math.ceil((ulim - llim) / h);
}