This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import httplib2 | |
import os | |
from apiclient import discovery | |
from oauth2client import client | |
from oauth2client import tools | |
from oauth2client.file import Storage | |
try: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from skimage import io | |
image_paths = sorted(glob('../input/train-tif/*.tif'))[0:1000] | |
image_paths_jpg = sorted(glob('../input/train-jpg/*.jpg'))[0:1000] | |
imgs = [io.imread(path) / io.imread(path).max() for path in image_paths] | |
#r, g, b, nir = img[:, :, 0], img[:, :, 1], img[:, :, 2], img[:, :, 3] | |
ndvis = [(img[:,:,3] - img[:,:,0])/((img[:,:,3] + img[:,:,0])) for img in imgs] | |
n = 16 | |
plt.figure(figsize=(12,8)) | |
plt.subplot(131) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.manifold import TSNE | |
tsne = TSNE( | |
n_components=2, | |
init='random', # pca | |
random_state=101, | |
method='barnes_hut', | |
n_iter=500, | |
verbose=2 | |
).fit_transform(img_mat) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mask = np.zeros_like(sq_dists, dtype=np.bool) | |
mask[np.triu_indices_from(mask)] = True | |
# upper triangle of matrix set to np.nan | |
sq_dists[np.triu_indices_from(mask)] = np.nan | |
sq_dists[0, 0] = np.nan | |
fig = plt.figure(figsize=(12,8)) | |
# maximally dissimilar image | |
ax = fig.add_subplot(1,2,1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%matplotlib inline | |
import plotly.offline as py | |
py.init_notebook_mode(connected=True) | |
import plotly.graph_objs as go | |
import plotly.tools as tls | |
from sklearn.manifold import TSNE | |
tsne = TSNE( | |
n_components=3, | |
init='random', # pca |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
n_imgs = 600 | |
all_imgs = [] | |
for i in range(n_imgs): | |
img = plt.imread(image_paths[i]) | |
img = cv2.resize(img, (100, 100), cv2.INTER_LINEAR).astype('float') | |
# img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY).astype('float') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.multiclass import OneVsRestClassifier | |
from sklearn.linear_model import LogisticRegression | |
from sklearn.model_selection import GridSearchCV, train_test_split | |
from sklearn.preprocessing import MultiLabelBinarizer, MinMaxScaler | |
from sklearn.metrics import fbeta_score, precision_score, make_scorer, average_precision_score | |
import cv2 | |
import warnings | |
n_samples = 5000 | |
rescaled_dim = 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Co-occurence Matrix | |
com = np.zeros([len(counts)]*2) | |
for i, l in enumerate(list(counts.keys())): | |
for i2, l2 in enumerate(list(counts.keys())): | |
c = 0 | |
cy = 0 | |
for row in labels.values: | |
if l in row: | |
c += 1 | |
if l2 in row: cy += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np # linear algebra | |
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv) | |
import os | |
import gc | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
%matplotlib inline | |
pal = sns.color_palette() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Thanks to tinrtgu for the wonderful base script | |
Use pypy for faster computations.! | |
""" | |
import csv | |
from datetime import datetime | |
from csv import DictReader | |
from math import exp, log, sqrt |
NewerOlder