PySpark: Beware of Python Mutable Objects
Published:
Tags:
Summary: We should be careful when dealing with python mutable objects. For example, make copies of python mutable objects in pyspark udfs.
PySpark: Compare Two Schemas
Published:
Tags:
Summary: To compare two dataframe schemas in [[PySpark]] Data Processing - (Py)Spark Processing Data using (Py)Spark , we can utilize the set operations in python.
def schema_diff(schema1, schema2): return { 'fields_in_1_not_2': set(schema1) - set(schema2), 'fields_in_2_not_1': set(schema2) - set(schema1) }
Differential Learning Rates in PyTorch
Published:
Tags:
References:
- Pointer I. Programming PyTorch for deep learning: Creating and deploying deep learning applications. Sebastopol, CA: O’Reilly Media; 2019.
- torch.optim — PyTorch 1.10.0 documentation. [cited 30 Nov 2021]. Available: https://pytorch.org/docs/stable/optim.html
Summary: Using different learning rates in different layers of our artificial neural network.
VSCode Terminal Python Can Not Activate Conda on Mac
Published:
Tags:
Summary: Enable your key repeat in vscode on mac
VSCode Setup Tests when Module is in a Different Folder
Published:
Tags:
References:
- Using Python environments in VS Code
Summary: Use .env file
Postgres Timezone Conversions
Published:
Tags:
References:
- kadkaz. Postgres AT TIME ZONE function shows wrong time? In: Stack Overflow [Internet]. [cited 27 Aug 2021]. Available: https://stackoverflow.com/questions/27938857/postgres-at-time-zone-function-shows-wrong-time
- 8.5. Date/Time Types. In: PostgreSQL Documentation [Internet]. 12 Aug 2021 [cited 27 Aug 2021]. Available: https://www.postgresql.org/docs/current/datatype-datetime.html
- Time Zones. (2012, January 1). PostgreSQL Documentation. https://www.postgresql.org/docs/7.2/timezones.html
- Momjian B. Postgres AT TIME ZONE Explained. In: EDB [Internet]. 7 Nov 2019 [cited 27 Aug 2021]. Available: https://www.enterprisedb.com/postgres-tutorials/postgres-time-zone-explained
Summary: Pitfals of timezone conversion in Postgres
Managing path using pathlib in Python
Published:
Tags:
Summary: It is a convinient package to manage path and files
Deal with Rare Categories Using Pandas
Published:
Tags:
References:
- pandas.DataFrame.mask
Summary: Deal with rare categories using pandas
Binning Data Values using Pandas
Published:
Tags:
References:
- pandas.cut
Summary: Convert continuous values into bins in pandas
PyTorch: Initialize Parameters
Published:
Tags:
Summary: We can set the parameters in a for loop. We take some of the initialization methods from Lippe1.
To set based on the input dimension of the layer ( [[Initialize Artificial Neural Networks]] Initialize Artificial Neural Networks Initialize a neural network is important for the training and performance. Some initializations simply don't work, some will degrade the performance of the model. We should choose wisely. ) (normalized initialization),
for name, param in model.named_parameters(): if name.endswith(".bias"): param.data.fill_(0) else: bound = math.sqrt(6)/math.sqrt(param.shape[0]+param.shape[1]) param.data.uniform_(-bound, bound) or set the parameters based on the input size of each layer
for name, param in model.named_parameters(): if name.
Three dots in Python
Published:
Tags:
Summary: Use three dots as placeholder for python empty function
Ordered Member Functions of a Class in Python
Published:
Tags:
References:
- Can I add attributes to class methods in Python?
Summary: Build an ordered list of methods in a python class by adding attributes to member functions
Postgres Optimization in JOIN
Published:
Tags:
Summary: Join tables together starting with the smallest table (table with less cardinality) speeds things up.
Pandas Groupby Does Not Guarantee Unique Content in Groupby Columns
Published:
Tags:
Summary: Pandas Groupby Does Not Guarantee Unique Content in Groupby Columns, it also considers the datatypes. Dealing with mixed types requires additional attention.
Switch statement in Python
Published:
Tags:
References:
- Dispatch Tables in Python
Summary: Love switch statement? We can design a switch statement it in python.
Python Tilde Operator
Published:
Tags:
References:
- The tilde operator in Python @StackOverflow
Summary: tilde operator may not work as you expected
Arrays and Dicts in MongoDB
Published:
Tags:
Summary: Array of dictionaries becomes hard to update in MongoDB.