def create_image_classifier():
    # Create a dataset on the MetaMind servers.
    # You can view your existing datasets here: https://www.metamind.io/my_stuff#my-datasets
    # Each dataset is assigned an id by the server.
    #
    # To create a local representation of any of your datasets, you can simply pass the id into the constructor:
    #
    #      ClassificationData(id=123)
    #
    training_data = ClassificationData(private=True, data_type='image', name='image_demo')

    # You can find more information about how to add data to a dataset here: http://docs.metamind.io/docs/datasets
    # There are multiple ways of adding data to both text and image datasets
    training_data.add_samples([
        (apple_pie_url, 'food'),
        (salad_url, 'food'),
        (deer_url, 'animal')
    ], input_type='urls')

    image_directory = os.path.dirname(os.path.realpath(__file__)) + '/images'
    training_data.add_samples([
        (image_directory + '/bonsai.jpg', 'animal'),
        (image_directory + '/dog.jpg', 'animal')
    ], input_type='files')

    # Each classifier is assigned an id by the server, much like a dataset.
    # As with a dataset, you can create a representation of a classifier by passing its id into the constructor:
    #
    #      ClassificationModel(id=123)
    #
    classifier = ClassificationModel(private=True, name='image_demo')
    classifier.fit(training_data)
    return classifier
Exemple #2
0
def train(names):
    training_data = ClassificationData(private=True, data_type='image', name='fish')

    inputs = []
    for name in names:
        urls = fetch(name)
        for url in urls:
            inputs.append((url, name))

    training_data.add_samples(inputs, input_type='urls')
    classifier = ClassificationModel(private=True, name='fish')
    classifier.fit(training_data)
def create_text_classifier():
    training_data = ClassificationData(private=True, data_type='text', name='text_demo')
    training_data.add_samples([
        ('The horse got out of the barn.', 'rural'),
        ('It is very quiet at night', 'rural'),
        ('There are 300 cattle in the field.', 'rural'),
        ('The roads are empty', 'rural'),
        ('There is so much traffic today.', 'urban'),
        ('Newer buildings are often made of glass.', 'urban'),
        ('The subways are quite loud.', 'urban'),
        ('How many skyscrapers do you see?', 'urban')
    ], input_type='text')

    classifier = ClassificationModel(private=True, name='text_demo')
    classifier.fit(training_data)
    return classifier
Exemple #4
0
def create_text_classifier():
    training_data = ClassificationData(private=True,
                                       data_type='text',
                                       name='text_demo')
    training_data.add_samples(
        [('The horse got out of the barn.', 'rural'),
         ('It is very quiet at night', 'rural'),
         ('There are 300 cattle in the field.', 'rural'),
         ('The roads are empty', 'rural'),
         ('There is so much traffic today.', 'urban'),
         ('Newer buildings are often made of glass.', 'urban'),
         ('The subways are quite loud.', 'urban'),
         ('How many skyscrapers do you see?', 'urban')],
        input_type='text')

    classifier = ClassificationModel(private=True, name='text_demo')
    classifier.fit(training_data)
    return classifier
Exemple #5
0
def create_image_classifier():
    # Create a dataset on the MetaMind servers.
    # You can view your existing datasets here: https://www.metamind.io/my_stuff#my-datasets
    # Each dataset is assigned an id by the server.
    #
    # To create a local representation of any of your datasets, you can simply pass the id into the constructor:
    #
    #      ClassificationData(id=123)
    #
    training_data = ClassificationData(private=True,
                                       data_type='image',
                                       name='image_demo')

    # You can find more information about how to add data to a dataset here: http://docs.metamind.io/docs/datasets
    # There are multiple ways of adding data to both text and image datasets
    training_data.add_samples([(apple_pie_url, 'food'), (salad_url, 'food'),
                               (deer_url, 'animal')],
                              input_type='urls')

    image_directory = os.path.dirname(os.path.realpath(__file__)) + '/images'
    training_data.add_samples([(image_directory + '/bonsai.jpg', 'animal'),
                               (image_directory + '/dog.jpg', 'animal')],
                              input_type='files')

    # Each classifier is assigned an id by the server, much like a dataset.
    # As with a dataset, you can create a representation of a classifier by passing its id into the constructor:
    #
    #      ClassificationModel(id=123)
    #
    classifier = ClassificationModel(private=True, name='image_demo')
    classifier.fit(training_data)
    return classifier
