This project is read-only.

Getting Started Guide

This is a technical guide is for getting started with the Google Prediction API for .NET.

If you want to know how to get started with Google Prediction, please see Google's Getting Started Guide.

 

You’ll need:

 

  1. Create a new project in Visual Studio and make sure the target framework is set to .NET 3.5 - not .NET 3.5 Client Profile.
  2. Add a reference to both Parise.Google.Predict.dll and Newtonsoft.Json.dll - both of these can be found on the Downloads page.
  3. You're ready to start using the library.

Primary namespace - Google.API.Predict

Creating the client

Google.API.Predict.GooglePredictionClient client;
client = new Google.API.Predict.GooglePredictionClient("email@gmail.com", "password", "bucket", "data.csv");

Changing the Bucket / Data

 

client.ChangeData("bucket2", "data2.csv");

Invoking the Training Mechanism - View at Google 

 

Google.API.Predict.Responses.TrainingResponse trainResponse = client.Train();
if (trainResponse.Success)
{
    Console.WriteLine("Training of " + trainResponse.Data + " has started.");
}
else
{
    Console.WriteLine("Training of " + trainResponse.Data + " failed.");
}

Checking Training Status - View at Google

 

Google.API.Predict.Responses.MetadataResponse metaResponse = client.Check();
Console.WriteLine(metaResponse.ModelInfo);

Perform a Text Prediction  - View at Google 

 

// Create the prediction
Google.API.Predict.Requests.TextPrediction text = new Google.API.Predict.Requests.TextPrediction("feature1", "feature2");

// Request a prediction and store the result
Google.API.Predict.Responses.PredictionResponse prediction = client.PredictText(text);

// Print the results to the console
Console.WriteLine(prediction.OutputLabel);
foreach (Google.API.Predict.Responses.MultiOutput output in prediction.OutputMulti)
{
    Console.WriteLine(output.Label + " - " + output.Score);
}

Perform a Mixed Prediction – View at Google

// Create the prediction
Google.API.Predict.Requests.MixedPrediction mixed = new Google.API.Predict.Requests.MixedPrediction("text", 1.56, 23);

// Request a prediction and store the result
Google.API.Predict.Responses.PredictionResponse prediction = client.PredictMixed(mixed);
if (prediction.Success)
{
    // Print the results to the console
    if (prediction.OutputType == Google.API.Predict.Responses.PredictionResponse.PredictionOutputType.Categorical) // Categorical Output
    {
        Console.WriteLine("Prediction: " + prediction.OutputLabel);
        foreach (Google.API.Predict.Responses.MultiOutput output in prediction.OutputMulti)
        {
            Console.WriteLine(output.Label + " - " + output.Score);
        }
    }
    else // Regression Output
    {
        Console.WriteLine("Prediction:" + prediction.OutputValue);
    }
}
else
{
    Console.WriteLine("Error: " + prediction.ResponseStatusCodeDescription);
}

Perform a Numeric Prediction - View at Google

// Create the prediction
Google.API.Predict.Requests.NumericPrediction<int> numericInt = new Google.API.Predict.Requests.NumericPrediction<int>(1, 2, 3, 4);

// Request a prediction and store the result
Google.API.Predict.Responses.PredictionResponse prediction = client.PredictNumeric(numericInt);

// Print the results to the console
Console.WriteLine("Prediction:" + prediction.OutputValue);

Last edited Oct 12, 2010 at 2:45 AM by ajparise, version 15

Comments

No comments yet.