As of July 2018, Raspbian does not yet include the latest Python release, Python 3.7.4. This means we will have to build it ourselves, and here is how to do it.
- Install the required build-tools (some might already be installed on your system).
// This code is related to PR https://github.com/apache/spark/pull/17461 | |
// I show how to use the setInitialModel() param of LDA to build a model incrementally, | |
// and I compare the performance (perplexity) with a model built in one-shot | |
import scala.collection.mutable | |
import org.apache.spark.ml.{Pipeline, PipelineModel} | |
import org.apache.spark.ml.clustering.{LDA, LDAModel} |
def time[T](block: => T): T = { | |
val start = System.currentTimeMillis | |
val res = block | |
val totalTime = System.currentTimeMillis - start | |
println("Elapsed time: %1d ms".format(totalTime)) | |
res | |
} |
import matplotlib.pyplot as plt | |
import numpy as np | |
def show_images(images, cols = 1, titles = None): | |
"""Display a list of images in a single figure with matplotlib. | |
Parameters | |
--------- | |
images: List of np.arrays compatible with plt.imshow. | |
xgfs_normal6 = [(64, 83, 211), (221, 179, 16), (181, 29, 20), (0, 190, 255), (251, 73, 176), (0, 178, 93), (202, 202, 202)] | |
xgfs_normal12 = [(235, 172, 35), (184, 0, 88), (0, 140, 249), (0, 110, 0), (0, 187, 173), (209, 99, 230), (178, 69, 2), (255, 146, 135), (89, 84, 214), (0, 198, 248), (135, 133, 0), (0, 167, 108), (189, 189, 189)] | |
xgfs_bright6 = [(239, 230, 69), (233, 53, 161), (0, 227, 255), (225, 86, 44), (83, 126, 255), (0, 203, 133), (238, 238, 238)] | |
xgfs_dark6 = [(0, 89, 0), (0, 0, 120), (73, 13, 0), (138, 3, 79), (0, 90, 138), (68, 53, 0), (88, 88, 88)] | |
xgfs_fancy6 = [(86, 100, 26), (192, 175, 251), (230, 161, 118), (0, 103, 138), (152, 68, 100), (94, 204, 171), (205, 205, 205)] | |
xgfs_tarnish6 = [(39, 77, 82), (199, 162, 166), (129, 139, 112), (96, 78, 60), (140, 159, 183), (121, 104, 128), (192, 192, 192)] |
import pandas as pd | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
def print_confusion_matrix(confusion_matrix, class_names, figsize = (10,7), fontsize=14): | |
"""Prints a confusion matrix, as returned by sklearn.metrics.confusion_matrix, as a heatmap. | |
Note that due to returning the created figure object, when this funciton is called in a | |
notebook the figure willl be printed twice. To prevent this, either append ; to your | |
function call, or modify the function by commenting out the return expression. |
Automated analysis is the main advantage to working with a modern statically typed compiled language like C++. Code analysis tools can inform us when we have implemented an operator overload with a non-canonical form, when we should have made a method const, or when the scope of a variable can be reduced.
As of January 2018, Raspbian does not yet include the latest Python release, Python 3.6. This means we will have to build it ourselves, and here is how to do it. There is also an ansible role attached that automates it all for you.
from collections import defaultdict | |
from heapq import * | |
def dijkstra(edges, f, t): | |
g = defaultdict(list) | |
for l,r,c in edges: | |
g[l].append((c,r)) | |
q, seen, mins = [(0,f,())], set(), {f: 0} | |
while q: |