Skip to content

Instantly share code, notes, and snippets.

missflash

Block or report user

Report or block missflash

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View logistic_function.py
from IPython.core.pylabtools import figsize
from matplotlib import pyplot as plt
import numpy as np
figsize(12, 3)
def logistic(x, beta, alpha=0):
return 1.0 / (1.0 + np.exp(np.dot(beta, x) + alpha))
x = np.linspace(-4, 4, 100)
View data_import.py
# Data Import Option
test_data = np.getfromtxt("data.csv", skip_header=1, usecols=[1, 2], missing_values="NA", delimiter=",")
# Remove NA rows
test_data = test_data[~np.isnan(test_data[:,1])]
View performance.py
from sklearn.metrics import accuracy_score, roc_auc_score, classification_report, roc_curve
def performance(y_true, pred, color="g", ann=True):
acc = accuracy_score(y_true, pred[:,1] > 0.5)
auc = roc_auc_score(y_true, pred[:,1])
fpr, tpr, thr = roc_curve(y_true, pred[:,1])
plot(fpr, tpr, color, linewidth="3")
xlabel("False positive rate")
ylabel("True positive rate")
if ann:
annotate("Acc: %0.2f" % acc, (0.1,0.8), size=14)
View scikit-image.py
pip install scikit-image
# Edge Detection
import skimage
image = skimage.data.camera()
edges = skimage.filter.sobel(image)
# HOG (Histogram of Oriented Gradient)
image = skimage.color.rgb2gray(skimage.data.astronaut())
skimage.feature.hog(image, orientations=9, pixels_per_cell=(8, 8), cells_per_block=(3, 3), visualise=True)
View normalize_feature.py
def normalize_feature(data, f_min=-1.0, f_max=1.0):
d_min, d_max = min(data), max(data)
factor = (f_max - f_min) / (d_max - d_min)
normalized = f_min + (data - d_min)*factor
return normalized, factor
You can’t perform that action at this time.