Instantly share code, notes, and snippets.

View classify.py
from word_features import extract
import pickle
import sys
try:
f = open('classifier.pickle', 'rb')
except FileNotFoundError:
print('Classifier not found')
exit()
View train.py
from nltk.classify import NaiveBayesClassifier
from nltk.corpus import movie_reviews
from word_features import extract
import pickle
import nltk.classify.util
"""
Only downloads the movie reviews database
View tensorflow_image_classification_predict.py
import tensorflow as tf
import sys
image_path = sys.argv[1]
image_data = tf.gfile.FastGFile(image_path, 'rb').read()
label_lines = [line.rstrip() for line in tf.gfile.GFile('labels.txt')]
with tf.gfile.FastGFile('graph.pb', 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
View predict_wine.py
from keras.models import load_model
import numpy
model = load_model('wine-model.h5')
predict_me = numpy.array([
[6.6, 0.16, 0.4, 1.5, 0.044, 48, 143, 0.9912, 3.54, 0.52, 12.4], # Good
[5.2, 0.405, 0.15, 1.45, 0.038, 10, 44, 0.99125, 3.52, 0.4, 11.6] # Bad
])
View evaluate_wine_model.py
from keras.models import load_model
import numpy
dataset = numpy.loadtxt("wine-data.csv", delimiter=";")
input = dataset[:, 0:11]
output = dataset[:, 11]
# since the data comes in a scale of 0 to 10, this is needed to we get a simple true or false
output = [(round(each / 10)) for each in output]
View train_wine_model.py
from keras.models import Sequential
from keras.layers import Dense
import numpy
dataset = numpy.loadtxt("wine-data.csv", delimiter=";")
input = dataset[:, 0:11]
output = dataset[:, 11]
# since the data comes in a scale of 0 to 10, this is needed to we get a simple true or false
View evaluate_model.py
from keras.models import load_model
import numpy
dataset = numpy.loadtxt("diabetes.csv", delimiter=",")
input = dataset[:,0:8]
output = dataset[:,8]
model = load_model('diabetes.h5')
View predict_diabetes.py
from keras.models import load_model
import numpy
model = load_model('diabetes.h5')
predict_me = numpy.array([[1, 126, 60, 0, 0, 30.1, 0.349, 47]])
predictions = model.predict(predict_me)
rounded = [round(output[0]) for output in predictions]
View keras_training_diabetes_model.py
from keras.models import Sequential
from keras.layers import Dense
import numpy
# load dataset
dataset = numpy.loadtxt("diabetes.csv", delimiter=",")
# split into input and ouput
input = dataset[:,0:8]
output = dataset[:,8]