Skip to content

Instantly share code, notes, and snippets.

View Proteusiq's full-sized avatar

Prayson Wilfred Daniel Proteusiq

View GitHub Profile
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
@Proteusiq
Proteusiq / tasker.py
Created April 11, 2019 10:36
tasker.py
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)
@Proteusiq
Proteusiq / img.py
Created April 12, 2019 13:05
img.py
import random
from PIL import Image
import requests
import images
listofimages = [item for key, item in images.images.items()]
# 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
@Proteusiq
Proteusiq / blockchain.py
Created July 28, 2019 10:32
blockchain.py
from datetime import datetime
import json
import hashlib
import uuid
from itsdangerous import URLSafeSerializer
class Block:
'''Basic Block Chain
@Proteusiq
Proteusiq / basic_linear.py
Created August 18, 2019 07:24
basic_linear.py
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):
@Proteusiq
Proteusiq / get_faces.py
Created September 8, 2019 12:36
face detection with CNN
###################################################
# conda create -n opencnn python=3.7 tensorflow #
# conda activate opencnn #
# pip install opencv-python mtcnn #
###################################################
import logging
import os
import cv2
@Proteusiq
Proteusiq / geo.py
Created September 25, 2019 05:32
geo.py
# 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()
@Proteusiq
Proteusiq / binet_fib.py
Created January 23, 2020 06:49
binet_fib.py
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))
@Proteusiq
Proteusiq / events_change.py
Created August 23, 2020 06:11
events_change.py
# 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