static async void Main() { // New BigML client with username and API key Console.Write("user: "******"key: "); var ApiKey = Console.ReadLine(); // set true the development mode var client = new Client(User, ApiKey, true); // create a source var remoteURL = @"azure://csv/iris.csv?AccountName=bigmlpublic"; Source.Arguments remoteArguments = new Source.Arguments(); remoteArguments.Add("remote", remoteURL); var sourceFromAzure = await client.Create(remoteArguments); while ((sourceFromAzure = await client.Get(sourceFromAzure)).StatusMessage.NotSuccessOrFail()) await Task.Delay(10); Console.WriteLine(sourceFromAzure.StatusMessage.ToString()); var dataset = await client.Create(sourceFromAzure); // No push, so we need to busy wait for the dataset to be processed. while ((dataset = await client.Get(dataset)).StatusMessage.NotSuccessOrFail()) await Task.Delay(10); Console.WriteLine(dataset.StatusMessage.ToString()); // Customized cluster from dataset. 3 is the desired number of cluster. Sets cluster name: "my cluster" var cluster = await client.CreateCluster(dataset, "my cluster", 3); while ((cluster = await client.Get(cluster)).StatusMessage.NotSuccessOrFail()) await Task.Delay(10); Console.WriteLine(cluster.StatusMessage.ToString()); }
static async void Main() { // New BigML client with username and API key Console.Write("user: "******"key: "); var ApiKey = Console.ReadLine(); var client = new Client(User, ApiKey); // Create a source from a file in azure storage var remoteURL = @"azure://csv/iris.csv?AccountName=bigmlpublic"; Source.Arguments remoteArguments = new Source.Arguments(); remoteArguments.Remote = remoteURL; remoteArguments.Name = "Iris from Azure"; var sourceFromAzure = await client.Create(remoteArguments); while ((sourceFromAzure = await client.Get(sourceFromAzure)).StatusMessage.NotSuccessOrFail()) await Task.Delay(10); // Create a dataset from this sources var dataset = await client.Create(sourceFromAzure); while ((dataset = await client.Get(dataset)).StatusMessage.NotSuccessOrFail()) await Task.Delay(10); Console.WriteLine(dataset.StatusMessage.ToString()); // Default model from this 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.NotSuccessOrFail()) await Task.Delay(10); Console.WriteLine(model.StatusMessage.ToString()); }
/// <summary> /// Simple sample that runs through all steps to explicitly create a prediction /// from a csv file with the classic iris data. /// </summary> static async Task MainAsync() { // New BigML client using username and API key. Console.Write("user: "******"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()); } // 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()); // The model description is what we are really after 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"); }
static async void Main() { // New BigML client with username and API key Console.Write("user: "******"key: "); var ApiKey = Console.ReadLine(); var client = new Client(User, ApiKey); // retrieve a anomaly detector with a known ID Anomaly anomaly; string anomalyId = "anomaly/54daa82eaf447f5daa000XXY"; //Put your ID here if ((anomaly = await client.Get<Anomaly>(anomalyId)).StatusMessage.StatusCode != Code.Finished) { Console.WriteLine("Error retrieving anomaly " + anomalyId); } else { Console.WriteLine(anomaly.StatusMessage.ToString()); } //Input the data and calculate the score var parameters = new AnomalyScore.Arguments(); parameters.Anomaly = anomaly.Resource; parameters.InputData.Add("000000", 7.9); parameters.InputData.Add("000001", 3.8); parameters.InputData.Add("000002", 6.4); parameters.InputData.Add("000003", 2); parameters.InputData.Add("000004", "virginica"); AnomalyScore score; while ((score = await client.Create<AnomalyScore>(parameters)).StatusMessage.StatusCode != Code.Finished) await Task.Delay(10); Console.WriteLine(score.StatusMessage.ToString()); }