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
# check package versions | |
import sys | |
import keras | |
import cv2 | |
import numpy | |
import matplotlib | |
import skimage | |
print('Python: {}'.format(sys.version)) | |
print('Keras: {}'.format(keras.__version__)) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 sys | |
import sklearn | |
import matplotlib | |
import numpy as np | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
print(‘Python: {}’.format(sys.version)) | |
print(‘Sklearn: {}’.format(sklearn.version)) | |
print(‘Matplotlib: {}’.format(matplotlib.version)) |
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 keras.datasets import mnist | |
(x_train, y_train), (x_test, y_test) = mnist.load_data() | |
print(‘Training Data: {}’.format(x_train.shape)) | |
print(‘Training Labels: {}’.format(y_train.shape)) | |
Training Data: (60000L, 28L, 28L) | |
Training Labels: (60000L,) |
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
# convert each image to 1 dimensional array | |
X = x_train.reshape(len(x_train),-1) | |
Y = y_train | |
# normalize the data to 0 - 1 | |
X = X.astype(float) / 255. | |
print(X.shape) |
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.cluster import MiniBatchKMeans | |
n_digits = len(np.unique(y_test)) | |
print(n_digits) | |
# Initialize KMeans model | |
kmeans = MiniBatchKMeans(n_clusters = n_digits) | |
# Fit the model to the training data |
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
def infer_cluster_labels(kmeans, actual_labels): | |
inferred_labels = {} | |
for i in range(kmeans.n_clusters): | |
# find index of points in cluster | |
labels = [] | |
index = np.where(kmeans.labels_ == i) | |
# append actual labels for each point in cluster |
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
# Initialize and fit KMeans algorithm | |
kmeans = MiniBatchKMeans(n_clusters = 36) | |
kmeans.fit(X) | |
# record centroid values | |
centroids = kmeans.cluster_centers_ | |
# reshape centroids into images | |
images = centroids.reshape(36, 28, 28) | |
images *= 255 |
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
const Twitter = require('twitter'); | |
const createCsvWriter = require('csv-writer').createObjectCsvWriter; | |
const fs = require('fs'); | |
// set up Twitter API client | |
const client = new Twitter({ | |
// consumer_key: 'your_consumer_key', | |
// consumer_secret: 'your_consumer_secret', | |
// access_token_key: 'your_access_token_key', | |
// access_token_secret: 'your_access_token_secret' |