<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Christian Deveaux on Medium]]></title>
        <description><![CDATA[Stories by Christian Deveaux on Medium]]></description>
        <link>https://medium.com/@christian_deveaux?source=rss-8a92c470522c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*n_DSc_H-c-ZhDoSt.jpg</url>
            <title>Stories by Christian Deveaux on Medium</title>
            <link>https://medium.com/@christian_deveaux?source=rss-8a92c470522c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 11:26:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@christian_deveaux/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A genetic algorithm solving Flappy Bird using data science]]></title>
            <link>https://medium.com/@christian_deveaux/a-genetic-algorithm-solving-flappy-bird-using-data-science-87bcd981cefd?source=rss-8a92c470522c------2</link>
            <guid isPermaLink="false">https://medium.com/p/87bcd981cefd</guid>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[genetic-algorithm]]></category>
            <category><![CDATA[mutation]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[flappy-bird]]></category>
            <dc:creator><![CDATA[Christian Deveaux]]></dc:creator>
            <pubDate>Wed, 18 Mar 2020 16:28:57 GMT</pubDate>
            <atom:updated>2020-03-18T16:28:57.664Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*iYTfFFvj3Dn96RZNG2tp1w.gif" /></figure><h3>Overview</h3><p>Flappy Bird was actually created in the year 2013 by Dong Nguyen and became viral. The game earned Don up to 50.000USD per day thanks to in-app advertisements. In the game you play a bird, which needs to be guided through pipes. It is a “one-button” action game. The user has to tap the screen to let the bird jump to guide him through the pipes. The game is pretty hard and the average score per game is definitely not higher than 10.</p><p>The original game may be played <a href="https://flappybird.io/">here</a>.</p><p>With new skills I acquired with the help of Udacity, I went on to create a project, which consists out of the creation of a Flappy Bird clone and afterwards solving it using a neural network with the hope that weights for the neural network may be found, which “solve” the game. Due to the fact that the game does not have an ending; another metric has to hold up. Since an average human does not normally get a score higher than 10, I think that the game is considered to be “solved” if the AI can pass 1000. A hundred times better than a human? Sounds good to me.</p><h3>Starting the project</h3><p>Before jumping in to code, first the decision for a framework had to be made. I decided to use Python and the “<a href="https://www.pygame.org/">pyGame</a>” package (in version 1.9.6) to create my very first own video game.</p><h4>Programming the game</h4><p>I will not go too much into detail in regard to the logic of the game. The main aspect of this article is the data science part. Feel free to check out the source code, which is linked below.</p><p>During the creation, the game underwent multiple phases, while more and more things were added to it. The first version basically contained just rectangles instead of graphics, during a later phase this became the “training mode” of the project, which can run with a higher FPS count, in turn meaning more training.</p><p>Basically, the game consists out of a few things: The bird jumps when user clicks, the pipes are spawned and move from right to left and a collision detection system, the UI is updated whenever a pipe pair is passed or the player died. The score is not only needed to fulfill our metrics of solving the game, but it is also satisfying to beat a highscore.</p><p>This is the game played by a human:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*0t9e4snOZXAcB6OUclO4Hg.gif" /><figcaption>Pity human having a hard time mastering the game</figcaption></figure><h4>Programming the AI</h4><blockquote>How to win a game you are bad at? Use Data-Science techniques to run a neural network!</blockquote><p>Here we come to the meat of the project. Once the game was playable for humans it had to be made playable by the AI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/1*7jLLZEgAJD3ZT8Ew3S1iFg.png" /><figcaption>Weights of the neural network</figcaption></figure><p>Since this is a data science project, I chose to give the bird a brain and solve the game using a neural network.</p><h4><strong>The birds brain and thinking process</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*mof9NaL4OL72iasewqU3kA.png" /><figcaption>Explaining the bird’s brain</figcaption></figure><p>A bird in the game does not know much, but what it knows is exact. The neural network contains five input variables: The y position of the bird, the y distance to the bottom pipe, the y distance to the top pipe, the x distance to the pipe pair and the y velocity of the bird. No further preprocessing of these data points is needed, and the data is good to be fed to the neural network. Normalization of the inputs was explored, but led to worse results.</p><p>Several different inputs were tried (removing the y velocity, adding the distances to ground and ceiling), but the chosen ones seem to give the best results.</p><p>For the neural network itself one hidden layer with three nodes was chosen, due to the fact that training the neural network with more hidden layers with a genetic algorithm takes a long time and makes debugging very hard. The weights of the neural net are initialized with random values and 90 birds are flying for their lives.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3qX-iE2A-vhV60Ju-G6wJg.png" /><figcaption>How a perceptron works (picture reference: <a href="https://www.udacity.com/">Udacity</a>)</figcaption></figure><p>The output of the neural network is either “Flap” or “Fall” (not flap). Sigmoid was implemented as the activation function.</p><p>Since the way of training differs while using a genetic algorithm (backward passes are not possible to find and correct errors, but instead mutation is used), it was chosen to write the neural network, forward pass and mutation from scratch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/407/1*GqFW-ImpznnRlFUnGCEpBg.png" /><figcaption>In-game representation of what the Bird senses/sees.</figcaption></figure><h4>Natural selection — Breeding and mutation of the fittest</h4><p>After no bird is alive anymore, due to all of them crashing against the border or pipes, it must be made sure that adaptions to the neural network are introduced. In order to know which bird to breed, a fitness of birds was introduced, which is increased for every frame the bird lives. The longer a bird lives, the higher his fitness is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*b1WVkVQXuLDjzjV19VKBGA.gif" /><figcaption>AI starting to learn</figcaption></figure><p>When no bird is left alive, the fitness of birds is evaluated, and the best two birds are chosen to create offspring. The mutation rate for each weight of the neural network is between -0.125 and 0.125 with a 50:50 chance of no mutation happening to the weight. One third of the new birds is cloned and mutated from the fittest bird, the second third is cloned and mutated from the second fittest bird and the final third averages all weights of the two best birds and mutates them. Additionally, the fittest bird of the generation is kept alive and the fittest bird known yet is kept alive.</p><h3>Complications and refinements on the way</h3><p>Especially when messing with the difficulty of the game (e.g. increasing velocity/decreasing pipe y distances), It may occur, that the neural network of every single spawned bird is mutating in wrong directions leading to instant extinction of the generation. To counter this a mechanism was introduced, which initializes one third of the birds with random values if no improvement of the population’s fitness was recorded for 50 generations or longer.</p><p>It was tried to increase the velocity to a point, where the bird jumps higher than the pipe y-distance (image 1 below). The bird’s brain was not able to adapt to these circumstances. It was able to understand that it had to jump late in order to make it (image 2 below) but did not manage to overcome a pipe spawning at the lower end of the screen and always led to extinction of the generation. To master this a jump has to be setup a few flaps ahead, so the bird is falling in between the pipes and then starting to jump (image 3 below). After thousands of generations, the brain was not able to understand how to solve the situation from here on referred as the “setup-situation”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*J2n9MoyHkIq6PEuSdxOGlA.png" /><figcaption>High velocity problems</figcaption></figure><p>It was tried to add additional hidden layers to the network, but it did not solve the issue. Furthermore, adding additional inputs (y distance to ceiling and y distance to floor) did not help either. Neither did a combination of the two.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*nYnD-fJXfajOrCWzD6Vtxg.gif" /><figcaption>Training mode for higher FPS (score &gt; 11.000 by the way)</figcaption></figure><p>In order to perform a quicker training turnaround time, a training mode was introduced, which decreases the detail level and the CPU usage. On a slow PC this increases the FPS significantly. In the training mode no images have to be rendered or rotated. Furthermore, only one bird (instead of all) is drawn, what the bird sees is not rendered either. The introduction of the training mode also introduced the need to change the max FPS using the keyboard, which was implemented additionally to other keyboard shortcuts (toggling details, toggling the bird view). Additionally, command line parameters were added to start the game with different flags set. Notably are two parameters, which lets the human instead of the AI play and another parameter, which always initializes one bird with preset (and provenly good) weights of the neural network. Please refer to the <a href="https://github.com/cr00nkz/Sloppy-Block">repositories readme file</a> for more details.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/355/1*5afkLibJ0s2v4DoBCwzj9w.png" /><figcaption>Problem depiction</figcaption></figure><p>The pipes spawn with a random distance to each other. In an earlier version rare cases led to pipes spawning very close to each other additionally having a large y distance between the two pipe openings. This led to unsolvable situations, as the bird was not able to fall/rise fast enough to reach the gap. Increasing the velocity led to the “setup-situation” described above.</p><h3>Results, Conclusion and ways forward</h3><p>After a few generations, the genes are frequently good enough to solve the game. The bird reached a score of 100.000 pipes passed, which is significantly higher than the original goal of 1.000 pipes passed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*O0F1qYIzGOOyaSN1pjn18Q.gif" /><figcaption>Older version of the game scoring 100.000 points</figcaption></figure><p>Some adaptions to the neural network were tried out with mixed results:</p><ul><li>Having no hidden layer at all seems to perform slightly worse than having one hidden layer in regard to the results.</li><li>Having additional hidden layers needed significantly more generations for the bird to solve the game. Potentially the “setup-issue” described above could be solved with more layers, but in the tests performed this did not happen.</li><li>Making the game easier (e.g. by decreasing the velocity gain or increasing the y distances of the pipe pairs) leads to a far shorter learning time of the bird.</li></ul><p>The learning rate of the completely implemented game is good and in just a few generations the game is solved by the neural network. However, the following adaptations could improve the learning rate even more:</p><ul><li>The input weights could be mutated stronger depending on the type of death. For instance, the input weight of the neural network marking the y distance to the top pipe could undergo a higher mutation, if it was hit.</li><li>The breeding currently averages weights. It may be explored if it is more efficient to swap whole genes instead.</li><li>Breeding of two birds could be performed only if the fitness of the two birds is not too far apart (e.g. one bird instantly died, while the other one achieved a high score).</li><li>The mutation rate of genes could be adapted on the bird’s fitness. The higher the fitness of a bird, the lower the mutation rate could be, since it seems to get closer to an optimum.</li></ul><p>Please go ahead and try out the game yourself. Let the AI play or play yourself.</p><h3>References</h3><ul><li><a href="https://www.pygame.org/">PyGame 1.9.6</a></li><li><a href="https://github.com/cr00nkz/Sloppy-Block">Sloppy Block Github page</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87bcd981cefd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Is PC the Master Race? - Exploring ratings and sales of video games]]></title>
            <link>https://medium.com/analytics-vidhya/is-pc-the-master-race-exploring-ratings-and-sales-of-video-games-6b1f91400d63?source=rss-8a92c470522c------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b1f91400d63</guid>
            <category><![CDATA[pc-masterrace]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Christian Deveaux]]></dc:creator>
            <pubDate>Tue, 17 Dec 2019 07:59:30 GMT</pubDate>
            <atom:updated>2019-12-20T08:42:58.419Z</atom:updated>
            <content:encoded><![CDATA[<h3>Is PC the Master Race? - Exploring and analyzing ratings and sales of video games</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*fkkPwDYbnWSu37L8QcUr8g.jpeg" /></figure><p>If you are like me your toe-nails are burning to finally get answers to these questions:</p><ul><li>Does Metacritic agree, that PC is the master race?</li><li>What ratings would a mature shooter developed by Nintendo on a PC receive?</li><li>Do games get better ratings over time?</li></ul><p>Come and join me to figure out the answers to these questions, while analyzing, demystifying and predicting on a Video Game dataset.</p><blockquote>intense glamrock music for introduction</blockquote><p>Let’s take a look at a dataset provided by <strong>Rush Kirubi </strong>on <a href="https://www.kaggle.com/rush4ratio/video-game-sales-with-ratings">kaggle</a>.</p><p>The dataset contains 16719 different games and 17 columns.<br>The columns in question are Name, Platform, Year of Release, Genre, Publisher, NA Sales, EU Sales, JP Sales, Other Sales, Global Sales, Critic Score, Critic Count, User Score, User Count, Developer, Rating</p><p>Following the CRISP-DM process, the first step is to explore the data we have.</p><h4>Explore</h4><p>The rating column mostly contains (95%+) data for “Everyone”, “Teen”, “Mature” and “E10+”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/995/1*Qy2rLccRb__abvdD0ZyJkg.png" /></figure><p>Quite a few of the games are duplicated in the dataset, this is due to the fact, that each game may be ported to a different platform (even by different developers). This is true for a majority of the games. Out of 16719 games, 11562 are duplicated. An example game ported to 9 consoles (record is 12 with just one game “Need for Speed: Most Wanted” is interestingly “Ratatouille”. A game nobody knows or played, which is reflected by the sales and the rating.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_POFLBTKmxJ4oMWKfWpHEg.png" /></figure><p>Over the course of the dataset (1980 to 2016) A total of 31 platforms have game releases. <br>Due to the fact, that the number of games added in the dataset is getting less and less the earlier we look, only games from 2000 and afterwards are being considered.</p><h4>Clean</h4><p>After the initial analysis of the data, it may now be cleaned. For this the duplicated games are renamed; in total 7961 games.<br>The dataset also contained “corrupt” rows. Corrupt, for our case, means, that it has not yet been released or does not have developers and critic scores.<br>The columns “User Score” also has “tbd” as a possible value; this was instead set to “NaN” (Not a Number) during the cleansing process. 2422 user scores were affected and replaced.</p><h4><strong>Model and visualize</strong></h4><p>Now that we have data to work with it is time to analyze, visualize, model and predict!<br>Let’s see..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*IvoR5QYybC7Rxe70oSsv7A.png" /></figure><p>We can see, that the critics gave better ratings over time than the users, crossing the line in 2010. Are users more sceptic? Are critics being paid?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*on07pJeRIp9oRNwlH2hLww.png" /></figure><p>A lot more users reviewed games over the past, peaking in 2011. Let’s look at some sales figures.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/1*QlwhBj12C5ezV2sSlhdk8Q.png" /></figure><p>From 2003 to 2008 there were the golden ages of games according to the global sales. It is noticable, that the asia area (specifically China and South Korea, since they are “gaming countries”) are not listed here. Not enough sales to be listed.</p><p>Let’s get dirty and look at some publishers</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/1*AUIhL3E4OM6VtUMlpe85pw.png" /></figure><p>Investigating this messy chart a bit closer it is visible, that Nintendo delivers quality results and surprisingly EA Sports ratings are not stable, even though the same game is released year for year. Is Konami with Pro Evolution Soccer catching up? One thing is for sure. Ubisoft does not know.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*ge6hQhO93ovbPTsS6yQJoA.png" /></figure><p>Here we see the unstableness of sports games once again. We can also see, that RPGs are delivering constantly good results. Shooters are getting better.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*FpQk0vDPyQGvZudMrWqWmQ.png" /><figcaption>PC Master-review-race</figcaption></figure><p>The chart you have been waiting for showing without a doubt, that, according to critics, the PC is the master race from 2000 to 2016. The PC seems to have cut off the head of the Wii before it was able to take over and possibly the same will happen to the XBox One, but that is a story of another dataset to tell.</p><h4><strong>Building a Machine Learning Model to predict scores of games</strong></h4><p>In this section we explore how the machine learning libraries provided by scikit-learn may be used to train and test a new model and then use that model to predict outcomes.</p><p>After a bit of tuning and preparing the dataset for machine learning, two machine learning models are created and trained. Both models are not receiving good scores, due to the relatively small amount of input data.</p><p>Let’s try to leverage them anyways and create a Nintendo Shooter in 2017 rated M on different platforms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*KJ_u7c_xi1tkxFSyTNd39w.png" /><figcaption>PC Master-review-race</figcaption></figure><p>We can see, that the PC received the highest ratings. Even though the Wii went uphill in the last year of it’s existance, it seems to deliver the worst (shooter) results. It is possible, that the “M”-Rating is playing a larger role in this case as well, which was not usual for Wii-Games.</p><blockquote>Does the PC favor the PC? — No. This is not how this works.</blockquote><p>Lets look at other possible Nintendo games</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*d2XdXrW8NJcQmTkEf-PE6Q.png" /><figcaption>More Nintendo</figcaption></figure><p>Nintendo can deliver above-average results throughout the field, but the PC delivers the best ratings.</p><h3>It’s your turn now!</h3><p>please head over to <a href="https://github.com/cr00nkz/Video_Games_DataScience">https://github.com/cr00nkz/Video_Games_DataScience</a> and play around with the dataset, the model, the data and everything else. <br>We together explored data, analyzed data and predicted some new and fun games.</p><p>You would like to prove, that PC is not the masterrace? Do it and, please, share the results you have found.</p><p>Thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b1f91400d63" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/is-pc-the-master-race-exploring-ratings-and-sales-of-video-games-6b1f91400d63">Is PC the Master Race? - Exploring ratings and sales of video games</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>