Skip to content

Instantly share code, notes, and snippets.

View housecricket's full-sized avatar

Dang Trung Anh housecricket

View GitHub Profile
with ProgressBar():
print(nyc_data_raw.drop('total_amount', axis=1).head())
...
# load all datasets
(azData, azLabels) = load_az_dataset(args["az"])
(digitsData, digitsLabels) = load_zero_nine_dataset()
# the MNIST dataset occupies the labels 0-9, so let's add 10 to every A-Z label to ensure the A-Z characters are not incorrectly labeled as digits
azLabels += 10
# stack the A-Z data and labels with the MNIST digits data and labels
data = np.vstack([azData, digitsData])
def load_zero_nine_dataset():
# load the MNIST dataset and stack the training data and testing
# data together (we'll create our own training and testing splits
# later in the project)
((trainData, trainLabels), (testData, testLabels)) = mnist.load_data()
data = np.vstack([trainData, testData])
labels = np.hstack([trainLabels, testLabels])
# return a 2-tuple of the MNIST data and labels
return (data, labels)
def load_az_dataset(dataset_path):
# initialize the list of data and labels
data = []
labels = []
# loop over the rows of the A-Z handwritten digit dataset
for row in open(dataset_path):
# parse the label and image from the row
row = row.split(",")
label = int(row[0])
# TensorFlow and tf.keras
import tensorflow as tf
from tensorflow.keras.applications.resnet50 import preprocess_input, decode_predictions
from tensorflow.keras.preprocessing import image
# Helper libraries
import numpy as np
import matplotlib.pyplot as plt
/*
* s, d, e represents three pegs (source, destination and extra).
* n is number of discs (All initially in s)
*/
resolver_tower_of_hanoi = function (s, d, e, n) {
// terminating condition
if (n <= 0) {
return
look_for_key = function(box) {
for (item in box) {
if (item.is_a_key()) {
print("found the key")
} else {
look_for_key(item)
}
}
}
// ✗ avoid
function animal () { ... }
// ✓ ok
function Animal () { ... }
// ✓ ok
if (flag) {
// ...
} else {
// ...
}
// ✗ avoid
if (obj.prop) { .. }
if (obj.prop !== undefined) { ... }
// ✓ ok
if (Object.prototype.hasOwnProperty.call(obj, 'prop')) { ... }