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
# Here we view that many random trials result in a Gaussian Distribution. | |
# first we create random vector and resize it be a matrix | |
d2 <- runif(4000,-1,2) | |
dim(d2) <- c(100,40) | |
#wanna see my d2? | |
head(d2) | |
#now we bind the a new column rowsum to the original matrix (Column 41!) |
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
pip install --upgrade pip | |
pip install jupyter |
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
# Download heroku database dump and run pg restore on it to populate local db | |
## Source: https://medium.com/coding-blocks/creating-user-database-and-adding-access-on-postgresql-8bfcd2f4a91e | |
## link: https://data.heroku.com/datastores/ | |
# prep: download the heroku dump from heroku > Databases > durability | |
psql | |
postgres=# drop database if exists replace_this_with_your_database_name; | |
postgres=# create database replace_this_with_your_database_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
# install libpostal v1.1-alpha. Environment: MacOS 10.14 Python 3.6 | |
# libpostal library instructions didn't work for me, got error: | |
# ERR Error loading transliteration module, dir=(null) at libpostal_setup_datadir (libpostal.c:266) errno: No such file or directory | |
# Here is a workaround: | |
git clone https://github.com/openvenues/libpostal | |
cd libpostal | |
./bootstrap.sh |
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://pymotw.com/2/collections/namedtuple.html | |
# doc: https://docs.python.org/3.7/library/collections.html#collections.namedtuple | |
import collections | |
Person = collections.namedtuple('Person', field_names=['name', 'age', 'gender']) | |
filip = Person(name='Filip', age=101, gender='undisclosed') | |
print(filip.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
# Conda cheatsheet | |
# Conda create new environment | |
conda create -n myenvname python=3.7 | |
# Add conda environment to jupyter | |
python -m ipykernel install --user --name myenvname --display-name "Python (myenvname)" | |
# Conda create new environment and install datascience packages | |
conda create -n myenvname python=3.7 jupyter ipykernel nb_conda pandas geopandas shapely numpy scipy |
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
# pip cheatsheet | |
# pip install from requirements | |
pip install -r requirements.txt |
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 keras | |
# Integer to categorical | |
keras.utils.to_categorical(4, num_classes=5, dtype='int') |
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. Use f-strings | |
#instead of this | |
name = 'projects/{}/locations/us-central1/models/{}'.format(project_id, model_id) | |
# do this | |
name = f'projects/{project_id}/locations/us-central1/models/{model_id}' | |
# 2. Explicitly name errors: | |
# instead of this | |
try: |
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. Apply works with multiple arguments | |
## instead of this | |
binary_test["prediction"] = binary_test["sentence"].apply(lambda x: get_prediction(x, PROJECT_ID, BINARY_MODEL_ID)) | |
## do this | |
binary_test["prediction"] = binary_test["sentence"].apply(get_predictions, project_id=PROJECT_ID, model_id=BINARY_MODEL_ID |
OlderNewer