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 rocker/ml:4.0.2 | |
USER rstudio | |
WORKDIR /home/rstudio/ | |
RUN Rscript -e 'devtools::install_github("Netflix/metaflow", subdir="R")' | |
RUN Rscript -e 'metaflow::install_metaflow(method="conda", prompt=FALSE)' | |
ENV USERNAME mfuser | |
RUN Rscript -e 'metaflow::test()' | |
USER root |
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 metaflow import FlowSpec, step, Parameter | |
def script_path(filename): | |
""" | |
A convenience function to get the absolute path to a file in this | |
tutorial's directory. This allows the tutorial to be launched from any | |
directory. | |
""" |
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
# Compute ROC curve and ROC area for each class in multi-class classification tasks | |
from sklearn.metrics import roc_curve, auc | |
from scipy import interp | |
from itertools import cycle | |
from typing import Tuple, List | |
def ROC(y_val: np.ndarray, y_score: np.ndarray) -> Tuple[dict, dict, dict]: | |
fpr = dict() |
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
# ask the node to always return the maxinum depth | |
# of the subtree that it is leading | |
Class MaxDepth: | |
def __init__(self): | |
pass | |
def max_depth(self, node): | |
# remember 1-2-3: | |
# here pre-order traversal is applied |
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
## ENTERING: if leaf, update self.max_depth & return | |
## Traversal: carries depth+1 around | |
Class MaxDepth: | |
def __init__(self): | |
self.max_depth = 0 | |
def max_depth(node, depth=0): | |
if not node: # empty tree or Null | |
return |
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 re | |
import pyarrow.parquet as pq | |
def query_unique_value(dataset: pq.ParquetDataset, | |
partition: str | |
) -> set: | |
''' query the unique values of a given partition name from a give `ParquetDataset`, returns a set. | |
Parameters | |
---------- |
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
# example class Circle showing the difference between | |
# decorator function @property, @classmethod, and | |
# @staticmethod | |
# source: https://realpython.com/primer-on-python-decorators/ | |
# pls credit the source if you choose to use this snippet | |
class Circle: | |
def __init__(self, radius): | |
self._radius = radius |
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
# source: https://realpython.com/primer-on-python-decorators/ | |
# please credit the source if you choose to use this snippet. | |
import functools | |
import time | |
def timer(func): | |
"""Print the runtime of the decorated function""" | |
@functools.wraps(func) | |
def wrapper_timer(*args, **kwargs): |