Skip to content

Instantly share code, notes, and snippets.

View crodriguez1a's full-sized avatar

Carlos Rodriguez crodriguez1a

View GitHub Profile
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
@crodriguez1a
crodriguez1a / lesson_generator_expressions.py
Last active September 20, 2019 13:06
Lesson - Generator Expressions
"""
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
@crodriguez1a
crodriguez1a / single_perceptron.py
Last active September 10, 2019 00:18
Single Perceptron (Shallow Network)
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
@crodriguez1a
crodriguez1a / lesson_setter_decorator.py
Last active July 3, 2019 13:43
Pythonic Getters and Setters
class Customer:
__slots__ = ['member_discount']
def __init__(self, member_discount:float):
self.member_discount = member_discount
class Product:
__slots__ = ['_price', '_discounted_price', '_color_way']
@crodriguez1a
crodriguez1a / lesson_classes.py
Last active June 28, 2019 15:06
Lesson - Classes (encapsulation, static methods/pure functions, inheritance)
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 {}
@crodriguez1a
crodriguez1a / quiz_div_float_int.py
Last active June 27, 2019 23:54
Division - Float vs Integer
# double
6 // 2.5 # -> 2.0
# single
6 / 2.5 # -> 2.4
@crodriguez1a
crodriguez1a / lessons_pure_functions_static_methods.py
Last active June 24, 2019 17:17
Pythonic Pure Functions with Static Methods
"""
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.
"""
@crodriguez1a
crodriguez1a / quiz_remove_even.py
Last active June 24, 2019 17:16
Python Learning Series: Remove Even Challenge
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:
@crodriguez1a
crodriguez1a / quiz_slicing.py
Last active June 24, 2019 17:20
Intermediate Python Quiz
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