Skip to content

Commit

Permalink
first tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Jul 25, 2018
1 parent ae66acb commit e4e7fe5
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 45 deletions.
10 changes: 5 additions & 5 deletions examples/DataFrameExample.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2042
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataFrameExample", "DataFrame\DataFrameExample.csproj", "{1F3267A2-7B3D-40BC-A030-3D33D659DE74}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GroupBy_Plot", "GroupBy_Plot\GroupBy_Plot.csproj", "{81BD059C-A2D0-4CA9-A61B-27980DE92199}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1F3267A2-7B3D-40BC-A030-3D33D659DE74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1F3267A2-7B3D-40BC-A030-3D33D659DE74}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1F3267A2-7B3D-40BC-A030-3D33D659DE74}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1F3267A2-7B3D-40BC-A030-3D33D659DE74}.Release|Any CPU.Build.0 = Release|Any CPU
{81BD059C-A2D0-4CA9-A61B-27980DE92199}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{81BD059C-A2D0-4CA9-A61B-27980DE92199}.Debug|Any CPU.Build.0 = Debug|Any CPU
{81BD059C-A2D0-4CA9-A61B-27980DE92199}.Release|Any CPU.ActiveCfg = Release|Any CPU
{81BD059C-A2D0-4CA9-A61B-27980DE92199}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
36 changes: 0 additions & 36 deletions examples/DataFrameExample/Program.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AssemblyName>DataFrameExample</AssemblyName>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="OxyPlot.Core" Version="1.0.0" />
<PackageReference Include="OxyPlot.Wpf" Version="1.0.0" />
<PackageReference Include="OxyPlot.Core" Version="2.0.0-unstable1035" />
<PackageReference Include="Scikit.ML.DataFrame" Version="0.3.0.1" />
</ItemGroup>

Expand Down
45 changes: 45 additions & 0 deletions examples/GroupBy_Plot/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.IO;
using System.Linq;
using Scikit.ML.DataFrame;
using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;
using Microsoft.ML.Runtime.Data;

namespace GroupBy_Plot
{
class Program
{
static void Main(string[] args)
{
var df = DataFrame.ReadCsv("airquality.csv");
Console.WriteLine("Shape: {0}", df.Shape);
Console.WriteLine("Columns: {0}", string.Join(",", df.Columns));

Console.WriteLine("df.iloc[0, 1] = {0}", df.iloc[0, 1]);
Console.WriteLine("df.loc[0, 'Ozone'] = {0}", df.loc[0, "Ozone"]);

var monthColumn = df["Month"];
var min = (double)(DvInt4)monthColumn.Aggregate(AggregatedFunction.Min).Get(0); // Syntax should be improved.
var max = (double)(DvInt4)monthColumn.Aggregate(AggregatedFunction.Max).Get(0); // Syntax should be improved.
df["MonthFrac"] = (df["Month"] - min) / (max - min);
Console.WriteLine("Head\n{0}", df.Head());
var gr = df.GroupBy(new[] { "MonthFrac" }).Sum();
Console.WriteLine("Grouped by MonthFrac\n{0}", gr);

var gr2 = df.Drop(new[] { "Ozone", "Solar_R" }).Copy().GroupBy(new[] { "MonthFrac" }).Sum();
Console.WriteLine("Grouped by MonthFrac, no Ozone\n{0}", gr2);

var plot = new PlotModel { Title = "Simple Graph" };
var serie = new ScatterSeries();
serie.Points.AddRange(Enumerable.Range(0, gr.Shape.Item1).Select(i => new ScatterPoint((double)gr2.iloc[i, 0], (float)gr2.iloc[i, 2])));
plot.Series.Add(serie);
plot.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = gr2.Columns[0] });
plot.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Title = gr2.Columns[2] });

var plotString = SvgExporter.ExportToString(plot, 600, 400, true);
File.WriteAllText("graph2.svg", plotString);
}
}
}
File renamed without changes.
17 changes: 17 additions & 0 deletions examples/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

Tutorial to Scikit.ML.DataFrame
===============================

.. contents::
:local:
:depth: 1

DataFrame + GroupBy + Svg Plot
++++++++++++++++++++++++++++++

* `sln <DataFrameExample.sln>`_
* `source <GroupBy_Plot/Program.cs>`_

Output:

.. image:: simple_graph.png
Binary file added examples/simple_graph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e4e7fe5

Please sign in to comment.