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 nth_percentile(dataset, percentile = 90): | |
sorted_dataset = sorted(dataset) | |
new_length = len(sorted_dataset) * percentile / 100 | |
return sorted_dataset[0:new_length] | |
def mean(dataset): | |
return sum(dataset)/float(len(dataset)) | |
dataset = [5, 9, 7, 101, 4, 8, 109, 104, 6, 1, 110, 106, 3, 107, 105, 2, 102, 10, 103, 108] | |
percentile_90 = nth_percentile(dataset) |
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 mongoengine import * | |
>>> class FacebookUser(Document): | |
... meta = { "allow_inheritance": False } | |
... facebook_id = StringField(primary_key = True, max_length = 20) | |
... | |
>>> connect("test") | |
Connection('localhost', 27017) | |
>>> FacebookUser.objects.delete() | |
>>> FacebookUser.objects | |
[] |
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 mongoengine import * | |
>>> class FacebookUser(Document): | |
... meta = { "allow_inheritance": False } | |
... facebook_id = StringField(primary_key = True, max_length = 20) | |
... name = StringField() | |
... def __unicode__(self): | |
... return u"/".join((self.facebook_id, self.name or u"")) | |
... | |
>>> connect("test") | |
Connection('localhost', 27017) |
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 division, print_function | |
import numpy as np | |
women_ratio = 0.513 # ratio of women in the US | |
min_ratio = 0.49 # roughly 5% more than women_ratio | |
max_ratio = 0.54 # roughly 5% less than women_ratio | |
sample_size = 1000 | |
n_samples = 10000 | |
#################################### |
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 tensorflow as tf | |
>>> X = tf.placeholder(shape=[None, 5], dtype=tf.float32, name="X") | |
>>> with tf.variable_scope("layer1"): | |
... hidden1 = tf.layers.dense(X, 100, name="hidden1") | |
... bn1 = tf.layers.batch_normalization(hidden1) | |
... | |
>>> for v in tf.global_variables(): | |
... print(v.name) | |
... | |
layer1/hidden1/kernel:0 |
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 division, print_function | |
import tensorflow as tf | |
""" | |
This program tries to test whether or not TensorFlow implements an inter-op thread pool on GPUs. In other words, | |
it checks whether or not operations that don't depend on each other can actually run in parallel. | |
To check this, it creates a TensorFlow graph that computes 1 + 1/2 + 1/4 + 1/8 + ... | |
There are two variables `x` and `y`, and two operations that modify these variables: | |
* `add` computes x <- x + y | |
* `divide` computes y <- y / 2 |
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 tensorflow as tf | |
tf.enable_eager_execution() | |
import tensorflow.contrib.eager as tfe | |
# predict the future | |
tf.function = tfe.defun # I vote for that name | |
tf.method = tfe.defun # Okay for what we will use it for | |
tf.Checkpointable = tfe.Checkpointable |
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
(tf2) ageron@macmix:~/dev/py/ml/kiwisoft_courses/dl_course$ python | |
Python 3.6.6 (default, Jun 28 2018, 05:43:53) | |
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> import shutil | |
>>> import numpy as np | |
>>> import tensorflow as tf | |
>>> from tensorflow import keras | |
>>> | |
>>> X_train = np.random.rand(1000, 10) |
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
""" | |
Usage: | |
>>> for pid, name in search_procs_by_name("python").items(): | |
... print(pid, name) | |
... | |
11882 python3.6 | |
47599 python3.6 | |
51877 python3.6 | |
51924 python3.6 |
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
#!/bin/bash | |
cat <<EOF > install_cuda_10_and_nvidia_driver_384.sh | |
#!/bin/bash | |
apt-get update && apt-get install -y --no-install-recommends gnupg2 curl ca-certificates && \ | |
curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub | apt-key add - && \ | |
echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/cuda.list && \ | |
echo "deb https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/nvidia-ml.list | |
export CUDA_VERSION=10.0.130 |
OlderNewer