Code Monkey home page Code Monkey logo

django-google-prediction's Introduction

django-google-prediction

Introduction

django-google-prediction is a Django application that wraps the Google Prediction API to make it easier to build web applications with machine learning and data analysis functionality.

Instructions

Creating a new project

  • Go to the Google Developers Console, click Create Project and fill in the project name and id.
  • Go to your project, select APIs & auth > APIs and turn the Prediction API on.

Uploading a dataset (.csv)

  • In your project dashboard, select Cloud Storage > Storage browser.
  • You might be requested to enable billing for this feature.
  • Click New Bucket, fill in as desired and upload your dataset.

Configuring your Django application

  • In your project dashboard, select APIs & auth > Credentials.
  • Click Create New Client ID, select the Service account option and save your private key as private-key.p12 in your project's base directory.
  • Still in that page, note the Email address provided for that key (e.g. 1234567890-abcdefghijklmnopqrstuvwxyz1234567890@developer.gserviceaccount.com).
  • Add the following to settings.py:
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
GOOGLE_PREDICTION_PRIVATE_KEY = os.path.join(BASE_DIR, 'private-key.p12')
GOOGLE_PREDICTION_PROJECT_EMAIL = '_________' # REPLACE WITH YOUR PROJECT EMAIL
  • Add the google_prediction folder to your project's base directory.
  • Install all the modules in requirements.txt (use pip install -r requirements.txt).

Examples

For a complete example, check django-google-prediction-example.

  • Using Hosted Models
HostedModel('sample.languageid').predict('Me llamo Gabriel. Como te llamas?')
# {u'kind': u'prediction#output', u'outputLabel': u'Spanish', u'id': u'sample.languageid', u'selfLink': u'https://www.googleapis.com/prediction/v1.6/projects/414649711441/hostedmodels/sample.languageid/predict', u'outputMulti': [{u'score': u'0.032187', u'label': u'English'}, {u'score': u'0.512064', u'label': u'Spanish'}, {u'score': u'0.455749', u'label': u'French'}]}

m = HostedModel('sample.languageid')
m.predict('My name is Gabriel - nice to meet you!')['outputLabel']
# u'English'
m.predict("Je m'appelle Gabriel. J'aime la France!")['outputLabel']
# u'French'
  • Using Trained Models
# Listing all your models
TrainedModel.list("YOUR_PROJECT_ID")

# Creating a new model 
# (DATASET_LOCATION must be in a Google Storage bucket; leave blank for empty model)
TrainedModel("YOUR_PROJECT_ID", "YOUR_MODEL_NAME").insert("DATASET_LOCATION")

# Inserting data into your model
TrainedModel("YOUR_PROJECT_ID", "YOUR_MODEL_NAME").update(OUTPUT, INPUT_DATA)

# Getting information about your model
TrainedModel("YOUR_PROJECT_ID", "YOUR_MODEL_NAME").get()

# Analyzing your model
TrainedModel("YOUR_PROJECT_ID", "YOUR_MODEL_NAME").analyze()

# Predicting based on your model
TrainedModel("YOUR_PROJECT_ID", "YOUR_MODEL_NAME").predict(INPUT_DATA)

# Deleting your model
TrainedModel("YOUR_PROJECT_ID", "YOUR_MODEL_NAME").delete()

# Multiple calls
m = TrainedModel("YOUR_PROJECT_ID", "YOUR_MODEL_NAME")
m.predict(INPUT_DATA)
m.predict(SOME_OTHER_DATA)
m.predict(MORE_STUFF_HERE)

django-google-prediction's People

Contributors

gabrielbianconi avatar

Watchers

James Cloos avatar Omar Miranda avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.