In [1]:
%pylab
%matplotlib inline
In [2]:
cd ..
In [3]:
import sys
import numpy as np
import skimage
import cv2
import sklearn
In [22]:
import time
In [4]:
from holoviews import *
In [5]:
%load_ext holoviews.ipython
In [6]:
import neukrill_net.utils
import neukrill_net.highlevelfeatures
In [7]:
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
In [8]:
settings = neukrill_net.utils.Settings('settings.json')
In [9]:
X,y = settings.flattened_train_paths(settings.classes)
In [10]:
img = neukrill_net.highlevelfeatures.loadimage(X[0])
In [11]:
imgplot = plt.imshow(img)
imgplot.set_cmap('gray')
In [12]:
import skimage.feature
In [13]:
M = skimage.feature.greycomatrix(img, [1], 0, levels=256, normed=True)
In [14]:
M.shape
Out[14]:
In [15]:
M.squeeze()
Out[15]:
In [16]:
%%opts Image style(cmap='coolwarm')
Image((M.squeeze()-M.min())*(M.max()-M.min()))
In [17]:
reload(neukrill_net.highlevelfeatures)
Out[17]:
In [18]:
hlf = neukrill_net.highlevelfeatures.CoocurProps()
In [19]:
hlf.extract_image(img)
Out[19]:
In [20]:
neukrill_net.highlevelfeatures.CoocurProps(num_angles=8).extract_image(img)
Out[20]:
In [23]:
t0 = time.time()
XF = hlf.transform(X)
print("Computing features took {}".format(time.time()-t0))
In [25]:
sklearn.externals.joblib.dump((hlf,XF,y),'cache/coocurprops.pkl')
Out[25]:
In [26]:
XF.shape
Out[26]:
In [27]:
import sklearn.naive_bayes
In [28]:
clf = sklearn.naive_bayes.GaussianNB()
t0 = time.time()
X_train, X_test, y_train, y_test = sklearn.cross_validation.train_test_split(
sklearn.preprocessing.StandardScaler().fit_transform(XF.squeeze(0)), y, test_size=0.5, random_state=42)
clf.fit(X_train, y_train)
t1 = time.time()
total = t1-t0
print("Time={}".format(total))
print("Accuracy={}".format(clf.score(X_test, y_test)))
print("Logloss={}".format(sklearn.metrics.log_loss(y_test, clf.predict_proba(X_test))))
In [29]:
clf = sklearn.linear_model.LogisticRegression(random_state=42)
t0 = time.time()
X_train, X_test, y_train, y_test = sklearn.cross_validation.train_test_split(
sklearn.preprocessing.StandardScaler().fit_transform(XF.squeeze(0)), y, test_size=0.5, random_state=42)
clf.fit(X_train, y_train)
t1 = time.time()
total = t1-t0
print("Time={}".format(total))
print("Accuracy={}".format(clf.score(X_test, y_test)))
print("Logloss={}".format(sklearn.metrics.log_loss(y_test, clf.predict_proba(X_test))))