Skip to content

Instantly share code, notes, and snippets.

View missflash's full-sized avatar
🙃
I may be slow to respond.

Sang Hun Kim missflash

🙃
I may be slow to respond.
View GitHub Profile
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)
# 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])]
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)
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)
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