Skip to content

Instantly share code, notes, and snippets.

View ariffyasri's full-sized avatar

Muhammad Ariff Yasri ariffyasri

View GitHub Profile
@ariffyasri
ariffyasri / reverse_dummies.py
Created July 25, 2018 03:53
reverse pandas dummies
def remove_column_name(value):
return value[value.rfind('_')+1:]
def check_categorical_column(columns):
dict_column_name = {}
for column in columns:
name = column[:column.rfind('_')]
dict_column_name.setdefault(name,[]).append(column)
return dict_column_name
@ariffyasri
ariffyasri / rem_outlier.py
Created December 11, 2017 01:13
Remove outliers in pandas
import pandas as pd
import numpy as np
from pandas.api.types import is_numeric_dtype
np.random.seed(42)
age = np.random.randint(20,100,50)
name = ['name'+str(i) for i in range(50)]
address = ['address'+str(i) for i in range(50)]
@ariffyasri
ariffyasri / print_cm.py
Last active September 5, 2017 07:10 — forked from ClementC/print_cm.py
from sklearn.metrics import confusion_matrix
def print_cm(cm, labels):
"""pretty print for confusion matrixes"""
# using str in len because of some label
# may using integer as label
columnwidth = max([len(str(x)) for x in labels])
# Print header
print(" " * columnwidth, end="\t")
for label in labels: