Browse files

Initial contents from Erik and Claudio

  • Loading branch information...
1 parent b29a387 commit 9687e4350d6782a720d76e9a5b307ab27cc283cc @jaor jaor committed Mar 6, 2013
Showing with 5,072 additions and 1 deletion.
  1. +64 −0 BigML.sln
  2. +6 −0 BigML.vsmdi
  3. +149 −0 BigML/BigML.csproj
  4. +17 −0 BigML/Client/Client.cs
  5. +67 −0 BigML/DataSet/Arguments.cs
  6. +33 −0 BigML/DataSet/BigMLClientDataSet.cs
  7. +107 −0 BigML/DataSet/DataSet.cs
  8. +13 −0 BigML/DataSet/DataSetListing.cs
  9. +38 −0 BigML/DataSet/Field/Categorial.cs
  10. +106 −0 BigML/DataSet/Field/Field.cs
  11. +102 −0 BigML/DataSet/Field/Numeric.cs
  12. +33 −0 BigML/DataSet/Field/Summary.cs
  13. +61 −0 BigML/DataSet/Filterable.cs
  14. +63 −0 BigML/DataSet/Orderable.cs
  15. +54 −0 BigML/DataSet/Status.cs
  16. +55 −0 BigML/Helpers/Extensions.cs
  17. +69 −0 BigML/Helpers/JsonContent.cs
  18. +10 −0 BigML/Helpers/OpType.cs
  19. +46 −0 BigML/Helpers/Reflection.cs
  20. +79 −0 BigML/Model/Arguments.cs
  21. +43 −0 BigML/Model/BigMLClientModel.cs
  22. +96 −0 BigML/Model/Description.cs
  23. +93 −0 BigML/Model/Filterable.cs
  24. +163 −0 BigML/Model/Model.cs
  25. +13 −0 BigML/Model/ModelListing.cs
  26. +78 −0 BigML/Model/Node.cs
  27. +95 −0 BigML/Model/Orderable.cs
  28. +98 −0 BigML/Model/Predicate.cs
  29. +28 −0 BigML/Model/Status.cs
  30. +54 −0 BigML/Prediction/Arguments.cs
  31. +33 −0 BigML/Prediction/BigMLClientPrediction.cs
  32. +73 −0 BigML/Prediction/Filterable.cs
  33. +75 −0 BigML/Prediction/Orderable.cs
  34. +40 −0 BigML/Prediction/Predicate.cs
  35. +129 −0 BigML/Prediction/Prediction.cs
  36. +13 −0 BigML/Prediction/PredictionListing.cs
  37. +62 −0 BigML/Prediction/PredictionPath.cs
  38. +20 −0 BigML/Prediction/Status.cs
  39. +36 −0 BigML/Properties/AssemblyInfo.cs
  40. +43 −0 BigML/Query/Filterable.cs
  41. +24 −0 BigML/Query/Filterable/Bool.cs
  42. +19 −0 BigML/Query/Filterable/Category.cs
  43. +29 −0 BigML/Query/Filterable/DateTimeOffset.cs
  44. +31 −0 BigML/Query/Filterable/Double.cs
  45. +29 −0 BigML/Query/Filterable/Int.cs
  46. +16 −0 BigML/Query/Filterable/Object.cs
  47. +19 −0 BigML/Query/Filterable/String.cs
  48. +19 −0 BigML/Query/Filterable/Type.cs
  49. +32 −0 BigML/Query/Filtered.cs
  50. +9 −0 BigML/Query/InputAttribute.cs
  51. +23 −0 BigML/Query/Json/JsonValue.cs
  52. +15 −0 BigML/Query/NameAttribute.cs
  53. +23 −0 BigML/Query/Object/Filter/Bool.cs
  54. +18 −0 BigML/Query/Object/Filter/Category.cs
  55. +28 −0 BigML/Query/Object/Filter/DateTimeOffset.cs
  56. +30 −0 BigML/Query/Object/Filter/Double.cs
  57. +28 −0 BigML/Query/Object/Filter/Int.cs
  58. +18 −0 BigML/Query/Object/Filter/String.cs
  59. +18 −0 BigML/Query/Object/Filter/Type.cs
  60. +9 −0 BigML/Query/Object/Sort/Bool.cs
  61. +9 −0 BigML/Query/Object/Sort/Category.cs
  62. +9 −0 BigML/Query/Object/Sort/DateTimeOffset.cs
  63. +9 −0 BigML/Query/Object/Sort/Double.cs
  64. +9 −0 BigML/Query/Object/Sort/Int.cs
  65. +6 −0 BigML/Query/Object/Sort/SortKey.cs
  66. +9 −0 BigML/Query/Object/Sort/String.cs
  67. +9 −0 BigML/Query/Object/Sort/Type.cs
  68. +46 −0 BigML/Query/Orderable.cs
  69. +10 −0 BigML/Query/Orderable/Bool.cs
  70. +10 −0 BigML/Query/Orderable/Category.cs
  71. +10 −0 BigML/Query/Orderable/DateTimeOffset.cs
  72. +10 −0 BigML/Query/Orderable/Double.cs
  73. +10 −0 BigML/Query/Orderable/Int.cs
  74. +16 −0 BigML/Query/Orderable/Object.cs
  75. +10 −0 BigML/Query/Orderable/String.cs
  76. +10 −0 BigML/Query/Orderable/Type.cs
  77. +135 −0 BigML/Query/Ordered.cs
  78. +37 −0 BigML/Query/Query.cs
  79. +67 −0 BigML/Response/Arguments.cs
  80. +20 −0 BigML/Response/Category.cs
  81. +97 −0 BigML/Response/Code.cs
  82. +218 −0 BigML/Response/Commands.cs
  83. +49 −0 BigML/Response/Field.cs
  84. +41 −0 BigML/Response/Listing.cs
  85. +56 −0 BigML/Response/MetaObject.cs
  86. +98 −0 BigML/Response/Response.cs
  87. +58 −0 BigML/Response/Status.cs
  88. +58 −0 BigML/Source/Arguments.cs
  89. +93 −0 BigML/Source/Client.cs
  90. +15 −0 BigML/Source/Field.cs
  91. +59 −0 BigML/Source/Filterable.cs
  92. +64 −0 BigML/Source/Orderable.cs
  93. +133 −0 BigML/Source/Parser.cs
  94. +116 −0 BigML/Source/Source.cs
  95. +13 −0 BigML/Source/SourceListing.cs
  96. +21 −0 BigML/Source/Status.cs
  97. +26 −0 BigML/Source/Type.cs
  98. +3 −0 BigML/app.config
  99. +4 −0 BigML/packages.config
  100. +71 −0 BigMLTest/BigMLTest.csproj
  101. +18 −0 BigMLTest/BigMLTests.cs
  102. +35 −0 BigMLTest/Properties/AssemblyInfo.cs
  103. +2 −0 CONTRIBUTORS.md
  104. +69 −0 Iris/Iris.csproj
  105. +226 −0 Iris/Program.cs
  106. +36 −0 Iris/Properties/AssemblyInfo.cs
  107. +3 −0 Iris/app.config
  108. +10 −0 Local.testsettings
  109. +1 −1 README.md
  110. +21 −0 TraceAndTestImpact.testsettings
  111. +13 −0 license.txt
