コード例 #1
0
ファイル: BigMLTests.cs プロジェクト: bigmlcom/bigml-csharp
       public async Task CreateMultiDataset()
       {
           Client c = new Client(userName, apiKey);
           Source.Arguments args = new Source.Arguments();
           args.Add("remote", "https://static.bigml.com/csv/iris.csv");
           args.Add("name", "https://static.bigml.com/csv/iris.csv");
 
           Source s = await c.CreateSource(args);
           s = await c.Wait<Source>(s.Resource);

           Assert.AreEqual(s.StatusMessage.StatusCode, Code.Finished);

           DataSet.Arguments argsDS = new DataSet.Arguments();
           argsDS.Source = s.Resource;
           DataSet ds = await c.CreateDataset(argsDS);
           ds = await c.Wait<DataSet>(ds.Resource);

           // use the other DataSet constructor
           argsDS = new DataSet.Arguments(s);
           DataSet ds2 = await c.CreateDataset(argsDS);
           ds2 = await c.Wait<DataSet>(ds2.Resource);

           argsDS = new DataSet.Arguments();
           argsDS.OriginDatasets.Add(ds.Resource);
           argsDS.OriginDatasets.Add(ds2.Resource);
           argsDS.Name = "Dataset using multi datasets";

           DataSet dsMulti = await c.CreateDataset(argsDS);
           dsMulti = await c.Wait<DataSet>(dsMulti.Resource);

           await c.Delete(s);
           await c.Delete(ds);
           await c.Delete(ds2);
           await c.Delete(dsMulti);
       }
コード例 #2
0
ファイル: Form1.cs プロジェクト: bigmlcom/bigml-csharp
        private Task<Listing<Source>> SourcesList()
        {

            Client c = new Client(userName, apiKey);
            Ordered<Source.Filterable, Source.Orderable, Source> result
                = (from s in c.ListSources()
                   orderby s.Created descending
                   select s);

            return result.InternalTask;
        }
コード例 #3
0
        /// <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");
        }
コード例 #4
0
ファイル: BigMLTests.cs プロジェクト: bigmlcom/bigml-csharp
       public async Task CreateSourceFromRemote()
       {
           Client c = new Client(userName, apiKey);
           Source.Arguments args = new Source.Arguments();
           args.Add("remote", "https://static.bigml.com/csv/iris.csv");

           Source s = await c.CreateSource(args);
           s = await c.Wait<Source>(s.Resource);

           Assert.AreEqual(s.StatusMessage.StatusCode, Code.Finished);

           await c.Delete(s);
       }
コード例 #5
0
ファイル: Program.cs プロジェクト: bigmlcom/bigml-csharp
        /// <summary>
        /// Simple sample that runs through all steps to explicitly create a
        /// local prediction from a csv file with the classic iris data.
        /// </summary>
        static async Task MainAsync()
        {
            // New BigML client with username and API key
            Console.Write("user: "******"key: ");
            var ApiKey = Console.ReadLine();

            var client = new Client(User, ApiKey);

            // New source from in-memory stream, with separate header. That's the header
            var source = await client.CreateSource(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.NotSuccessOrFail())
            {
                await Task.Delay(10);
            }
            Console.WriteLine(source.StatusMessage.ToString());

            // Default dataset from source
            var dataset = await client.CreateDataset(source);
            // 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());

            // Default model from dataset
            var model = await client.CreateModel(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());

            Console.WriteLine("Creating local model");
            Dictionary<string, dynamic> inputData = new Dictionary<string, dynamic>();
            inputData.Add("000002", 3);
            inputData.Add("000003", 1.5);

            var localModel = model.ModelStructure();
            var nodeResult = localModel.predict(inputData);

            Console.WriteLine("Predict:\n" + nodeResult);
        }
コード例 #6
0
ファイル: Form1.cs プロジェクト: bigmlcom/bigml-csharp
        // add async attribute in the event handler
        private async void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;
            label1.Text = "Loading...";

            Client c = new Client(userName, apiKey);
            Ordered<Source.Filterable, Source.Orderable, Source> result
                = (from s in c.ListSources()
                   orderby s.Created descending
                   select s);

            Listing<Source> sources = await result; //use await keyword
            int countSources = 0;
            foreach (Source src in sources)
            {
                countSources++;
            }

            label1.Text = countSources + " sources found";
            button1.Enabled = true;
        }
コード例 #7
0
ファイル: Form1.cs プロジェクト: bigmlcom/bigml-csharp
 private Task<Source> DoGetAsync()
 {
     Client c = new Client(userName, apiKey);
     return c.Get<Source>("source/57e4206ba2e47604db001b20");
 }