GithubHelp home page GithubHelp logo

bigml-csharp's Introduction

C# bindings for BigML.io

These bindings expose a full LINQ provider, a strongly typed projection of all the JSON objects exposed by the REST API, as well as the ability to compile models to .NET assemblies.

The implementation of the LINQ provider may be an interesting topic of study by itself, and follows the pattern outlined in The World According to LINQ.

Adding JSON Library

This bindings uses the System.Json dll that was released as part of Silverlight Framework ([See reference] (https://msdn.microsoft.com/en-us/library/system.json(v=vs.95).aspx)). So, its common to add it mannually. In order to add it you should use the package manager. In your visual studio enviroments go to the package manager console (Tools > Library packages manager > Package manager console) and type:

Install-Package System.Json -Version 4.0.20126.16343 BigML

you should see a message like this

'System.Json 4.0.20126.16343' was successfully added to BigML.

Accessing BigML.io

To access BigML using the bindings, you first create a new client object by passing your user name and API key. The client object provides methods for most of the operations provided by the BigML API (of course the binding may not reflect all the latest features, for example we do not implement Evaluations yet, but that is why we provide the source on GitHub) such as listing, filtering, and sorting your sources using LINQ queries. For instance:

// New BigML client using username and API key.
Console.Write("user: "); var User = Console.ReadLine();
Console.Write("key: "); var ApiKey = Console.ReadLine();
var client = new Client(User, ApiKey);

Ordered<Source.Filterable, Source.Orderable, Source> result
      = (from s in client.ListSources()
	     orderby s.Created descending
	     select s);

var sources = await result;
foreach(var src in sources) Console.WriteLine(src.ToString());

Creating a datasources, datasets and models

Once we have printed out the existing sources, we can create a new source from an in-memory collection, but BigML (and the .NET bindings) also supports creating sources from local files, Amazon S3, or Azure Blob store. And from that a dataset, and a model. Since it can take a while for the BigML service to process creation of sources, datasets, and models, we need to poll until we get status code “finished” back from the service:

// New source from in-memory stream, with separate header.
var source = await client.Create(iris, "Iris.csv", "sepal length, sepal width, petal length, petal width, species");
// No push, so we need to busy wait for the source to be processed.
while ((source = await client.Get(source)).StatusMessage.StatusCode != Code.Finished) await Task.Delay(10);
Console.WriteLine(source.StatusMessage.ToString());

// Default dataset from source
var dataset = await client.Create(source);
// No push, so we need to busy wait for the source to be processed.
while ((dataset = await client.Get(dataset)).StatusMessage.StatusCode != Code.Finished) await Task.Delay(10);
Console.WriteLine(dataset.StatusMessage.ToString());

// Default model from dataset
var model = await client.Create(dataset);
// No push, so we need to busy wait for the source to be processed.
while ((model = await client.Get(model)).StatusMessage.StatusCode != Code.Finished) await Task.Delay(10);
Console.WriteLine(model.StatusMessage.ToString());

Manipulating models

The model description is a JSON object that represents the decision tree that BigML has learned from the data we fed to it. We translate the model into a .NET expression tree and then compile the expression tree into a .NET delegate, and call it on one of the test inputs to see if it predicts the same kind of iris:

var description = model.ModelDescription;
Console.WriteLine(description.ToString());

// First convert it to a .NET expression tree
var expression = description.Expression();
Console.WriteLine(expression.ToString());

// Then compile the expression tree into MSIL
var predict = expression.Compile() as Func<double,double,double,double,string>;

// And try the first flower of the example set.
var result2 = predict(5.1, 3.5, 1.4, 0.2);
Console.WriteLine("result = {0}, expected = {1}", result2, "setosa");

Support

Please report problems and bugs to our BigML.io issue tracker.

You can also join us in our Campfire chatroom.

bigml-csharp's People

Contributors

joseribes avatar osroca avatar jaor avatar headinthebox avatar littleml avatar

Watchers

James Cloos avatar Leon Hwang 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.