Skip to content

Instantly share code, notes, and snippets.

@mrahul17
mrahul17 / clean.py
Last active January 24, 2016 07:57
Pandas utility scripts
#check if na values exist at all
df.isnull().any().any()
#if above returns true for any series
df.isnull().any()
#check for NA values
data.isnull().sum()
#replace NA values
# for real values
@mrahul17
mrahul17 / ml.py
Last active January 23, 2016 16:14
scikit-learn utility scripts
# train-test split
from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.4)
#get accuracy score
print metrics.accuracy_score(y,predict_y)
#get optimum value of k in knn
k_range = range(1,26)
scores = []
@mrahul17
mrahul17 / label_encode.py
Created February 5, 2016 04:47
Label encoder
def clean_data(train,test):
obj_cols = [] #list to store columns that have been read as objects
for col in train.columns:
if train[col].dtype==object:
obj_cols.append(col)
preprocessor = preprocessing.LabelEncoder()
for col in obj_cols:
preprocessor.fit(list(train[col].values) + list(test[col].values))
train[col] = preprocessor.transform(list(train[col].values))
@mrahul17
mrahul17 / fimp_xgboost.py
Last active May 31, 2017 22:20
Feature importance in XGBoost
# credits @mmueller https://www.kaggle.com/mmueller/liberty-mutual-group-property-inspection-prediction/xgb-feature-importance-python/code
import pandas as pd
import xgboost as xgb
import operator
from matplotlib import pylab as plt
def ceate_feature_map(features):
outfile = open('xgb.fmap', 'w')
i = 0
for feat in features:
@mrahul17
mrahul17 / samples.txt
Last active February 16, 2016 05:05
Code that I have to read
https://github.com/Far0n/kaggle-homesite/blob/master/top15_homesite_xgb.py
https://github.com/matefh/kaggle-homesite/blob/master/model.r
@mrahul17
mrahul17 / binary-search-tree-cpp.cpp
Created March 9, 2016 14:02 — forked from mgechev/binary-search-tree-cpp.cpp
Simple implementation of binary search tree in C++.
#include <iostream>
#include <math.h>
using namespace std;
template <class T>
struct Node {
T value;
Node *left;
Node *right;
@mrahul17
mrahul17 / encrypting.txt
Last active April 15, 2017 09:45
Encrypting Files in Linux
#Taken from
#http://askubuntu.com/questions/160253/encrypting-decrypting-a-single-file-in-ubuntu-12-04-lts/160334
Encrypt--> openssl des3 < youfile.txt > yourfile.txt.des3
Decrypt--> openssl des3 -d < yourfile.txt.des3 > yourfile.txt.decrypted
#http://stackoverflow.com/questions/16056135/how-to-use-openssl-to-encrypt-decrypt-files?noredirect=1&lq=1
Encrypt --> gpg --output encrypted.data --symmetric --cipher-algo AES256 un_encrypted.data
Decrypt --> gpg --output un_encrypted.data --decrypt encrypted.data
@mrahul17
mrahul17 / installer.sh
Last active March 26, 2016 15:48
bash script to install all packages I had on my previous machine
#! /bin/sh
sudo add-apt-repository ppa:kilian/f.lux
sudo add-apt-repository ppa:gnome-terminator
sudo apt-get update
# install dropbox
cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86_64" | tar xzf -
~/.dropbox-dist/dropboxd
@mrahul17
mrahul17 / configs.txt
Last active April 30, 2016 01:59
List of config files that I am modifying
~/.bash_funcs
~/.bashrc
~/.bash_completion
/etc/rc.local
/etc/bluetooth/main.conf
/etc/sudoers
@mrahul17
mrahul17 / redshift.conf
Last active April 1, 2016 04:49 — forked from bcomnes/redshift.conf
My configuration file for Redshift. Place it in ~/.config/ Drag redshift onto the Startup Applications menu to have it boot on start
; Global settings
[redshift]
temp-day=6500K
temp-night=5000
transition=1
;gamma=0.8:0.7:0.8
gamma=1.000:1.000:1.000
;location-provider=geoclue (no more internet connection required!!)
location-provider=manual
adjustment-method=vidmode