Skip to content

Instantly share code, notes, and snippets.

View adityajn105's full-sized avatar

Aditya Jain adityajn105

View GitHub Profile
@adityajn105
adityajn105 / competitions_tips_templates.md
Last active April 26, 2022 03:02
Useful programming templates implemented in python 3

General Snippets

1. Prime Factors of a number

  • Step1 : divide number by 2 and add 2 as factor till possible
  • Step2 : Start k from 3 with step of 2 till sqrt(number), divide number by k and add k as factor till possible
  • Step3 : Check if number remaining is greater than 1, add that number as another factor.
def getPrimeFactors(n):
    factors = []
    while n%2==0:
        factors.append(2)
@adityajn105
adityajn105 / policy_iteration.py
Last active October 18, 2018 11:08
Policy Optimization using policy iterations and value iterations.
"""
Author : Aditya Jain
Contact: https://adityajn105.github.io
"""
import gym
import numpy as np
#create game
game = gym.make('FrozenLake-v0')
#get game env object
@adityajn105
adityajn105 / Helloworld.scala
Created November 1, 2018 11:45
A tutorial to quickly revise Scala syntax and features
/*
* Scala - Scalable Language, hybrid functional Programming language
* Integrates features of OOP and functional languages
* Compliled on JVM
* Can use all classes of JAVA SDK and also own custom classes
* Some different features from JAVA
* 1. All types are objects
* 2. Tpye inference
* 3. Nested Functions
@adityajn105
adityajn105 / pandas.md
Last active December 4, 2018 05:47
Pandas Fundamentals and Advanced

Axis in Dataframes

  1. Axis 0 means along row ( for a particular feature of all samples ) |/
  2. Axis 1 means along columns (of a particular sample for all features ) --->
  3. Remember this by a matrix 2x3 matrix. Here axis 0 has length 2 and axis 1 has length 1

Groupby

  1. Perform aggregation on one or more than one columns
  2. If more than one column in used then it is considered as multi-indexing

df.groupby( columns ).colname.aggfunc()

@adityajn105
adityajn105 / hypothesis_testing_demo_datalit_week_2.ipynb
Last active April 26, 2019 07:28
Hypothesis_Testing_Demo.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@adityajn105
adityajn105 / webscrapper.py
Last active June 1, 2019 14:16
A web scrapping tutorial
from bs4 import BeautifulSoup
import urllib3
import re
import pandas as pd
http = urllib3.PoolManager()
link = "https://www.sitejabber.com/reviews/dream11.com"
#making http get request
@adityajn105
adityajn105 / System Design.md
Created October 12, 2019 05:08 — forked from vasanthk/System Design.md
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
def settleDebt(debt_dict):
"""
Function to settle debt among group of people
Parameters
----------
debt_dict : dictionary of names and debt(expenses-paid)
sum of debts should be approximately zero
-ve means negative debt, +ve means positive debt
@adityajn105
adityajn105 / app.py
Created February 22, 2020 13:42
Flask Simple File Uploader
from flask import Flask, request
from werkzeug import secure_filename
import os
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = os.path.join(app.root_path,'uploads/')
if not os.path.exists(app.config['UPLOAD_FOLDER']): os.mkdir(app.config['UPLOAD_FOLDER'])
def make_page(notification=""):
return f"""
# Decile chart, LIFT, KS
def getDeciles(models, X, y, n=10):
probs = predict_probas(gbms,X)[:,1]
cuts = pd.qcut(probs,n)
df = pd.DataFrame({'DECILE':cuts,"P":probs,'Y':y}).groupby('DECILE').Y.value_counts().unstack(fill_value=0)[::-1]
df.index = [ f"{i+1} {df.index[i]}" for i in range(n) ]
df.columns = ['ZEROS','ONES']
df['POPULATION'] = df.ZEROS+df.ONES
df['EVENT_RATE'] = df.ONES/df.POPULATION
df['CUMULATIVE_EVENT_RATE'] = df.ONES.cumsum()/df.POPULATION.cumsum()