Sunday, July 31, 2016

Do the Political Party Conventions Matter? Not according to the Betting Markets...

Think what you will about the party conventions that just wrapped up, but one thing worth pointing out is that, despite the so-called boost in polling that candidates receive coming out of their convention, temporary as it may be, this boost doesn't really exist if you look at a different metric than polls - the political betting markets.

Political betting markets have often proved to be a better predictor of electoral outcomes than public opinion polls, particularly the further away the analysis is done from Election Day.  So with the Republican and now Democratic conventions just completed, this is what the betting markets have had to say regarding who will win the presidential election...


Click image to enlarge

This is a 30-day snapshot with the conventions occurring during the second half of the chart.  Do you notice those drastic swings for and against Hillary Clinton and Donald Trump?  If not, you're not alone.  There is virtually no discernible change for either candidate.

For the record, as of July 31st, the betting markets favor Hillary Clinton winning the presidency over Donald Trump by a 68 to 35 margin (these are not percentages but rather how many cents it would cost per dollar to "Buy Yes" for each candidate).

So do the conventions matter?  According to the betting markets, not in the slightest.


  

Thursday, July 28, 2016

Basic Minecraft Programming Examples...

In the last post we reviewed how to set up Python for Minecraft.  Once you have it up and running, jump right in and try these two simple scripts that not only demonstrate what Python-for-Minecraft programs look like, but are also both really useful when you're actually playing.


Example 1:  Teleport to your starting location (or any location)

As most Minecrcaft newbies and veterans alike can tell you, sometimes you just want to go back to your "home base" (wherever in your world that might be) without needing to hike all the way there or even needing to figure out where it is.  Wouldn't it be helpful to have an easy way to teleport there whenever you wanted?

As soon as you start a new game, click on "F3" to see lots of in-game details display on the screen.  Pay particular attention to the three "Block" numbers (or XYZ numbers).  Then try this...

from mcpi.minecraft import Minecraft
mc = Minecraft.create()

# Replace these numbers with your three starting "Block" numbers

x = 20
y = 80
z = 16

mc.player.setTilePos(x, y, z)


Example 2:  Instantly build a shelter

Most players have to spend their first day gathering materials to build a shelter before nightfall.  But you can try this instead whenever you want to instantly build yourself a cobblestone shelter right next to your present location.  You can even build it in the sky!

# Get player's location and build a hollow cuboid

from mcpi.minecraft import Minecraft
mc = Minecraft.create()
pos = mc.player.getPos()

x = pos.x
y = pos.y
z = pos.z
width = 10
height = 5
length = 6
blockType = 4
air = 0

mc.setBlocks(x, y, z, x + width, y + height, z + length, blockType)
mc.setBlocks(x+1, y+1, z+1, x + width-1, y + height-1, z + length-1, air)

The result...




  

Wednesday, July 13, 2016

How to Set Up Python for Minecraft...

Most of the online tutorials on this topic seem weak, so here is my step-by-step beginner's tutorial on how to set up your Windows PC so that you can start writing Python programs for Minecraft.

Step #1:  Download and install Python (use any version after 3.5.0).  During installation, make sure to check the box to "Add Python to Path".

Step #2:  Download and install the Minecraft Python API and Spigot.  Go to this link and download the file: "Minecraft Tools.zip".  Extract all of the files, then double-click the file: "Install_API".

Step #3:  Run the Spigot Server.  Open the "Minecraft Tools" folder (that you extracted in Step #2), then double-click the file: "Start_Server".  Without closing the Spigot window, open Minecraft and choose "Multiplayer", then "Add Server".  In the server address box, type "localhost", then "Done".  Double-click the server name listed and your game should start.
  • If you have a compatibility issue when you double-click the server name, exit back to the Minecraft launcher and create a new profile. Edit the settings for that profile by selecting an older version release (for example, 1.9.4) 
You're now totally set up.  In the future, when you want to write the code for your programs, use IDLE (a text editor installed when you installed Python).  In order to execute your finished programs, make sure to run the Spigot server and Minecraft, and simply click "F5" within IDLE.

Some actual programming examples are coming soon.



  

Thursday, July 07, 2016

Using Tableau for Political Visualizations...

If you're curious about how Data Science is being used to analyze political data, look no further than Tableau - an easy-to-use tool for converting analytics into fabulous visualizations.

Recently, Tableau held a Politics Viz Contest to showcase some of the work their users are generating.  The contest winner, Robert Rouse, used data from a Pew Research Center report to visualize increasing political polarization in the U.S. over the past few decades (Click on the image to enlarge and see the details):

https://www.interworks.com/blog/rrouse/2016/06/24/politics-viz-contest-plotting-political-polarization


Or here is one that I personally found interesting - a visualization of how each state has voted in partisan terms since 1964:

https://public.tableau.com/s/gallery/republican-democrat-voting-1946-2012

Or this alternative visualization of state-by-state partisanship in every election since 1916:


https://public.tableau.com/s/gallery/presidential-election-results-1916-2012


Really, if the conjunction of Data Science and Politics is your jam, then it's worth checking out the entire Tableau gallery to see what people are doing in the field.