Skip to content

Instantly share code, notes, and snippets.

View s9k96's full-sized avatar
🏠
Working from home

Shubham Saxena s9k96

🏠
Working from home
  • Fractal Analytics
  • New Delhi
View GitHub Profile
@s9k96
s9k96 / iterative_vif_view.py
Created July 12, 2023 12:14
Given a pandas dataframe of n columns, and we want to iteratively drop columns which are linearly dependent on other columns. Snippet is to calculate Variance inflation factor of each column and drop the column having max VIF at each iteration. It'll return a view showing all the column names and their vif values at each iteration, so we can see…
import pandas as pd
from statsmodels.stats.outliers_influence import variance_inflation_factor
def get_vif(X, drop_cols = []):
X = X.drop(columns = drop_cols).dropna()
vif_data = pd.DataFrame()
vif_data['feature'] = X.columns
vif_data['VIF'] = [variance_inflation_factor(X.values, i) for i in range(len(X.columns))]
return vif_data.sort_values(by = 'VIF').reset_index(drop=True)
x = np.arange(0,10)
y = [10,8,7,8,6,5,4,4,3,13]
fig, ax = plt.subplots(figsize = (15,10))
line, = ax.plot(x, y, 'bo--', color='k')
plt.grid()
def update(num, x, y, line):
line.set_data(x[:num+1], y[:num+1])
line.set_animated(True)
color = 'black'
@s9k96
s9k96 / slack-notify.py
Created July 13, 2020 06:32
Send notifications to a slack channel through slack webhooks.
# Send notifications to a slack channel through slack webhooks.
import requests
import json
webhook = '' # Slack channel webhook.
def notify_slack(message):
"""
Send a string to slack channel.
message: str
@s9k96
s9k96 / aws-lambda-start-ssh.py
Created July 10, 2020 15:59
Lambda function for starting an already set EC2 instance and ssh-ing into it using Paramiko library.
"""
Lambda function for starting an already set EC2 instance and ssh-ing into it using Paramiko library.
Paramiko is installed on lambda using lambda layers.
"""
import json
import paramiko
import boto3
region = ''
@s9k96
s9k96 / aws-lambda-start-stop-instance.py
Created July 10, 2020 15:51
Lambda function script to list/start/stop an EC2 Instance.
"""
Lambda function to switch on/off an ec2 instance.
Event can be passed like:
{
"action" : "list" -> to list all the instances.
: "start" -> to start a already set instance.
: "stop" -> to stop a alreadt set instance.
}
"""