This file contains hidden or 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 pandas import DataFrame, Series | |
def compute_bounds(series: DataFrame) -> tuple: | |
Q1:Series = series.quantile(0.25) | |
Q3:Series = series.quantile(0.75) | |
IQR:np.float = Q3 - Q1 | |
lower_lim: float = Q1 - 1.5 * IQR | |
upper_lim: float = Q3 + 1.5 * IQR |
This file contains hidden or 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
""" | |
So what’s the difference between Generator Expressions and List Comprehensions? | |
The generator yields one item at a time and generates item only when in demand. | |
Whereas, in a list comprehension, Python reserves memory for the whole list. | |
Thus we can say that the generator expressions are memory efficient than the lists. | |
Ref: https://www.geeksforgeeks.org/python-list-comprehensions-vs-generator-expressions/ | |
""" | |
from sys import getsizeof |
This file contains hidden or 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 sklearn.model_selection import train_test_split | |
from sklearn.metrics import confusion_matrix | |
from sklearn.preprocessing import LabelEncoder | |
import keras | |
from keras.models import Sequential | |
from keras.layers import Dropout, Flatten, Dense, BatchNormalization, Activation | |
from keras import metrics | |
from keras import backend as K |
This file contains hidden or 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 Customer: | |
__slots__ = ['member_discount'] | |
def __init__(self, member_discount:float): | |
self.member_discount = member_discount | |
class Product: | |
__slots__ = ['_price', '_discounted_price', '_color_way'] |
This file contains hidden or 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
STATIC_MAKE_URL = 'https://foo.com/make/' | |
STATIC_CANCEL_URL = 'https://foo.com/cancel/' | |
class AppointmentMaker: | |
__slots__ = ['_status', '_response', '_url'] | |
def make_request(self, url:str, http_method:str='POST') -> dict: # -> instance method | |
# TODO: make a request | |
return {} | |
This file contains hidden or 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
# double | |
6 // 2.5 # -> 2.0 | |
# single | |
6 / 2.5 # -> 2.4 |
This file contains hidden or 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
""" | |
Background: | |
Pure functions are functions that have no side effects and always perform | |
the same computation resulting in the same ouput, given a set inputs. These | |
functions should only ever have access to the function scope. (1) | |
Static Methods (using @staticmethod decorator) can conceptually be treated as | |
"pure" since they do not have access to the either `cls` or `self` and must in | |
turn rely soley on input parameters to compute output. | |
""" |
This file contains hidden or 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
num = [1,2,3,4,5,6,7] | |
# explore modulo | |
for i in num: | |
print(i, i % 2 != 0) | |
# long form | |
def remove_even(List): | |
odds = [] | |
for i in List: |
This file contains hidden or 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 reverse_letters(thing:str) -> str: | |
return thing[::-1] | |
x = reverse_letters("foo bar baz") # => zab rab oof | |
print(x) | |
def reverse_words(str): | |
return " ".join(str.split()[::-1]) | |
y = reverse_words("foo bar baz") # => baz bar foo |