boto3_resource = boto3.resource
def boto3_mock_resource(service_name, region_name):
return boto3_resource(
service_name=service_name,
region_name=region_name,
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
class Vector(dict): | |
def __init__(self, a, b): | |
import uuid | |
self._load(a, b) | |
self.id = uuid.uuid4() | |
self.__name__ = 'Vector:' | |
def _build(self, a, b): | |
return Vector(a, b) | |
def _load(self, a, b): |
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
acumulator = [0, 0] | |
for _ in range(10**6): | |
mh = MontyHall() | |
mh.set_random_guess() | |
mh.open_goat_door() | |
mh.switch_door() # comment to don't swich | |
result = mh.validade_guess_door() | |
if result: acumulator[0] += 1 |
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
"""author: `Bernardo Costa <bernardoantunescosta at gmail.com>`""" | |
import random | |
class MontyHall: | |
"""Monty Hall Simulator Class.""" | |
def __init__(self): | |
self.doors = list('123') | |
self.reward_door = None |
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
"""Playing with primes.""" | |
def get_square_root(n): | |
"""Return square root of n.""" | |
return n ** (1.0 / 2) | |
def is_divisor(n, d): | |
"""Return True if n divides d, False otherwise.""" |
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 pandas as pd | |
# create sample dataset | |
columns = ['ID', 'Beer', 'Diaper', 'Gum', 'Soda', 'Snack'] | |
dataset = [[1, 1, 1, 1, 1, 0], | |
[2, 1, 1, 0, 0, 0], | |
[3, 1, 1, 1, 0, 1], | |
[4, 1, 1, 0, 1, 1], | |
[5, 0, 1, 0, 1, 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
# Running Apriori | |
if 'ID' in df.columns: del df['ID'] # ID is not relevant to apriori | |
apriori_runner = Apriori(df, threshold=0.4, transform_bol=True) | |
apriori_df = apriori_runner.run(use_colnames=True) | |
print(apriori_df) | |
#output | |
# support itemsets length |
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 mlxtend.frequent_patterns import apriori | |
class Apriori: | |
"""Apriori Class. Its has Apriori steps.""" | |
threshold = 0.5 | |
df = None | |
def __init__(self, df, threshold=None, transform_bol=False): | |
"""Apriori Constructor. |
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
# 1. open cloud shell | |
# 2. download the the resource lab named resources-echo-web.tar.gz | |
# 3. upload it in the cloud shell | |
# 4. extract the file | |
tar -xvzf resources-echo-web.tar.gz | |
# 5. build the image as v1 tag | |
docker build -t gcr.io/<PROJECT_ID>/echo-app:v1 . | |
# 6. check if the image was Built |
NewerOlder