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 sklearn.base import BaseEstimator, ClassifierMixin | |
class HurdleRegression(BaseEstimator, ClassifierMixin): | |
'''Regression classifier that deals with large amount of zeros | |
Finds the probabilites of zeros and multiply with predicted regression''' | |
def __init__(self, cls_model, reg_model, cls_params=None, reg_params=None): | |
''' | |
Called when initializing the classifier |
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 functools import singledispatch | |
@singledispatch | |
def tasks(arg, verbose=False): | |
if verbose: | |
print(f'{arg} pong! Title it is.') | |
return arg.title() | |
@tasks.register(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
import random | |
from PIL import Image | |
import requests | |
import images | |
listofimages = [item for key, item in images.images.items()] | |
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
# Update and Upgrade | |
sudo apt update && sudo apt upgrade --yes | |
# Get Miniconda and make it the main Python interpreter | |
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh | |
bash ~/miniconda.sh -b -p ~/miniconda | |
# Remove the script | |
rm ~/miniconda.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
from datetime import datetime | |
import json | |
import hashlib | |
import uuid | |
from itsdangerous import URLSafeSerializer | |
class Block: | |
'''Basic Block Chain | |
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 numpy as np | |
import matplotlib.pyplot as plt | |
plt.style.use('ggplot') | |
def get_yhats(weight,bias, predictors): | |
return bias + weight*predictors | |
def mse(predicted_values,actual_values): |
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
# simple script to get lats and lngs from address | |
# auth.py contains a variable GOOGLEMAPKEY with | |
# Googlemap API key(auth.py must be gitignored as | |
# it plays the role of os.environ) | |
import requests | |
import auth | |
s = requests.Session() |
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
def binet(n): | |
''' Binet's Formula | |
Deduce the nth Fibonacci number, without calculating the preceding numbers. | |
''' | |
PHI = (1 + 5**0.5)/2 | |
return int(round((PHI**n - (1-PHI)**n) / 5**0.5)) | |
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
# Advance Python: Tips and Tricks | |
# Author: Prayson W. Daniel (github.com/proteusiq) | |
# Objective: We want functions to be activate/executed when we experience change in X | |
# Note: we can run functions in threads or asynchronic to avoid blocking (if that's wanted behavior) | |
from events import Events | |
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
''' | |
Example of Wrappers | |
''' | |
from functools import wraps | |
from datetime import datetime | |
import time | |
def verbose_timeit(func): | |
@wraps(func) |