Machine Learning For Hackers: Chapter 1, Part 2

I then wanted to show the data graphically.   I Added a ASP.NET Web Form project to my solution and added a Chart to the page.  That Chart points to an objectDataSource that consumes the UFO Library method:

  1. <asp:Chart ID="Chart1" runat="server" DataSourceID="ObjectDataSource1">
  2.     <series>
  3.         <asp:Series Name="Series1" XValueMember="Item4" YValueMembers="Item1">
  4.         </asp:Series>
  5.     </series>
  6.     <chartareas>
  7.         <asp:ChartArea Name="ChartArea1">
  8.         </asp:ChartArea>
  9.     </chartareas>
  10. </asp:Chart>
  11. <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
  12.     SelectMethod="GetDetailData"
  13.     TypeName="Tff.MachineLearningWithFSharp.Chapter01.UFOLibrary">
  14. </asp:ObjectDataSource>

 

When I ran it, I got this:

image

 

So that is cool that the Chart control can access the data and show ‘something’.  I then read this tutorial about how to show every state on the X Axis

image

Unfortunately, I was diving down too deep into the weeds of charting controls, which is really not where I want to be.  I then decided to build a function that aggregates the data

  1. member this.GetSummaryData() =
  2.     let subset =
  3.         this.GetDetailData()
  4.         |> Seq.map(fun (a,b,c,d,e,f,g) -> a,d)
  5.         |> Seq.map(fun (a,b) ->
  6.             a.Year,
  7.             b)
  8.  
  9.     let summary =
  10.         subset
  11.         |> Seq.groupBy fst
  12.         |> Seq.map (fun (a, b) -> (a, b
  13.             |> Seq.countBy snd))

Sure enough, when I look on my console app

 

image

I then decided to switch it so that the state would come up first and each year of UFO sightings would be shown (basically switching the Seq.Map)

  1. |> Seq.map(fun (a,b) ->
  2.     b,
  3.     a.Year)

 

And now:

image

So then I added another method that only returns a state’s aggregate data:

  1. member this.GetSummaryData(stateCode: string) =
  2.     let stateOnly =
  3.         this.GetSummaryData()
  4.         |> Seq.filter(fun (a,_) -> a = stateCode)
  5.     stateOnly

 

And I changed the ASP.NET UI to show that state:

  1. <div class="content-wrapper">
  2.     <asp:DropDownList ID="StatesDropList" runat="server" Width="169px" Height="55px">
  3.         <asp:ListItem Value="AZ"></asp:ListItem>
  4.         <asp:ListItem>MD</asp:ListItem>
  5.         <asp:ListItem>CA</asp:ListItem>
  6.         <asp:ListItem>NC</asp:ListItem>
  7.  
  8.     </asp:DropDownList>
  9.     <br />
  10.     <br />
  11.     <asp:Chart ID="Chart1" runat="server" DataSourceID="ObjectDataSource1" Width="586px">
  12.         <series>
  13.             <asp:Series Name="Series1" XValueMember="item1" YValueMembers="item2">
  14.             </asp:Series>
  15.         </series>
  16.         <chartareas>
  17.             <asp:ChartArea Name="ChartArea1">
  18.                 <AxisX IsLabelAutoFit="False">
  19.                     <LabelStyle Interval="Auto" IsStaggered="True" />
  20.                 </AxisX>
  21.             </asp:ChartArea>
  22.         </chartareas>
  23.     </asp:Chart>
  24.     <br />
  25.     <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
  26.         SelectMethod="GetSummaryData"
  27.         TypeName="Tff.MachineLearningWithFSharp.Chapter01.UFOLibrary">
  28.         <SelectParameters>
  29.             <asp:ControlParameter ControlID="StatesDropList" DefaultValue="NC" Name="stateCode" PropertyName="SelectedValue" Type="String" />
  30.         </SelectParameters>
  31.     </asp:ObjectDataSource>
  32. </div>

 

The problem is this:

image

I need to flatten the subTuple so that only native types are sent to the ODS.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: