Skip to content

Instantly share code, notes, and snippets.

View pemagrg1's full-sized avatar
:octocat:
working...

Pema Gurung pemagrg1

:octocat:
working...
View GitHub Profile
@pemagrg1
pemagrg1 / one hot encoding using Keras
Created January 9, 2019 04:37
one hot encoding using Keras
from keras.preprocessing.text import Tokenizer
from numpy import array
from numpy import argmax
from keras.utils import to_categorical
doc = "Can I eat the Pizza".lower().split()
def using_Tokenizer(doc):
# create the tokenizer
@pemagrg1
pemagrg1 / one hot encoding using sklearn
Created January 9, 2019 04:36
one hot encoding using sklearn
from numpy import array
from numpy import argmax
from sklearn.preprocessing import LabelEncoder
from sklearn.preprocessing import OneHotEncoder
# define example
# data = ['cold', 'cold', 'warm', 'cold', 'hot', 'hot', 'warm', 'cold', 'warm', 'hot']
doc1 = "Can I eat the Pizza".lower()
doc2 = "You can eat the Pizza".lower()
@pemagrg1
pemagrg1 / one hot encoding using numpy
Created January 9, 2019 04:31
one hot encoding using numpy
import numpy as np
docs = "Can I eat the Pizza".lower().split()
doc1 = set(docs)
doc1 = sorted(doc1)
print ("\nvalues: ", doc1)
integer_encoded = []
for i in docs:
v = np.where( np.array(doc1) == i)[0][0]
integer_encoded.append(v)