This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export FLASK_DEBUG=1 | |
export FLASK_APP=name-of-your-python-file-here.py | |
flask run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import pandas and numpy | |
import pandas as pd | |
import numpy as np | |
#create dataframe with some random data | |
df = pd.DataFrame(np.random.rand(10, 2) * 10, columns=['Price', 'Qty']) | |
#add a column with random string values that would need to have dummy variables created for them | |
df['City'] = [np.random.choice(('Chicago', 'Boston', 'New York')) for i in range(df.shape[0])] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Mac OS or Linux | |
conda create -n tensorflow python=3.5 | |
source activate tensorflow | |
pip install widgetsnbextension | |
conda install pandas matplotlib jupyter notebook scipy scikit-learn | |
conda install -c conda-forge tensorflow | |
//Windows | |
conda create -n tensorflow python=3.5 | |
activate tensorflow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Concise implementation | |
def softmax(inputs): | |
return np.exp(inputs) / np.sum(np.exp(inputs)) | |
#Verbose implementation (for clarification/understanding) | |
def softmax_verbose(inputs): | |
results = [np.exp(x) for x in inputs] | |
summation = sum(results) | |
probabilities = [(x / summation) for x in results] | |
return probabilities |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
def bag_of_words(text): | |
return Counter(text.split()) | |
test_text = 'the quick brown fox jumps over the lazy dog' | |
print(bag_of_words(test_text)) | |
#Output will be: Counter({'the': 2, 'jumps': 1, 'dog': 1, 'brown': 1, 'over': 1, 'quick': 1, 'fox': 1, 'lazy': 1}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
To save your work and exit press Esc and then :wq (w for write and q for quit). | |
Alternatively, you could both save and exit by pressing Esc and then :x | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create_text_lookup_tables = lambda text: ({c: i for i, c in enumerate(set(text))}, dict(enumerate(set(text)))) | |
vocab_to_int, int_to_vocab = create_text_lookup_tables(['this','is','my','test']) | |
print(vocab_to_int) | |
#{'is': 0, 'my': 1, 'this': 2, 'test': 3} | |
print(int_to_vocab) | |
#{0: 'is', 1: 'my', 2: 'this', 3: 'test'} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
min_length = 1 #as long or longer than this | |
max_length = 4 #no longer than this | |
data = ['', 'a', 'bb', 'cc', '', 'ddd', 'eee', 'ffff', 'ggggg', 'hhhhhh'] | |
results = [item[:max_length] for item in data if len(item) >= min_length] | |
print(results) | |
#['a', 'bb', 'cc', 'ddd', 'eee', 'ffff', 'gggg', 'hhhh'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def tanh(x): | |
return (1.0 - numpy.exp(-2*x))/(1.0 + numpy.exp(-2*x)) | |
def tanh_derivative(x): | |
return (1 + tanh(x))*(1 - tanh(x)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections | |
input = [1,2,3,2,1,5,6,5,5,5] | |
result = [item for item, count in collections.Counter(input).items() if count > 1] | |
print(result) | |
#[1, 2, 5] |
OlderNewer