Exemple #6
0
def train_data():
	set_api_key('bHIqZD7ZJgRDn4oDWwMiSkDdGiuX3YvHKeCdNV1VF2WkQJO5gR')
	training_data = ClassificationData(private=True, data_type='image',name='training images')
	training_data.add_samples([
		('./imgs/banana.jpg','fruits'),('./imgs/blueberries.jpg','fruits'),('./imgs/fruit_collection2.jpg','fruits'),('./imgs/fruit_collection.jpg','fruits'),('./imgs/grapefruit.jpg','fruits'),
		('./imgs/grapes.jpg','fruits'),('./imgs/oranges.jpg','fruits'),('./imgs/peaches.jpg','fruits'),('./imgs/pears.jpg','fruits'),('./imgs/strawberries.jpg','fruits'),('./imgs/watermelon.jpg','fruits'),('./imgs/carrots.jpg','vegetables'),('./imgs/lettuce.jpg','vegetables'),('./imgs/radish.jpg','vegetables')], input_type='files')
	training_data.add_samples([
	('http://punchbowlsocial.com/wp-content/uploads/2015/02/eyg.jpg','eggs'),('http://media.thefowlergroup.com.s3.amazonaws.com/wp-content/uploads/2012/05/copywriting-deli-ham.jpg','meat'),('http://www.tyson.com/~/media/Consumer/Call-Outs/fresh-package.ashx?la=en','meat'),('http://homeguides.sfgate.com/DM-Resize/photos.demandstudios.com/gett/article/83/5/86544602_XS.jpg?w=442&h=442&keep_ratio=1','dairy'),('http://i-store.walmart.ca/images/WMTCNPE/155/016/155016_Large_1.jpeg','dairy'),('http://www.10tv.com/content/graphics/2014/08/29/kraft-singles-american.jpg','dairy')], input_type='urls')
	
	fruit.fit(training_data)
from metamind.api import set_api_key, twitter_text_classifier, ClassificationData, ClassificationModel, set_api_key

#Set the metamind API key for my account
set_api_key("IpdP8N0nsPmYstaqwqL1CWpPWfxxETCj5BzQWa7ANN6ChZ9PYS")

#Using the MetaMind API we can look up things 
#print twitter_text_classifier.query_and_predict("comcast")

#Create the classification training data to feed into the model
training_data = ClassificationData(private=True, data_type="text", name="RT snippets 3 feature training data")
training_data.add_samples("rt.train-3.tsv", input_type="tsv")

#Train the classifier
classifier = ClassificationModel(private=True, name="RT movie 3-value classifier")
classifier.fit(training_data)

#print classifier.predict("Furious7 was the worst movie I've ever seen. Period.", input_type="text")
Exemple #8
0
from metamind.api import set_api_key, ClassificationData, ClassificationModel
import pymongo
from pymongo import MongoClient
import pickle
import time

### metamind setup
set_api_key("k3U0ZYw5U7BiQWnXYCAJGzKHmSk42VSNUoVebKxPC9jlchnXzk")
training_data = ClassificationData(private=True, data_type='text', name="text snippets")
clf = ClassificationModel(private=True, name='SCF_category_classifier')

### mongodb setup
client = MongoClient()
db = client.nh1

### extract samples
with open('/home/allan/Desktop/new_haven_seeclickfix_visualization/data/wrangling/training_samples.pkl','r') as f: #load the samples...
	training_samples = pickle.load(f)

count=0
training_samples_2=[]
for sample in training_samples:
	count+=1
	training_samples_2.append((sample[0]+' '+sample[1],sample[2]))
training_data.add_samples(training_samples_2,input_type='text') #add them to the training data.


clf.fit(training_data) # train the classifier...

## put all cleaning operations under a single function
from metamind.api import set_api_key, twitter_text_classifier, ClassificationData, ClassificationModel, set_api_key

set_api_key("5eqwiKI50ym253djlf84VEgQptIb5odohKFpgS1SSWOdeGDzQ3")

training_data = ClassificationData(private=True, data_type="text", name="RT snippets training data")
training_data.add_samples()

classifier = ClassificationModel(private=True, name="RT movie classifier")
classifier.fit(training_data)

print classifier.predict("This company is the worst and is losing money", input_type="text")
from metamind.api import ClassificationData, ClassificationModel, set_api_key
from story_teller import *
import os

set_api_key(os.environ.get('METAMIND_KEY'))

#print getPostBetweenScores((200,300), 1)
#print getContentWithLabel(1)

training_data = ClassificationData(private=True, data_type='text', name='hn_stories_2labels_800_samples')
#training_data = ClassificationData(id=184417)
labels = ('0To15', '150Plus')
samples = getContentWithLabel(400, labels)

training_data.add_samples(samples, input_type='text')
classifier = ClassificationModel(private=True, name='HN score predictor_2labels')
#classifier = ClassificationModel(id=27906)

classifier.fit(training_data)

randomPost = getRandomPost()
prediction = classifier.predict(randomPost['content'], input_type='text')
print randomPost['score']
print prediction[0]['label'], prediction[0]['confidence']
#print 'prediction of score %d is %s with confidence %f' %(randomPost['score'], prediction['label'], prediction['probability'])