Skip to content

Instantly share code, notes, and snippets.

View vikramsoni2's full-sized avatar

Vikram vikramsoni2

View GitHub Profile
@vikramsoni2
vikramsoni2 / dynamic_dns_cloudflare.sh
Last active May 27, 2021 10:49
update your dynamic ip address automatically to cloudflare dns using cloudflare API
#!/bin/sh
domain="MY_DOMAIN_NAME"
email="CLOUDFLARE_EMAIL"
global_api_key="GLOBAL_API_KEY"
zone_id="ZONE_ID_FOR_DOMAIN"
ip_file="/var/log/dyndns.log"
ipOld=$(cat $ip_file)
ipNow=$(curl ifconfig.co/)
@vikramsoni2
vikramsoni2 / brcmfmac43455-sdio.txt
Created January 28, 2021 13:51
brcmfmac43455-sdio.txt wifi firmware
# Cloned from bcm94345wlpagb_p2xx.txt
NVRAMRev=$Rev: 498373 $
sromrev=11
vendid=0x14e4
devid=0x43ab
manfid=0x2d0
prodid=0x06e4
#macaddr=00:90:4c:c5:12:38
macaddr=b8:27:eb:74:f2:6c
nocrc=1
@vikramsoni2
vikramsoni2 / confusion_matrix.py
Created March 25, 2021 03:05
Multiclass confusion matrix using Seaborn heatmap
y_true = le.inverse_transform(y_valid)
y_pred = le.inverse_transform(y_valid_pred_lr)
from sklearn.metrics import confusion_matrix
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
data = confusion_matrix(y_true, y_pred)
@vikramsoni2
vikramsoni2 / remove_highly_correlated_features.py
Created May 12, 2021 13:22
Remove Highly Correlated Features
def remove_highly_correlated_features(df = None, ths=0.99):
print("The data has : {} features ".format(len(list(df))))
correlations = df.corr()
mask = np.triu(np.ones_like(correlations, dtype=bool))
corr_matrix = correlations.abs()
# Create a True/False mask and apply it
mask = np.triu(np.ones_like(corr_matrix, dtype=bool))
tri_df = corr_matrix.mask(mask)
# List column names of highly correlated features (r >0.98 )
to_drop = [c for c in tri_df.columns if any(tri_df[c] > ths)]
@vikramsoni2
vikramsoni2 / contractions.py
Created June 28, 2021 00:04
contractions english
contractions = {
"ain't": "am not",
"aren't": "are not",
"can't": "cannot",
"can't've": "cannot have",
"'cause": "because",
"could've": "could have",
"couldn't": "could not",
"couldn't've": "could not have",
"didn't": "did not",
@vikramsoni2
vikramsoni2 / plot_keras_history.py
Created June 28, 2021 04:02
plotting train vs valid metrics in line plot
metrics_names = ['loss', 'accuracy', 'top10_accuracy']
plt.figure(figsize=(14,4))
sns.set_style('whitegrid')
for i in range(len(metrics_names)):
ax = plt.subplot(1, len(metrics_names), i+1)
ax.plot(history.history[metrics_names[i]], label="train")
ax.plot(history.history['val_'+ metrics_names[i]], label="valid")
ax.title.set_text(metrics_names[i])
@vikramsoni2
vikramsoni2 / remove_top_level_dir_unzip.py
Created July 10, 2021 02:08
extract zip file containing github repo witout the top level directory
from requests import get
from io import BytesIO
from zipfile import ZipFile
import os
from pathlib import Path
destination = "testproject"
file_url = 'https://github.com/vikramsoni2/aihubcli/archive/refs/heads/main.zip'
@vikramsoni2
vikramsoni2 / custom_format_logger.py
Created July 10, 2021 22:43
logging formats based on log levels
import logging
from bisect import bisect
from logging import getLogger, Formatter, LogRecord, StreamHandler
from typing import Dict
class LevelFormatter(Formatter):
def __init__(self, formats: Dict[int, str], **kwargs):
super().__init__()
@vikramsoni2
vikramsoni2 / lightgbm_custom_feval.py
Created July 19, 2021 12:33
custom eval metric function for lightgbm cv. calculating top K accuracy
def top_10_accuracy(preds, train_data, is_higher_better=True):
y_preds = np.asarray(preds).reshape(-1, len(np.unique(y)))
y_true = train_data.get_label()
score = top_k_accuracy_score(y_true, y_preds, k=10)
return ('top_10_accuracy', score, True)
@vikramsoni2
vikramsoni2 / parallel_coord.py
Last active March 2, 2022 15:22
parallel coordinates plot using matplotlib
import numpy as np
import pandas as pd
from matplotlib.path import Path
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import seaborn as sns
from typing import Union, List, Tuple
def parallel_coordinates(df: pd.DataFrame,