View
64 BigML.sln
@@ -0,0 +1,64 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BigML", "BigML\BigML.csproj", "{458B9779-E302-4C7C-A0E7-7F20F4EA2D67}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BigMLTest", "BigMLTest\BigMLTest.csproj", "{8E86F251-ABDC-4CB7-9A8D-3AB7B2B3E923}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F071F120-B5B9-4DE9-A1F4-A0C110416673}"
+ ProjectSection(SolutionItems) = preProject
+ BigML.vsmdi = BigML.vsmdi
+ Local.testsettings = Local.testsettings
+ TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings
+ EndProjectSection
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Iris", "Iris\Iris.csproj", "{BADEF19D-9587-48D2-ACAB-0B16C650B063}"
+EndProject
+Global
+ GlobalSection(TestCaseManagementSettings) = postSolution
+ CategoryFile = BigML.vsmdi
+ EndGlobalSection
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Debug|Mixed Platforms = Debug|Mixed Platforms
+ Debug|x86 = Debug|x86
+ Release|Any CPU = Release|Any CPU
+ Release|Mixed Platforms = Release|Mixed Platforms
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {458B9779-E302-4C7C-A0E7-7F20F4EA2D67}.Debug|Any CPU.ActiveCfg = Debug|x86
+ {458B9779-E302-4C7C-A0E7-7F20F4EA2D67}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
+ {458B9779-E302-4C7C-A0E7-7F20F4EA2D67}.Debug|Mixed Platforms.Build.0 = Debug|x86
+ {458B9779-E302-4C7C-A0E7-7F20F4EA2D67}.Debug|x86.ActiveCfg = Debug|x86
+ {458B9779-E302-4C7C-A0E7-7F20F4EA2D67}.Debug|x86.Build.0 = Debug|x86
+ {458B9779-E302-4C7C-A0E7-7F20F4EA2D67}.Release|Any CPU.ActiveCfg = Release|x86
+ {458B9779-E302-4C7C-A0E7-7F20F4EA2D67}.Release|Mixed Platforms.ActiveCfg = Release|x86
+ {458B9779-E302-4C7C-A0E7-7F20F4EA2D67}.Release|Mixed Platforms.Build.0 = Release|x86
+ {458B9779-E302-4C7C-A0E7-7F20F4EA2D67}.Release|x86.ActiveCfg = Release|x86
+ {458B9779-E302-4C7C-A0E7-7F20F4EA2D67}.Release|x86.Build.0 = Release|x86
+ {8E86F251-ABDC-4CB7-9A8D-3AB7B2B3E923}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {8E86F251-ABDC-4CB7-9A8D-3AB7B2B3E923}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {8E86F251-ABDC-4CB7-9A8D-3AB7B2B3E923}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {8E86F251-ABDC-4CB7-9A8D-3AB7B2B3E923}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {8E86F251-ABDC-4CB7-9A8D-3AB7B2B3E923}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {8E86F251-ABDC-4CB7-9A8D-3AB7B2B3E923}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {8E86F251-ABDC-4CB7-9A8D-3AB7B2B3E923}.Release|Any CPU.Build.0 = Release|Any CPU
+ {8E86F251-ABDC-4CB7-9A8D-3AB7B2B3E923}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {8E86F251-ABDC-4CB7-9A8D-3AB7B2B3E923}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {8E86F251-ABDC-4CB7-9A8D-3AB7B2B3E923}.Release|x86.ActiveCfg = Release|Any CPU
+ {BADEF19D-9587-48D2-ACAB-0B16C650B063}.Debug|Any CPU.ActiveCfg = Debug|x86
+ {BADEF19D-9587-48D2-ACAB-0B16C650B063}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
+ {BADEF19D-9587-48D2-ACAB-0B16C650B063}.Debug|Mixed Platforms.Build.0 = Debug|x86
+ {BADEF19D-9587-48D2-ACAB-0B16C650B063}.Debug|x86.ActiveCfg = Debug|x86
+ {BADEF19D-9587-48D2-ACAB-0B16C650B063}.Debug|x86.Build.0 = Debug|x86
+ {BADEF19D-9587-48D2-ACAB-0B16C650B063}.Release|Any CPU.ActiveCfg = Release|x86
+ {BADEF19D-9587-48D2-ACAB-0B16C650B063}.Release|Mixed Platforms.ActiveCfg = Release|x86
+ {BADEF19D-9587-48D2-ACAB-0B16C650B063}.Release|Mixed Platforms.Build.0 = Release|x86
+ {BADEF19D-9587-48D2-ACAB-0B16C650B063}.Release|x86.ActiveCfg = Release|x86
+ {BADEF19D-9587-48D2-ACAB-0B16C650B063}.Release|x86.Build.0 = Release|x86
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
View
6 BigML.vsmdi
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<TestLists xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
+ <TestList name="Lists of Tests" id="8c43106b-9dc1-4907-a29f-aa66a61bf5b6">
+ <RunConfiguration id="6d3c66c8-a5d0-4a4e-be4d-9ffe73a5f068" name="Local" storage="local.testsettings" type="Microsoft.VisualStudio.TestTools.Common.TestRunConfiguration, Microsoft.VisualStudio.QualityTools.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+ </TestList>
+</TestLists>
View
149 BigML/BigML.csproj
@@ -0,0 +1,149 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{458B9779-E302-4C7C-A0E7-7F20F4EA2D67}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>BigML</RootNamespace>
+ <AssemblyName>BigML</AssemblyName>
+ <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ <TargetFrameworkProfile>
+ </TargetFrameworkProfile>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <Prefer32Bit>false</Prefer32Bit>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <Prefer32Bit>false</Prefer32Bit>
+ </PropertyGroup>
+ <PropertyGroup>
+ <StartupObject />
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Json">
+ <HintPath>..\..\OpenCnam\packages\System.Json.4.0.20126.16343\lib\net40\System.Json.dll</HintPath>
+ </Reference>
+ <Reference Include="System.Net.Http">
+ <HintPath>..\packages\System.Net.Http.2.0.20126.16343\lib\net40\System.Net.Http.dll</HintPath>
+ </Reference>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Client\Client.cs" />
+ <Compile Include="DataSet\Field\Categorial.cs" />
+ <Compile Include="DataSet\Field\Numeric.cs" />
+ <Compile Include="DataSet\Field\Summary.cs" />
+ <Compile Include="Response\Category.cs" />
+ <Compile Include="DataSet\Filterable.cs" />
+ <Compile Include="DataSet\Orderable.cs" />
+ <Compile Include="Helpers\Reflection.cs" />
+ <Compile Include="Model\Arguments.cs" />
+ <Compile Include="Model\Description.cs" />
+ <Compile Include="Model\Node.cs" />
+ <Compile Include="Model\Orderable.cs" />
+ <Compile Include="Prediction\Arguments.cs" />
+ <Compile Include="Prediction\Orderable.cs" />
+ <Compile Include="Prediction\PredictionListing.cs" />
+ <Compile Include="Model\ModelListing.cs" />
+ <Compile Include="Helpers\Extensions.cs" />
+ <Compile Include="DataSet\BigMLClientDataSet.cs" />
+ <Compile Include="DataSet\Status.cs" />
+ <Compile Include="DataSet\Field\Field.cs" />
+ <Compile Include="Helpers\JsonContent.cs" />
+ <Compile Include="Model\BigMLClientModel.cs" />
+ <Compile Include="Model\Filterable.cs" />
+ <Compile Include="Model\Status.cs" />
+ <Compile Include="Model\Predicate.cs" />
+ <Compile Include="Prediction\BigMLClientPrediction.cs" />
+ <Compile Include="Prediction\Filterable.cs" />
+ <Compile Include="Prediction\Predicate.cs" />
+ <Compile Include="Prediction\Prediction.cs" />
+ <Compile Include="Prediction\PredictionPath.cs" />
+ <Compile Include="Prediction\Status.cs" />
+ <Compile Include="DataSet\DataSetListing.cs" />
+ <Compile Include="Query\Filterable\Bool.cs" />
+ <Compile Include="Query\Filterable\Category.cs" />
+ <Compile Include="Query\Filterable\DateTimeOffset.cs" />
+ <Compile Include="Query\Filterable\Double.cs" />
+ <Compile Include="Query\Filterable\Int.cs" />
+ <Compile Include="Query\Filterable\Object.cs" />
+ <Compile Include="Query\Filterable\String.cs" />
+ <Compile Include="Query\Filterable\Type.cs" />
+ <Compile Include="Query\Json\JsonValue.cs" />
+ <Compile Include="Query\Orderable\Bool.cs" />
+ <Compile Include="Query\Orderable\Category.cs" />
+ <Compile Include="Query\Orderable\DateTimeOffset.cs" />
+ <Compile Include="Query\Orderable\Double.cs" />
+ <Compile Include="Query\Orderable\Int.cs" />
+ <Compile Include="Query\Orderable\Object.cs" />
+ <Compile Include="Query\Orderable\String.cs" />
+ <Compile Include="Query\Orderable\Type.cs" />
+ <Compile Include="Response\Arguments.cs" />
+ <Compile Include="Response\Commands.cs" />
+ <Compile Include="Response\Status.cs" />
+ <Compile Include="Query\Filterable.cs" />
+ <Compile Include="Query\InputAttribute.cs" />
+ <Compile Include="Query\Query.cs" />
+ <Compile Include="Source\Arguments.cs" />
+ <Compile Include="DataSet\Arguments.cs" />
+ <Compile Include="Source\Filterable.cs" />
+ <Compile Include="Source\Orderable.cs" />
+ <Compile Include="Response\Field.cs" />
+ <Compile Include="Source\SourceListing.cs" />
+ <Compile Include="Query\Filtered.cs" />
+ <Compile Include="Query\NameAttribute.cs" />
+ <Compile Include="Query\Orderable.cs" />
+ <Compile Include="Query\Ordered.cs" />
+ <Compile Include="Source\Client.cs" />
+ <Compile Include="DataSet\DataSet.cs" />
+ <Compile Include="Model\Model.cs" />
+ <Compile Include="Helpers\OpType.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Response\Response.cs" />
+ <Compile Include="Source\Field.cs" />
+ <Compile Include="Source\Source.cs" />
+ <Compile Include="Response\Listing.cs" />
+ <Compile Include="Response\MetaObject.cs" />
+ <Compile Include="Source\Parser.cs" />
+ <Compile Include="Response\Code.cs" />
+ <Compile Include="Source\Status.cs" />
+ <Compile Include="Source\Type.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config" />
+ <None Include="packages.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <Folder Include="Query\Object\" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
View
17 BigML/Client/Client.cs
@@ -0,0 +1,17 @@
+namespace BigML
+{
+ /// <summary>
+ /// BigML client.
+ /// </summary>
+ public partial class Client
+ {
+ readonly string _apiKey;
+ readonly string _username;
+
+ public Client(string userName, string apiKey)
+ {
+ _apiKey = apiKey;
+ _username = userName;
+ }
+ }
+}
View
67 BigML/DataSet/Arguments.cs
@@ -0,0 +1,67 @@
+using System.Collections.Generic;
+using System.Json;
+
+namespace BigML
+{
+ public partial class DataSet
+ {
+ public class Arguments : Arguments<DataSet>
+ {
+ public Arguments(Source source): this()
+ {
+ Source = source.Resource;
+ }
+
+ public Arguments()
+ {
+ FieldInfos = new Dictionary<string,Field>();
+ }
+
+ /// <summary>
+ /// Data for inline source creation.
+ /// </summary>
+ public IDictionary<string, Field> FieldInfos
+ {
+ get;
+ private set;
+ }
+
+ /// <summary>
+ /// The number of bytes from the source that you want to use.
+ /// </summary>
+ public int Size
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// A valid source/id.
+ /// </summary>
+ public string Source
+ {
+ get;
+ set;
+ }
+
+ public override JsonValue ToJson()
+ {
+ dynamic json = base.ToJson();
+
+ json.source = Source;
+ if (Size != 0) json.size = Size;
+ if(FieldInfos.Count > 0)
+ {
+ var field = new JsonObject();
+ foreach(var kv in FieldInfos)
+ {
+ field[kv.Key] = kv.Value.ToJson();
+ }
+ json.field = field;
+ }
+
+ return json;
+ }
+ }
+ }
+}
View
33 BigML/DataSet/BigMLClientDataSet.cs
@@ -0,0 +1,33 @@
+using System.Threading.Tasks;
+
+namespace BigML
+{
+ public partial class Client
+ {
+ /// <summary>
+ /// Create a dataset using the supplied arguments.
+ /// </summary>
+ public Task<DataSet> Create(DataSet.Arguments arguments)
+ {
+ return Create<DataSet>(arguments);
+ }
+
+ /// <summary>
+ /// Create a dataset.
+ /// </summary>
+ /// <param name="source">The source from which you want to generate a dataset.</param>
+ /// <param name="name">The optional name you want to give to the new dataset. </param>
+ public Task<DataSet> Create(Source source, string name = null, DataSet.Arguments arguments = null)
+ {
+ arguments = arguments ?? new DataSet.Arguments();
+ if (!string.IsNullOrWhiteSpace(name)) arguments.Name = name;
+ arguments.Source = source.Resource;
+ return Create<DataSet>(arguments);
+ }
+
+ public Query<DataSet.Filterable, DataSet.Orderable, DataSet> ListDataSets()
+ {
+ return new DataSetListing(List<DataSet>);
+ }
+ }
+}
View
107 BigML/DataSet/DataSet.cs
@@ -0,0 +1,107 @@
+using System.Collections.Generic;
+
+namespace BigML
+{
+ /// <summary>
+ /// A dataset is a structured version of a source where each field has been processed and serialized according to its type.
+ /// </summary>
+ public partial class DataSet : Response
+ {
+ /// <summary>
+ /// The number of fields in the dataset.
+ /// </summary>
+ public int Columns
+ {
+ get { return Object.columns; }
+ }
+
+ /// <summary>
+ /// A dictionary with an entry per field (column) in your data.
+ /// Each entry includes the column number, the name of the field, the type of the field, and the summary.
+ /// </summary>
+ public IDictionary<string, Field> Fields
+ {
+ get
+ {
+ var dictionary = new Dictionary<string, Field>();
+ foreach (var kv in Object.fields)
+ {
+ dictionary[kv.Key] = new Field(kv.Value);
+ }
+ return dictionary;
+ }
+ }
+
+ /// <summary>
+ /// The dataset's locale.
+ /// </summary>
+ public string Locale
+ {
+ get { return Object.locale; }
+ }
+
+ /// <summary>
+ /// The name of the dataset as your provided or based on the name of the source by default.
+ /// </summary>
+ public string Name
+ {
+ get { return Object.name; }
+ }
+
+ /// <summary>
+ /// The current number of models that use this dataset.
+ /// </summary>
+ public int NumberOfModels
+ {
+ get { return Object.number_of_models; }
+ }
+
+ /// <summary>
+ /// The current number of predictions that use this dataset.
+ /// </summary>
+ public int NumberOfPredictions
+ {
+ get { return Object.number_of_predictions; }
+ }
+
+ /// <summary>
+ /// The total number of rows in the dataset.
+ /// </summary>
+ public int Rows
+ {
+ get { return Object.rows; }
+ }
+
+ /// <summary>
+ /// The number of bytes of the source that were used to create this dataset.
+ /// </summary>
+ public int Size
+ {
+ get { return Object.size; }
+ }
+
+ /// <summary>
+ /// The source/id that was used to build the dataset.
+ /// </summary>
+ public string Source
+ {
+ get { return Object.source; }
+ }
+
+ /// <summary>
+ /// Whether the source is still available or has been deleted.
+ /// </summary>
+ public bool SourceStatus
+ {
+ get { return Object.source_status; }
+ }
+
+ /// <summary>
+ /// A description of the status of the dataset.
+ /// </summary>
+ public Status StatusMessage
+ {
+ get{ return new Status(Object.status); }
+ }
+ }
+}
View
13 BigML/DataSet/DataSetListing.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Threading.Tasks;
+
+namespace BigML
+{
+ public class DataSetListing : Query<DataSet.Filterable, DataSet.Orderable, DataSet>
+ {
+ public DataSetListing(Func<string, Task<Listing<DataSet>>> client)
+ : base(client)
+ {
+ }
+ }
+}
View
38 BigML/DataSet/Field/Categorial.cs
@@ -0,0 +1,38 @@
+using System.Collections.Generic;
+using System.Json;
+
+namespace BigML
+{
+ public partial class DataSet
+ {
+ public partial class Field
+ {
+ public abstract partial class Summary
+ {
+ /// <summary>
+ /// Categorical summaries give you a count per each category and missing count in case any of the instances contain missing values.
+ /// </summary>
+ public class Categorical : Summary
+ {
+ internal Categorical(JsonValue json)
+ : base(json)
+ {
+ }
+
+ /// <summary>
+ /// A dictionary where the keys are the unique categories found in the field and the values are the count for that category.
+ /// </summary>
+ public IDictionary<string, int> Counts
+ {
+ get
+ {
+ var counts = new Dictionary<string, int>();
+ foreach (var kv in _summary.counts) counts[kv.Key] = kv.Value;
+ return counts;
+ }
+ }
+ }
+ }
+ }
+ }
+}
View
106 BigML/DataSet/Field/Field.cs
@@ -0,0 +1,106 @@
+using System.Collections.Generic;
+using System.Json;
+using System.Linq;
+
+namespace BigML
+{
+ public partial class DataSet
+ {
+ /// <summary>
+ /// The column number, the name of the field, the type of the field, and the summary of a dataset field.
+ /// </summary>
+ public partial class Field : Field<DataSet>
+ {
+ readonly dynamic _field;
+
+ /// <summary>
+ /// Internal constructor for use when created internally.
+ /// </summary>
+ internal Field(JsonValue json): base(json)
+ {
+ _field = json;
+
+ MissingTokens = json.ContainsKey("missing_tokens")
+ ? new HashSet<string>(json["missing_tokens"].Select(x => (string)x))
+ : new HashSet<string>();
+ }
+
+ /// <summary>
+ /// Public constructor to create fields for use in argument.
+ /// </summary>
+ public Field(): this(new JsonObject())
+ {
+ }
+
+ /// <summary>
+ /// Name of the field.
+ /// </summary>
+ public new string Name
+ {
+ get { return base.Name; }
+ }
+
+ /// <summary>
+ /// The specific locale for this field.
+ /// </summary>
+ public string Locale
+ {
+ get { return _field.locale; }
+ }
+
+ /// <summary>
+ /// Specifies the type of the field.
+ /// It can be numerical, categorical, or text.
+ /// </summary>
+ public new OpType OpType
+ {
+ get { return base.OpType; }
+ set { _field.optype = value.ToString().ToLower(); }
+ }
+
+ public ISet<string> MissingTokens
+ {
+ get;
+ private set;
+ }
+
+ /// <summary>
+ /// Numeric or categorical summary of the field.
+ /// Downcast to appropriate (Summary.Numeric or Summary.Categorical) subtype as needed.
+ /// </summary>
+ public Summary FieldSummary
+ {
+ get
+ {
+ switch(OpType)
+ {
+ case OpType.Categorical:
+ return new Summary.Categorical(_field.summary);
+ case OpType.Numeric:
+ return new Summary.Numeric(_field.summary);
+ default:
+ return default(Summary);
+ }
+ }
+ }
+
+ public JsonValue ToJson()
+ {
+ dynamic copy = new JsonObject();
+
+ if (!string.IsNullOrWhiteSpace(Name)) copy.name = Name;
+ if (!string.IsNullOrWhiteSpace(Locale)) copy.locale = Locale;
+ if (OpType != OpType.Error) copy.optype = OpType.ToString().ToLower();
+ if (MissingTokens.Count > 0) copy.missing_tokens = new JsonArray(MissingTokens.Select(t => (JsonValue)t));
+
+ return copy;
+ }
+
+ public override string ToString()
+ {
+ return ToJson().ToString();
+ }
+
+ }
+ }
+}
View
102 BigML/DataSet/Field/Numeric.cs
@@ -0,0 +1,102 @@
+using System.Collections.Generic;
+using System.Json;
+
+namespace BigML
+{
+ public partial class DataSet
+ {
+ public partial class Field
+ {
+ public abstract partial class Summary
+ {
+ /// <summary>
+ /// Numeric summaries come with all the fields described below.
+ /// Depending on whether the number of different values for the field is lower than 32 or not,
+ /// you can get either counts or splits points.
+ /// </summary>
+ public class Numeric : Summary
+ {
+ internal Numeric(JsonValue json)
+ : base(json)
+ {
+ }
+
+ /// <summary>
+ /// A dictionary where each key is one of the unique values found in the field and the value is the count.
+ /// Only available when the number of distinct values is less than or equal to 32.
+ /// </summary>
+ public IDictionary<int, int> Counts
+ {
+ get
+ {
+ var counts = new Dictionary<int, int>();
+ foreach (var kv in _summary.counts) counts[(int)kv[0]] = (int)kv[1];
+ return counts;
+ }
+ }
+
+ /// <summary>
+ /// The maximum value found in this field.
+ /// </summary>
+ public int Maximum
+ {
+ get { return _summary.maximum; }
+ }
+
+ /// <summary>
+ /// The median value found in this field.
+ /// </summary>
+ public int Median
+ {
+ get { return _summary.median; }
+ }
+
+ /// <summary>
+ /// The minimum value found in this field.
+ /// </summary>
+ public int Minimum
+ {
+ get { return _summary.minimum; }
+ }
+
+ /// <summary>
+ /// The number of instances containing data for this field.
+ /// </summary>
+ public int Population
+ {
+ get { return _summary.population; }
+ }
+
+ /// <summary>
+ /// Histogram split points for this field.
+ /// The split points break the distribution into buckets of equal population.
+ /// This helps you easily compute histograms with you preferred number of bins.
+ /// Only available when the number of distinct values is more than 32.
+ /// </summary>
+ public IEnumerable<double> Splits
+ {
+ get { return (_summary.splits as JsonArray).Select(s => (double)s); }
+ }
+
+ /// <summary>
+ /// Sum of all values for this field (for mean calculation).
+ /// </summary>
+ public double Sum
+ {
+ get { return _summary.sum; }
+ }
+
+ /// <summary>
+ /// Sum of squared values (for variance calculation).
+ /// </summary>
+ public double SumSquares
+ {
+ get { return _summary.sum_squares; }
+ }
+ }
+ }
+ }
+ }
+
+
+}
View
33 BigML/DataSet/Field/Summary.cs
@@ -0,0 +1,33 @@
+using System.Collections.Generic;
+using System.Json;
+
+namespace BigML
+{
+ public partial class DataSet
+ {
+ public partial class Field
+ {
+ /// <summary>
+ /// Statistical summary of field
+ /// </summary>
+ public abstract partial class Summary
+ {
+ protected readonly dynamic _summary;
+
+ protected Summary(JsonValue json)
+ {
+ _summary = json;
+ }
+
+
+ /// <summary>
+ /// Number of instances missing this field.
+ /// </summary>
+ public int Missing
+ {
+ get { return _summary.missing_count; }
+ }
+ }
+ }
+ }
+}
View
61 BigML/DataSet/Filterable.cs
@@ -0,0 +1,61 @@
+using BigML.Meta;
+
+namespace BigML
+{
+ public partial class DataSet
+ {
+ /// <summary>
+ /// Filterable properties for DataSets
+ /// </summary>
+ public class Filterable : Filterable<DataSet>
+ {
+ /// <summary>
+ /// The number of fields in the dataset.
+ /// </summary>
+ public Int Columns
+ {
+ get { return Object.columns; }
+ }
+
+ /// <summary>
+ /// The current number of models that use this source.
+ /// </summary>
+ public Int NumberOfModels
+ {
+ get { return Object.number_of_models; }
+ }
+
+ /// <summary>
+ /// The current number of predictions that use this source.
+ /// </summary>
+ public Int NumberOfPredictions
+ {
+ get { return Object.number_of_predictions; }
+ }
+
+ /// <summary>
+ /// The total number of rows in the dataset.
+ /// </summary>
+ public Int Rows
+ {
+ get { return Object.rows; }
+ }
+
+ /// <summary>
+ /// The source/id that was used to build the dataset.
+ /// </summary>
+ public String Source
+ {
+ get { return Object.source; }
+ }
+
+ /// <summary>
+ /// Whether the source is still available or has been deleted.
+ /// </summary>
+ public Bool SourceStatus
+ {
+ get { return Object.source_status; }
+ }
+ }
+ }
+}
View
63 BigML/DataSet/Orderable.cs
@@ -0,0 +1,63 @@
+using BigML.Meta;
+
+namespace BigML
+{
+ using Meta.Key;
+
+ public partial class DataSet
+ {
+ /// <summary>
+ /// Orderable properties for DataSets
+ /// </summary>
+ public class Orderable : Orderable<DataSet>
+ {
+ /// <summary>
+ /// The number of fields in the dataset.
+ /// </summary>
+ public Int Columns
+ {
+ get { return Object.columns; }
+ }
+
+ /// <summary>
+ /// The current number of models that use this source.
+ /// </summary>
+ public Int NumberOfModels
+ {
+ get { return Object.number_of_models; }
+ }
+
+ /// <summary>
+ /// The current number of predictions that use this source.
+ /// </summary>
+ public Int NumberOfPredictions
+ {
+ get { return Object.number_of_predictions; }
+ }
+
+ /// <summary>
+ /// The total number of rows in the dataset.
+ /// </summary>
+ public Int Rows
+ {
+ get { return Object.rows; }
+ }
+
+ /// <summary>
+ /// The source/id that was used to build the dataset.
+ /// </summary>
+ public String Source
+ {
+ get { return Object.source; }
+ }
+
+ /// <summary>
+ /// Whether the source is still available or has been deleted.
+ /// </summary>
+ public Bool SourceStatus
+ {
+ get { return Object.source_status; }
+ }
+ }
+ }
+}
View
54 BigML/DataSet/Status.cs
@@ -0,0 +1,54 @@
+using System.Json;
+
+namespace BigML
+{
+ public partial class DataSet
+ {
+ /// <summary>
+ /// Before a dataset is successfully created, BigML.io makes sure that it has been uploaded in an understandable format,
+ /// that the data that it contains is parseable, and that the types for each column in the data can be inferred successfully.
+ /// The dataset goes through a number of states until all these analyses are completed.
+ /// Through the status field in the dataset you can determine when the dataset has been fully processed and ready to be used to create a model.
+ /// </summary>
+ public class Status : Status<DataSet>
+ {
+ internal Status(JsonValue json)
+ : base(json)
+ {
+ }
+
+ /// <summary>
+ /// Number of bytes processed so far.
+ /// </summary>
+ public int Bytes
+ {
+ get { return _status.bytes; }
+ }
+
+ /// <summary>
+ /// Information about ill-formatted fields that includes the total format errors for the field and a sampling of the ill-formatted tokens.
+ /// </summary>
+ public JsonArray FieldErrors
+ {
+ get { return _status.field_errors; }
+ }
+
+ /// <summary>
+ /// Information about ill-formatted rows.
+ /// It includes the total row-format errors and a sampling of the ill-formatted rows.
+ /// </summary>
+ public JsonArray RowFormatErrors
+ {
+ get { return _status.row_format_errors; }
+ }
+
+ /// <summary>
+ /// The number of rows serialized so far.
+ /// </summary>
+ public int SerializedRows
+ {
+ get { return _status.serialized_rows; }
+ }
+ }
+ }
+}
View
55 BigML/Helpers/Extensions.cs
@@ -0,0 +1,55 @@
+using System;
+using System.Collections.Generic;
+using System.Json;
+using System.Linq;
+
+namespace BigML
+{
+ public static class Extensions
+ {
+
+ public static IEnumerable<T> Select<T>(this JsonValue source, Func<JsonValue, T> selector)
+ {
+ return (source as IEnumerable<JsonValue> ?? new JsonValue[]{}).Select(selector);
+ }
+
+ /// <summary>
+ /// Convert OpType to System.Type
+ /// </summary>
+ public static Type TypeOf(this OpType optype)
+ {
+ switch (optype)
+ {
+ case OpType.Numeric:
+ return typeof (double);
+ case OpType.Categorical:
+ return typeof (string);
+ case OpType.Text:
+ return typeof (string);
+ default:
+ throw new ArgumentOutOfRangeException(string.Format("Cannot convert {0} to System.Type", optype));
+ }
+ }
+
+ /// <summary>
+ /// Get friendly names for field numbers.
+ /// </summary>
+ public static IDictionary<string, string> FieldNumbersToNames(this DataSet dataset)
+ {
+ return dataset.Fields.FieldNumbersToNames();
+ }
+
+ /// <summary>
+ /// Get friendly names for field numbers.
+ /// </summary>
+ public static IDictionary<string, string> FieldNumbersToNames(this IDictionary<string, DataSet.Field> fieldInfos)
+ {
+ var names = new Dictionary<string, string>();
+ foreach(var number in fieldInfos.Keys)
+ {
+ names[fieldInfos[number].Name] = number;
+ }
+ return names;
+ }
+ }
+}
View
69 BigML/Helpers/JsonContent.cs
@@ -0,0 +1,69 @@
+using System.Collections.Generic;
+using System.IO;
+using System.Json;
+using System.Net.Http.Headers;
+using System.Text;
+
+namespace System.Net.Http
+{
+ /// <summary>
+ /// Helper class for Json content
+ /// </summary>
+ public class JsonContent : StringContent
+ {
+ public JsonContent(JsonValue content): base(content.ToString(), Encoding.UTF8, "application/json")
+ {
+ }
+ }
+
+ /// <summary>
+ /// Helpers for addding content to MultiFormDataContent
+ /// </summary>
+ public static class Helpers
+ {
+ public static void Add(this MultipartFormDataContent source, KeyValuePair<string, JsonValue> contentName)
+ {
+ source.Add(contentName.Value, contentName.Key);
+ }
+
+ public static void Add(this MultipartFormDataContent source, JsonObject json)
+ {
+ foreach(var kv in json)
+ {
+ source.Add(kv);
+ };
+ }
+
+ public static void Add(this MultipartFormDataContent source, string content, string name)
+ {
+ source.Add(new StringContent(content, Encoding.UTF8), name);
+ }
+
+ public static void Add(this MultipartFormDataContent source, JsonValue content, string name)
+ {
+ source.Add(new JsonContent(content), name);
+ }
+
+ public static void Add(this MultipartFormDataContent source, int content, string name)
+ {
+ source.Add(new StringContent(content.ToString(), Encoding.UTF8), name);
+ }
+
+ public static void Add(this MultipartFormDataContent source, bool content, string name)
+ {
+ source.Add(new StringContent(content.ToString(), Encoding.UTF8), name);
+ }
+
+ public static void Add(this MultipartFormDataContent source, Stream content, MediaTypeHeaderValue mediaType, string fileName)
+ {
+ var part = new StreamContent(content);
+ part.Headers.ContentType = mediaType;
+ source.Add(part, @"""file""", string.Format(@"""{0}""", fileName));
+ }
+
+ public static void Add(this MultipartFormDataContent source, Stream content, string fileName)
+ {
+ source.Add(content, new MediaTypeHeaderValue("text/csv"), fileName);
+ }
+ }
+}
View
10 BigML/Helpers/OpType.cs
@@ -0,0 +1,10 @@
+namespace BigML
+{
+ public enum OpType
+ {
+ Error = 0,
+ Numeric=1,
+ Categorical=2,
+ Text=3
+ }
+}
View
46 BigML/Helpers/Reflection.cs
@@ -0,0 +1,46 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Reflection;
+using System.Reflection.Emit;
+
+namespace BigML
+{
+ public static class Reflection
+ {
+ /// <summary>
+ /// Compile lambda expression to an assembly
+ /// </summary>
+ public static Func<S, T> CompileToAssembly<S, T>(this LambdaExpression expression, IEnumerable<PropertyInfo> inputs, string assemblyName, string directoryName)
+ {
+ var domain = AppDomain.CurrentDomain;
+ var assembly = new AssemblyName("Assembly");
+ var assemblyBuilder = domain.DefineDynamicAssembly(assembly, AssemblyBuilderAccess.RunAndSave, directoryName);
+ var module = assemblyBuilder.DefineDynamicModule("Module", assemblyName);
+ var typeBuilder = module.DefineType("BigML", TypeAttributes.Public | TypeAttributes.Abstract | TypeAttributes.Sealed);
+ var methodBuilder = typeBuilder.DefineMethod("Predict", MethodAttributes.Public | MethodAttributes.Static, typeof(T), new[] { typeof(S) });
+ expression.CompileToMethod(methodBuilder);
+ var type = typeBuilder.CreateType();
+ assemblyBuilder.Save(assemblyName);
+ var predict = type.GetMethod("Predict");
+
+ return delegate(S s)
+ {
+ var args = inputs.GetValue(s);
+ return (T)Convert.ChangeType(predict.Invoke(null, args.ToArray()), typeof(T));
+ };
+ }
+
+ /// <summary>
+ /// Get values of given list of properties of a value.
+ /// </summary>
+ /// <param name="enumToName">Convert enums to name. Default true, since enums are categorical</param>
+ public static IEnumerable<object> GetValue<T>(this IEnumerable<PropertyInfo> properties, T obj, object[] index = null, bool enumToName = true)
+ {
+ return from property in properties
+ let value = property.GetValue(obj, index)
+ select enumToName && value.GetType().IsEnum ? value.ToString() : value;
+ }
+ }
+}
View
79 BigML/Model/Arguments.cs
@@ -0,0 +1,79 @@
+using System.Collections.Generic;
+using System.Json;
+using System.Linq;
+
+namespace BigML
+{
+ public partial class Model
+ {
+ public class Arguments : Arguments<Model>
+ {
+ public Arguments()
+ {
+ Inputs = new List<string>();
+ Range = new List<int>(2);
+ }
+
+ /// <summary>
+ /// A valid dataset/id.
+ /// </summary>
+ public string DataSet
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// Specifies the percentage of instances that you do not want to be considered directly when building the model
+ /// but to use them to later prune the model and obtain and model that generalizes better.
+ /// </summary>
+ public double HoldOut
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// Specifies the ids of the fields that you want to use as predictors to create the model.
+ /// TODO use Field?
+ /// </summary>
+ public ICollection<string> Inputs
+ {
+ get;
+ private set;
+ }
+
+ /// <summary>
+ /// Specifies the id of the field that you want to predict.
+ /// TODO use Field?
+ /// </summary>
+ public string Objective
+ {
+ get;
+ set;
+ }
+
+ /// <summary>
+ /// The range of successive instances to build the model.
+ /// </summary>
+ public ICollection<int> Range
+ {
+ get;
+ private set;
+ }
+
+ public override JsonValue ToJson()
+ {
+ dynamic json = base.ToJson();
+
+ if(!string.IsNullOrWhiteSpace(DataSet)) json.dataset = DataSet;
+ if (!double.IsNaN(HoldOut)) json.holdout = HoldOut;
+ if(Inputs.Count > 0) json.input_fields = new JsonArray(Inputs.Select(input => (JsonValue)input));
+ if (!string.IsNullOrWhiteSpace(Objective)) json.Objective = new JsonArray((JsonValue)Objective);
+ if(Range.Count >= 2) json.range = new JsonArray(Range.Take(2).Select(index => (JsonValue)index));
+
+ return json;
+ }
+ }
+ }
+}
View
43 BigML/Model/BigMLClientModel.cs
@@ -0,0 +1,43 @@
+using System.Threading.Tasks;
+
+namespace BigML
+{
+ public partial class Client
+ {
+ /// <summary>
+ /// Create a model using supplied arguments.
+ /// </summary>
+ public Task<Model> Create(Model.Arguments arguments)
+ {
+ return Create<Model>(arguments);
+ }
+
+ /// <summary>
+ /// Create a model.
+ /// </summary>
+ /// <param name="dataset">A DataSet instance</param>
+ /// <param name="name">The name you want to give to the new model. </param>
+ /// <param name="inputFields">Specifies the ids of the fields that you want to use as predictors to create the model. </param>
+ /// <param name="objectiveField">Specifies the id of the field that you want to predict.</param>
+ public Task<Model> Create(DataSet dataset, string name = null, string[] inputFields = null, string objectiveField = null, Model.Arguments arguments = null)
+ {
+ arguments = arguments ?? new Model.Arguments();
+ if (!string.IsNullOrWhiteSpace(name)) arguments.Name = name;
+ if (inputFields != null && inputFields.Length > 0)
+ {
+ foreach(var input in arguments.Inputs) arguments.Inputs.Add(input);
+ }
+ if (!string.IsNullOrWhiteSpace(objectiveField)) arguments.Objective = objectiveField;
+ arguments.DataSet = dataset.Resource;
+ return Create<Model>(arguments);
+ }
+
+ /// <summary>
+ /// List all models
+ /// </summary>
+ public Query<Model.Filterable, Model.Orderable, Model> ListModels()
+ {
+ return new ModelListing(List<Model>);
+ }
+ }
+}
View
96 BigML/Model/Description.cs
@@ -0,0 +1,96 @@
+using System.Collections.Generic;
+using System.Json;
+using System.Linq;
+using System.Linq.Expressions;
+
+namespace BigML
+{
+ public partial class Model
+ {
+ public new class Description
+ {
+ readonly dynamic _description;
+ readonly IEnumerable<string> _inputFields;
+
+ internal Description(JsonValue description, IEnumerable<string> inputfields)
+ {
+ _description = description;
+ _inputFields = inputfields;
+ }
+
+ /// <summary>
+ /// Compile Model description to Expression
+ /// </summary>
+ public LambdaExpression Expression()
+ {
+ var parameters = new Dictionary<string, ParameterExpression>();
+ foreach (var field in Fields)
+ {
+ if (!_inputFields.Contains(field.Key)) continue;
+ var type = field.Value.OpType.TypeOf();
+ var parameter = System.Linq.Expressions.Expression.Parameter(type, field.Value.Name);
+ parameters[field.Key] = parameter;
+ }
+
+ var body = Root.Expression(parameters);
+ var lambda = System.Linq.Expressions.Expression.Lambda(body, parameters.Values);
+ return lambda;
+ }
+
+ /// <summary>
+ /// A dictionary with an entry per field in the model.
+ /// Each entry includes the column number in original source, the name of the field, the type of the field, and the summary.
+ /// </summary>
+ public IDictionary<string, DataSet.Field> Fields
+ {
+ get
+ {
+ var dictionary = new Dictionary<string, DataSet.Field>();
+ foreach (var kv in _description.fields)
+ {
+ dictionary[kv.Key] = new DataSet.Field(kv.Value);
+ }
+ return dictionary;
+ }
+ }
+
+ /// <summary>
+ /// The type of model. So far you will only get "stree".
+ /// </summary>
+ public string Kind
+ {
+ get { return _description.kind; }
+ }
+
+ /// <summary>
+ /// The dataset's locale.
+ /// </summary>
+ public string Locale
+ {
+ get { return _description.locale; }
+ }
+
+ /// <summary>
+ /// Strategy followed by the model in case it founds a missing value.
+ /// So far you will only get "last_prediction".
+ /// </summary>
+ public string MissingStrategy
+ {
+ get { return _description.missing_strategy; }
+ }
+
+ /// <summary>
+ /// A Node Object, a tree-like recursive structure representing the model.
+ /// </summary>
+ public Node Root
+ {
+ get { return new Node(_description.root); }
+ }
+
+ public override string ToString()
+ {
+ return _description.ToString();
+ }
+ }
+ }
+}
View
93 BigML/Model/Filterable.cs
@@ -0,0 +1,93 @@
+using BigML.Meta;
+
+namespace BigML
+{
+ public partial class Model
+ {
+ /// <summary>
+ /// Filterable properties for Model
+ /// </summary>
+ public class Filterable : Filterable<Model>
+ {
+ /// <summary>
+ /// The number of fields in the dataset.
+ /// </summary>
+ public Int Columns
+ {
+ get { return Object.columns; }
+ }
+
+ /// <summary>
+ /// The dataset/id that was used to build the model.
+ /// </summary>
+ public String DataSet
+ {
+ get { return Object.dataset; }
+ }
+
+ /// <summary>
+ /// Whether the dataset is still available or has been deleted.
+ /// </summary>
+ public Bool DataStatus
+ {
+ get { return Object.dataset_status; }
+ }
+
+ /// <summary>
+ /// The holdout size used to build the model.
+ /// </summary>
+ public Double HouldOut
+ {
+ get { return Object.holdout; }
+ }
+
+ /// <summary>
+ /// The total number of fields in the dataset used to build the model.
+ /// </summary>
+ public Int MaxColumns
+ {
+ get { return Object.max_columns; }
+ }
+
+ /// <summary>
+ /// The total number of rows in the dataset used to build the model.
+ /// </summary>
+ public Int MaxRows
+ {
+ get { return Object.max_rows; }
+ }
+
+ /// <summary>
+ /// The current number of predictions that use this source.
+ /// </summary>
+ public Int NumberOfPredictions
+ {
+ get { return Object.number_of_predictions; }
+ }
+
+ /// <summary>
+ /// The total number of rows in the dataset.
+ /// </summary>
+ public Int Rows
+ {
+ get { return Object.rows; }
+ }
+
+ /// <summary>
+ /// The source/id that was used to build the dataset.
+ /// </summary>
+ public String Source
+ {
+ get { return Object.source; }
+ }
+
+ /// <summary>
+ /// Whether the source is still available or has been deleted.
+ /// </summary>
+ public Bool SourceStatus
+ {
+ get { return Object.source_status; }
+ }
+ }
+ }
+}
View
163 BigML/Model/Model.cs
@@ -0,0 +1,163 @@
+using System.Collections.Generic;
+using System.Json;
+
+namespace BigML
+{
+ /// <summary>
+ /// A model is a tree-like representation of your dataset with predictive power.
+ /// You can create a model selecting which fields from your dataset you want to use as input fields (or predictors) and which field you do want to predict, the objective field.
+ /// </summary>
+ public partial class Model : Response
+ {
+ /// <summary>
+ /// The number of fields in the model.
+ /// </summary>
+ public int Columns
+ {
+ get { return Object.columns; }
+ }
+
+ /// <summary>
+ /// The dataset/id that was used to build the dataset.
+ /// </summary>
+ public string DataSet
+ {
+ get { return Object.dataset; }
+ }
+
+ /// <summary>
+ /// Whether the dataset is still available or has been deleted.
+ /// </summary>
+ public bool DataSetStatus
+ {
+ get { return Object.dataset_status; }
+ }
+
+ /// <summary>
+ /// The holdout size used to build the model.
+ /// </summary>
+ public double Holdout
+ {
+ get { return Object.holdout; }
+ }
+
+ /// <summary>
+ /// The list of input fields's ids used to build the model.
+ /// </summary>
+ public IEnumerable<string> InputFields
+ {
+ get
+ {
+ return (Object.input_fields as JsonValue).Select(field => (string)field);
+ }
+ }
+
+ /// <summary>
+ /// Dataset's locale
+ /// </summary>
+ public string Locale
+ {
+ get { return Object.locale; }
+ }
+
+ /// <summary>
+ /// The total number of fields in the dataset used to build the model.
+ /// </summary>
+ public int MaxColumns
+ {
+ get { return Object.max_columns; }
+ }
+
+ /// <summary>
+ /// The total number of instances in the dataset used to build the model.
+ /// </summary>
+ public int MaxRows
+ {
+ get { return Object.max_rows; }
+ }
+
+ /// <summary>
+ /// All the information that you need to recreate or use the model on your own.
+ /// It includes a very intuitive description of the tree-like structure that made the model up and the field's dictionary describing the fields and their summaries.
+ /// </summary>
+ public Description ModelDescription
+ {
+ get { return new Description(Object.model, InputFields); }
+ }
+
+ /// <summary>
+ /// The name of the model as your provided or based on the name of the dataset by default.
+ /// </summary>
+ public string Name
+ {
+ get { return Object.name; }
+ }
+
+ /// <summary>
+ /// The current number of predictions that use this model.
+ /// </summary>
+ public int NumberOfPredictions
+ {
+ get { return Object.number_of_predictions; }
+ }
+
+ /// <summary>
+ /// Specifies the id of the field that the model predicts.
+ /// </summary>
+ public string ObjectiveField
+ {
+ get { return Object.objective_fields[0]; }
+ }
+
+ /// <summary>
+ /// The range of instances used to build the model.
+ /// </summary>
+ public IEnumerable<int> Range
+ {
+ get
+ {
+ return (Object.range as JsonValue).Select(r => (int)r);
+ }
+ }
+
+ /// <summary>
+ /// The total number of instances used to build the model.
+ /// </summary>
+ public int Rows
+ {
+ get { return Object.rows; }
+ }
+
+ /// <summary>
+ /// The number of bytes of the dataset that were used to create this model.
+ /// </summary>
+ public int Size
+ {
+ get { return Object.size; }
+ }
+
+ /// <summary>
+ /// The source/id that was used to build the dataset.
+ /// </summary>
+ public string Source
+ {
+ get { return Object.source_id; }
+ }
+
+ /// <summary>
+ /// Whether the source is still available or has been deleted.
+ /// </summary>
+ public bool SourceStatus
+ {
+ get { return Object.source_status; }
+ }
+
+ /// <summary>
+ /// A description of the status of the model. It includes a code, a message, and some extra information.
+ /// </summary>
+ public Status StatusMessage
+ {
+ get { return new Status(Object.status); }
+ }
+ }
+}
View
13 BigML/Model/ModelListing.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Threading.Tasks;
+
+namespace BigML
+{
+ public class ModelListing : Query<Model.Filterable, Model.Orderable, Model>
+ {
+ public ModelListing(Func<string, Task<Listing<Model>>> client)
+ : base(client)
+ {
+ }
+ }
+}
View
78 BigML/Model/Node.cs
@@ -0,0 +1,78 @@
+using System.Collections.Generic;
+using System.Json;
+using System.Linq;
+using System.Linq.Expressions;
+
+namespace BigML
+{
+ public partial class Model
+ {
+ /// <summary>
+ /// A tree-like recursive structure representing the model.
+ /// </summary>
+ public class Node
+ {
+ readonly dynamic _node;
+ internal Node(JsonValue json)
+ {
+ _node = json;
+ }
+
+ internal Expression Expression(Dictionary<string, ParameterExpression> parameters)
+ {
+ var result = System.Linq.Expressions.Expression.Constant(Output) as Expression;
+ return Children.Aggregate(result,
+ (current, child) =>
+ System.Linq.Expressions.Expression.Condition(
+ child.Predicate.Expression(parameters), child.Expression(parameters),
+ current));
+ }
+
+ /// <summary>
+ /// Array of child Node Objects.
+ /// </summary>
+ public IEnumerable<Node> Children
+ {
+ get
+ {
+ return (_node.children as JsonValue).Select(child => new Node(child));
+ }
+ }
+
+ /// <summary>
+ /// Number of instances classified by this node.
+ /// </summary>
+ public int Count
+ {
+ get { return _node.count; }
+ }
+
+ /// <summary>
+ /// Distribution of the objective field at this node.
+ /// </summary>
+ public JsonArray Distribution
+ {
+ get
+ {
+ return _node.distribution;
+ }
+ }
+
+ /// <summary>
+ /// Prediction at this node (number or string)
+ /// </summary>
+ public string Output
+ {
+ get { return _node.output; }
+ }
+
+ /// <summary>
+ /// Predicate structure to make a decision at this node.
+ /// </summary>
+ public Predicate Predicate
+ {
+ get { return new Predicate(_node.predicate); }
+ }
+ }
+ }
+}
View
95 BigML/Model/Orderable.cs
@@ -0,0 +1,95 @@
+using BigML.Meta;
+
+namespace BigML
+{
+ using Meta.Key;
+
+ public partial class Model
+ {
+ /// <summary>
+ /// Filterable properties for Model
+ /// </summary>
+ public class Orderable : Orderable<Model>
+ {
+ /// <summary>
+ /// The number of fields in the dataset.
+ /// </summary>
+ public Int Columns
+ {
+ get { return Object.columns; }
+ }
+
+ /// <summary>
+ /// The dataset/id that was used to build the model.
+ /// </summary>
+ public String DataSet
+ {
+ get { return Object.dataset; }
+ }
+
+ /// <summary>
+ /// Whether the dataset is still available or has been deleted.
+ /// </summary>
+ public Bool DataStatus
+ {
+ get { return Object.dataset_status; }
+ }
+
+ /// <summary>
+ /// The holdout size used to build the model.
+ /// </summary>
+ public Double HouldOut
+ {
+ get { return Object.holdout; }
+ }
+
+ /// <summary>
+ /// The total number of fields in the dataset used to build the model.
+ /// </summary>
+ public Int MaxColumns
+ {
+ get { return Object.max_columns; }
+ }
+
+ /// <summary>
+ /// The total number of rows in the dataset used to build the model.
+ /// </summary>
+ public Int MaxRows
+ {
+ get { return Object.max_rows; }
+ }
+
+ /// <summary>
+ /// The current number of predictions that use this source.
+ /// </summary>
+ public Int NumberOfPredictions
+ {
+ get { return Object.number_of_predictions; }
+ }
+
+ /// <summary>
+ /// The total number of rows in the dataset.
+ /// </summary>
+ public Int Rows
+ {
+ get { return Object.rows; }
+ }
+
+ /// <summary>
+ /// The source/id that was used to build the dataset.
+ /// </summary>
+ public String Source
+ {
+ get { return Object.source; }
+ }
+
+ /// <summary>
+ /// Whether the source is still available or has been deleted.
+ /// </summary>
+ public Bool SourceStatus
+ {
+ get { return Object.source_status; }
+ }
+ }
+ }
+}
View
98 BigML/Model/Predicate.cs
@@ -0,0 +1,98 @@
+using System;
+using System.Collections.Generic;
+using System.Json;
+using System.Linq.Expressions;
+
+namespace BigML
+{
+ public partial class Model
+ {
+ /// <summary>
+ /// Predicate structure to make a decision at each node.
+ /// </summary>
+ public class Predicate
+ {
+ readonly dynamic _predicate;
+ internal Predicate(JsonValue json)
+ {
+ _predicate = json;
+ }
+
+ internal Expression Expression(Dictionary<string, ParameterExpression> parameters)
+ {
+ if (IsSimple)
+ {
+ return System.Linq.Expressions.Expression.Constant(Constant);
+ }
+ var value = default(double);
+ var x = Value as object;
+ if (double.TryParse(Value, out value)) x = value;
+
+ switch (Operator)
+ {
+ case ">":
+
+ return System.Linq.Expressions.Expression.GreaterThan(parameters[Field],
+ System.Linq.Expressions.Expression.
+ Constant(x));
+ case ">=":
+ return System.Linq.Expressions.Expression.GreaterThanOrEqual(parameters[Field],
+ System.Linq.Expressions.
+ Expression.
+ Constant(x));
+ case "<":
+ return System.Linq.Expressions.Expression.LessThan(parameters[Field],
+ System.Linq.Expressions.Expression.
+ Constant(Value));
+ case "<=":
+ return System.Linq.Expressions.Expression.LessThanOrEqual(parameters[Field],
+ System.Linq.Expressions.Expression.
+ Constant(x));
+ case "=":
+ return System.Linq.Expressions.Expression.Equal(parameters[Field],
+ System.Linq.Expressions.Expression.
+ Constant(x));
+ default:
+ throw new Exception("unknown operator");
+ }
+ }
+
+ /// <summary>
+ /// Is leaf node (boolean)
+ /// </summary>
+ public bool IsSimple
+ {
+ get { return _predicate.JsonType == JsonType.Boolean; }
+ }
+
+ public bool Constant
+ {
+ get { return _predicate; }
+ }
+
+ /// <summary>
+ /// Field's id used for this decision.
+ /// </summary>
+ public string Field
+ {
+ get { return _predicate.field; }
+ }
+
+ /// <summary>
+ /// Type of test used for this field.
+ /// </summary>
+ public string Operator
+ {
+ get { return _predicate.@operator; }
+ }
+
+ /// <summary>
+ /// Value of the field to make this node decision (number or string)
+ /// </summary>
+ public string Value
+ {
+ get { return _predicate.value; }
+ }
+ }
+ }
+}
View
28 BigML/Model/Status.cs
@@ -0,0 +1,28 @@
+using System.Json;
+
+namespace BigML
+{
+ public partial class Model
+ {
+ /// <summary>
+ /// Creating a model is a process that can take just a few seconds or a few days depending on the size of the dataset used as input and on the work load of BigML's systems.
+ /// The model goes through a number of states until its fully completed.
+ /// Through the status field in the model you can determine when the model has been fully processed and ready to be used to create predictions.
+ /// </summary>
+ public class Status : Status<Model>
+ {
+ internal Status(JsonValue status): base(status)
+ {
+ }
+
+ /// <summary>
+ /// How far BigML.io has progressed processing the model.
+ /// </summary>
+ public double Progress
+ {
+ get { return _status.progress; }
+ }
+
+ }
+ }
+}
View
54 BigML/Prediction/Arguments.cs
@@ -0,0 +1,54 @@
+using System.Collections.Generic;
+using System.Json;
+
+namespace BigML
+{
+ public partial class Prediction
+ {
+ public class Arguments : Arguments<Prediction>
+ {
+ public Arguments()
+ {
+ InputData = new Dictionary<string, object>();
+ }
+
+ /// <summary>
+ /// An object with field's id/value pairs representing the instance you want to create a prediction for.
+ /// </summary>
+ public IDictionary<string,object> InputData
+ {
+ get;
+ private set;
+ }
+
+ /// <summary>
+ /// A valid model/id.
+ /// </summary>
+ public string Model
+ {
+ get;
+ set;
+ }
+
+ public override JsonValue ToJson()
+ {
+ dynamic json = base.ToJson();
+
+ json.model = Model;
+ if(InputData.Count > 0)
+ {
+ var input_data = new JsonObject();
+ foreach(var kv in InputData)
+ {
+ JsonPrimitive value;
+ JsonPrimitive.TryCreate(kv.Value, out value);
+ input_data[kv.Key] = value;
+ }
+ json.input_data = input_data;
+ }
+
+ return json;
+ }
+ }
+ }
+}
View
33 BigML/Prediction/BigMLClientPrediction.cs
@@ -0,0 +1,33 @@
+using System.Threading.Tasks;
+
+namespace BigML
+{
+ public partial class Client
+ {
+ /// <summary>
+ /// Create a new prediction.
+ /// </summary>
+ public Task<Prediction> Create(Prediction.Arguments arguments)
+ {
+ return Create<Prediction>(arguments);
+ }
+
+ /// <summary>
+ /// Create a new prediction.
+ /// </summary>
+ /// <param name="model">A valid Model</param>
+ /// <param name="name">The name you want to give to the new prediction. </param>
+ public Task<Prediction> Create(Model model, string name = null, Prediction.Arguments arguments = null)
+ {
+ arguments = arguments ?? new Prediction.Arguments();
+ if (!string.IsNullOrWhiteSpace(name)) arguments.Name = name;
+ arguments.Model = model.Resource;
+ return Create<Prediction>(arguments);
+ }
+
+ public Query<Prediction.Filterable, Prediction.Orderable, Prediction> ListPredictions()
+ {
+ return new PredictionListing(List<Prediction>);
+ }
+ }
+}
View
73 BigML/Prediction/Filterable.cs
@@ -0,0 +1,73 @@
+using BigML.Meta;
+
+namespace BigML
+{
+ public partial class Prediction
+ {
+ /// <summary>
+ /// Filterable properties for Prediction.
+ /// </summary>
+ public abstract class Filterable : Filterable<Prediction>
+ {
+ /// <summary>
+ /// The dataset/id that was used to build the model.
+ /// </summary>
+ public String DataSet
+ {
+ get { return Object.dataset; }
+ }
+
+ /// <summary>
+ /// Whether the dataset is still available or has been deleted.
+ /// </summary>
+ public Bool DataStatus
+ {
+ get { return Object.dataset_status; }
+ }
+
+ /// <summary>
+ /// The model/id that was used to build the prediction.
+ /// </summary>
+ public String Model
+ {
+ get { return Object.model; }
+ }
+
+ /// <summary>
+ /// Whether the model is still available or has been deleted.
+ /// </summary>
+ public Bool ModelStatus
+ {
+ get { return Object.model_status; }
+ }
+
+ /// <summary>
+ /// The objective field of the prediction.
+ /// </summary>
+ //[Name("objective_fields")]
+ //public String ObjectiveField { get { return Object.model_status; } }
+
+ /// <summary>
+ /// The objective field of the prediction.
+ /// </summary>
+ //[Name("prediction")]
+ //public String Prediction { get { return Object.model_status; } }
+
+ /// <summary>
+ /// The source/id that was used to build the dataset.
+ /// </summary>
+ public String Source
+ {
+ get { return Object.source; }
+ }
+
+ /// <summary>
+ /// Whether the source is still available or has been deleted.
+ /// </summary>
+ public Bool SourceStatus
+ {
+ get { return Object.source_status; }
+ }
+ }
+ }
+}
View
75 BigML/Prediction/Orderable.cs
@@ -0,0 +1,75 @@
+using BigML.Meta;
+
+namespace BigML
+{
+ using Meta.Key;
+
+ public partial class Prediction
+ {
+ /// <summary>
+ /// Orderable properties for Prediction.
+ /// </summary>
+ public class Orderable : Orderable<Prediction>
+ {
+ /// <summary>
+ /// The dataset/id that was used to build the model.
+ /// </summary>
+ public String DataSet
+ {
+ get { return Object.dataset; }
+ }
+
+ /// <summary>
+ /// Whether the dataset is still available or has been deleted.
+ /// </summary>
+ public Bool DataStatus
+ {
+ get { return Object.dataset_status; }
+ }
+
+ /// <summary>
+ /// The model/id that was used to build the prediction.
+ /// </summary>
+ public String Model
+ {
+ get { return Object.model; }
+ }
+
+ /// <summary>
+ /// Whether the model is still available or has been deleted.
+ /// </summary>
+ public Bool ModelStatus
+ {
+ get { return Object.model_status; }
+ }
+
+ /// <summary>
+ /// The objective field of the prediction.
+ /// </summary>
+ //[Name("objective_fields")]
+ //public String ObjectiveField { get { return Object.columns; } }
+
+ /// <summary>
+ /// The objective field of the prediction.
+ /// </summary>
+ //[Name("prediction")]
+ //public String Prediction { get { return Object.columns; } }
+
+ /// <summary>
+ /// The source/id that was used to build the dataset.
+ /// </summary>
+ public String Source
+ {
+ get { return Object.source; }
+ }
+
+ /// <summary>
+ /// Whether the source is still available or has been deleted.
+ /// </summary>
+ public Bool SourceStatus
+ {
+ get { return Object.source_status; }
+ }
+ }
+ }
+}
View
40 BigML/Prediction/Predicate.cs
@@ -0,0 +1,40 @@
+using System.Json;
+
+namespace BigML
+{
+ public partial class Prediction
+ {
+ public class Predicate
+ {
+ readonly dynamic _predicate;
+ internal Predicate(JsonValue json)
+ {
+ _predicate = json;