Zoltana Predicts March Madness

I’m working on the problem of predicting the winners of the 2014 NCAA men’s college basketball tournament, usually called March Madness. There are a total of 67 games in the tournament so the chances of correctly guessing all 67 by chance is 1 out of 2^67 = 147,573,952,589,676,412,928 which is, well, very hard to do. My prediction system is a work in progress. The system uses C# to create a custom machine learning model.

ZoltanaBooth

Because the prediction system is just C# code implemented as a console application, there really isn’t much to look at. So, to liven things up a bit I created a UI system that uses Microsoft Speech Recognition for input, and Speech Synthesis and the .NET Gadgeteer device for output. I named the entire system Zoltana.

The origin of this name goes back to last year when I created a similar system to give poker advice. I named that system Zoltar after the fortune telling machine you can see at arcades (arcade Zoltar is based on the fortune telling machine in the old movie “Big”). Then a few months ago I created a system to predict the outcomes of the NFL football playoffs and the Super Bowl game. I named that system Zoltara, the idea being she is Zoltar’s sister. So, Zoltana, the basketball predictor, is supposed to be the twin sister of Zoltara, the football predictor.

The system has three main components. The prediction engine computes the predictions. A second console app accepts speech input. The third component is a NET Gadgeteer program to receive information and generate output via a flashing crystal ball.

Here, without any explanation, is the Gadgeteer code:

using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using Gadgeteer.Modules.Seeed;

namespace GadgeteerApp1
{
  public partial class Program
  {
    uint lineStart = 1; // y-cord small display
    static int boothLight = 0; // light toggle
    int testToggle = 0;

    void ProgramStarted()
    {
      Debug.Print("Program Started");
      button.ButtonPressed += button_ButtonPressed;
      button2.ButtonPressed += button2_ButtonPressed;

      usbSerial.Configure(9600,
        GT.Interfaces.Serial.SerialParity.None,
        GT.Interfaces.Serial.SerialStopBits.One, 8);
      usbSerial.SerialLine.Open();
      usbSerial.SerialLine.DataReceived +=
        SerialLine_DataReceived;
    }

    void SerialLine_DataReceived(GT.Interfaces.Serial sender,
      System.IO.Ports.SerialData data)
    {
      Font smallFont =
        Resources.GetFont(Resources.FontResources.small);
      GT.Color red = GT.Color.Red;
      oledDisplay.SimpleGraphics.DisplayText("", smallFont,
        red, 1, lineStart); // not sure why this is needed

      int numBytesToRead = usbSerial.SerialLine.BytesToRead;
      byte[] inputBuffer = new byte[numBytesToRead];
      usbSerial.SerialLine.Read(inputBuffer, 0, numBytesToRead);
      string s =
        new string(
        System.Text.Encoding.UTF8.GetChars(inputBuffer));

      if (s.IndexOf("hello") >= 0)
      {
        multicolorLed.TurnWhite();
      }
      else if (s.IndexOf("yes") >= 0)
      {
        FlashBall(GT.Color.Green, 4);
      }
      else if (s.IndexOf("no") >= 0)
      {
        FlashBall(GT.Color.Red, 4);
      }
      else if (s.IndexOf("goodbye") >= 0)
      {
        FlashBall(GT.Color.Purple, 5);
        multicolorLed.TurnOff();
        oledDisplay.SimpleGraphics.Clear();
      }

      if (lineStart > 120)
     { oledDisplay.SimpleGraphics.Clear(); lineStart = 1; }
      oledDisplay.SimpleGraphics.DisplayText(s, smallFont,
        red, 1, lineStart);
      lineStart += 9;
    }

    void button2_ButtonPressed(Button sender,
      Button.ButtonState state) // system test
    {
      Font smallFont =
        Resources.GetFont(Resources.FontResources.small);
      GT.Color red = GT.Color.Red;
      if (testToggle == 0)
      {
        oledDisplay.SimpleGraphics.DisplayText("testing",
          smallFont, red, 1, lineStart);
        FlashBall(GT.Color.Red, 4);
        testToggle = 1;
      }
      else if (testToggle == 1)
      {
        multicolorLed.TurnOff();
        testToggle = 0;
      }
    }

    void button_ButtonPressed(Button sender,
      Button.ButtonState state) //overhead booth light
    {
      if (boothLight == 0)
      {
        multicolorLed2.TurnRed();
        ++boothLight;
      }
      else if (boothLight == 1)
      {
        multicolorLed2.TurnWhite();
        ++boothLight;
      }
      else if (boothLight == 2)
      {
        multicolorLed2.TurnColor(GT.Color.Yellow);
        ++boothLight;
      }
      else if (boothLight == 3)
      {
        multicolorLed2.TurnColor(GT.Color.Purple);
        ++boothLight;
      }
      else if (boothLight == 4)
      {
        multicolorLed2.TurnOff();
        boothLight = 0;
      }
    }

    void FlashBall(GT.Color color, int times)
    {
      multicolorLed.TurnOff();  // crystal ball
      for (int i = 1; i <= times; ++i)
      {
        multicolorLed.TurnColor(color);
        System.Threading.Thread.Sleep(1000);
        multicolorLed.TurnOff();
        System.Threading.Thread.Sleep(1000);
      }
      multicolorLed.TurnGreen();
    }
  } // class Program
} // ns
This entry was posted in Machine Learning. Bookmark the permalink.