Advertisement

Viser innlegg med etiketten programming. Vis alle innlegg
Viser innlegg med etiketten programming. Vis alle innlegg

tirsdag 14. juni 2016

Moneyball: Sports Analytics in Soccer to Predict Performance and Outcomes


There is no doubt that soccer is the most popular sport in the world, and its popularity is growing in the US. Over 25 million fans watched U.S. Women’s FIFA World Cup 2015, and earned Fox over $40 million in ad revenue. Similarly, the United States’ 2-2 draw with Portugal in the 2014 World Cup was seen by an average of 24.7 million viewers on Univision and ESPN.
What's Sports Analytics?

Sports analytics is the processes that identify and acquire the knowledge and insight about potential players’ performances based on the use of a variety of data sources such as game data and individual player performance data. These advanced and sophisticated type of analytics should be able to extract valuable actionable insights for the coaches and managers to utilize.

Sports analytics can be utilized in various domains including:
Predicting the outcome of a game
Predicting the performances of teams or individual players
Building new strategies for upcoming competitions
Deciding the price of a player if a club was to rent/sell/buy him or her
Connecting players to brands and sponsors

Of course, not all teams use analytical tools. In addition to the costs involved, there’s also the problem of explaining complex analytical methods to coaches in ways they can understand. Thus, soccer analytics is more widespread in big clubs where they have the necessary financial power to utilize these methods.

But that should not necessarily be the case. Since traditional sports analysts do not reveal the logic behind their methods, we’ve decided to give you a flavor of what can be done with soccer data. While this post will not answer all the questions you have about soccer analytics, it can help you understand how to get started.

In this project, we have used a very limited number of player’s attributes (See the section under Player’s Features/Attributes) that are easy and not expensive to gather, to both reverse engineer the most advanced Rating and Performance index (The results are presented in Figures 1-12) and then to propose a more robust and easy model for future player ratings and performance prediction (See the section under Machine-Learning and AI Models). The program runs on Spark and Cloud Environment, and can be used for Terra-Petta scale of data, from multiple years, with thousands of players, with 100s of attributes.
What's Soccer Analytics?

Soccer Analytics is the art of creating insights and actionable decisions using soccer related data. While predictive analytics uses big data to determine the probability or the likelihood of a certain outcome, intelligent descriptive analytics looks at big data and analyzes it using machine learning and artificial intelligence methods to come of with suggestions that will improve the likelihood of a desired outcome.

Some important concepts to know while conducting this analysis are:
Game Modeling: Modeling of the game before, during and after the game using scientific techniques to match or predict a set of outcomes.
Expert Player Rating: Players ratings given by an expert. These ratings take a black-box approach, and they vary according to the prior knowledge of the expert.
Soccer Performance Analytics: Is a tool to help players, coaches and managers to quantitatively assess the players and team performance and help to improve both players and team performance and design a set of wining strategies for upcoming game(s).

Here are some questions to ask when running analysis on soccer players:
How does expert rating differ from ratings generated by data-driven Machine Learning ratings?
What are the most important players’ attributes linked to their performance?
What criteria do experts use when they evaluate Players? Is there a way to reverse engineer their criteria?
Which attributes are important for each specific position?
Can we use ratings and players’ attributes to predict the outcome of a game?
Can we aggregate the players’ rating to come up with a team rating?
Is there a way to correlate the team rating to the outcome of the game?
Do the outcomes of games influence expert ratings more than individual performance indicators do?
Can we predict the outcome of a new game given the past performance of the players?

Using advance analytics and visualization tools such as Machine Learning and network analytics to predict the outcomes of soccer games is becoming more and more popular as these methods continue to move into the mainstream with the help of tools that make it easier to conduct these advanced analytical methods.
Some insights to our approach:

In this project, we used our selected set of clustering and classification techniques and the best model was selected and ranked based on Train-Validation-Test process.
Companies such as OPTA, Prozone, Amisco, and WhoScored are now collecting rich soccer data. These can be utilized to conduct accurate assessments.
For our project, a rich data set containing more than 210 attributes of players including 198 performance statistics were used. To calculate the overall performance and ratings of the players, some or all of the attributes were being used. Some of the very advanced Expert Ratings include: Caapello Index, Castrol Index, and WhoScored.com. These Ratings include each player’s cumulative ratings and game-based ratings.
For classification-regression and clustering, there are many Machine learning models that can be used. For classification-regression model, you can use Machine Learning models (SVMs, logistic regression, linear regression), naive Bayes, Regression by Discretization using J48, Additive Regression with Decision Stump, decision trees, ensembles of trees (Random Forests and Gradient-Boosted Trees), isotonic regression, Multilayer Perceptron, RBF Network. For Clustering, you can use k-means, clustering using affinity propagation, Agglomerative Clustering (Ward, Average, and Complete), Gaussian mixture, power iteration clustering (PIC), latent Dirichlet allocation (LDA). Furthermore, you can use dimensionality reduction such as singular value decomposition (SVD) and principal component analysis (PCA) to reduce the feature space. In our case study, we tested all the models and the best results combined and are presented in Figures 1-12, without elaborating about specific model and how they can be aggregated.
Players' Features/Attributes:

In this project, we have used a subset of the Player’s Features/Attributes from the following list. Keep in mind that your model should be able to select and rank these attributes based on their importance. At this blog, we are not elaborating on what features have been selected by models, as these will depend on the specific approach you choose to take when building your model.
Nationality, Club, League, Age, Height, String Foot, Position (GK, CB, RB, LB, DM, CM, RM, LM, AM, RW, LW, SS, CF)
Attacking Prowess, Ball Control, Dribbling, Low Pass, Lofted Pass, Finishing
Place Kicking, Swerve, Header, Defensive Prowess, Ball Winning, Kicking Power, Speed, Explosive Power, Body Balance, Jump, Stamina, Goalkeeping, Saving, Form, Injury, Resistance, Weak Foot Use, Weak Foot Accuracy, Trickster, Mazing Run, Speeding Bullet,, Incisive Run, Long Ball Expert, Early Cross, Long Ranger
Scissors Feint, Flip Flap, Marseille Turn, Sombrero, Cut Behind & Turn, Scotch Move, Long Range Drive, Knuckle Shot, Acrobatic Finishing, First-time Shot, One-touch Pass, Weighted Pass, Pinpoint Crossing, Outside Curler, Low Punt Trajectory, Long Throw, GK Long Throw, Man Marking, Track Back, Captancy, Super-sub, Fighting Spirit

While, we do not have intention to disclose the final optimized features selected by our optimized model and strategy, we used the following ML-AL based aggregator operator model (Figure 13 shows the Structure of our Committee Machine).
Figures:

Finally, here's a list of the plots and figures created as a result of this analysis:



Figure 1. Clustering (similarities of players’ clusters) and prediction of the rating (plot: prediction vs. actual) for the Forward Players. Train, test and Validation. The similarities of the individual players are shown by the lines on clustering plots.



Figure 2. Clustering (similarities of players’ clusters) and prediction of the rating (plot: prediction vs. actual) for the Goalkeepers. Train, test and Validation. The similarities of the individual players are shown by the lines on clustering plots.



Figure 3. Clustering (similarities of players’ clusters) and prediction of the rating (plot: prediction vs. actual) for the Defensive Players. Train, test and Validation. The similarities of the individual players are shown by the lines on clustering plots.



Figure 4. Clustering (similarities of players’ clusters) and prediction of the rating (plot: prediction vs. actual) for the MidField Players. Train, test and Validation. The similarities of the individual players are shown by the lines on clustering plots.



Figure 5. Clustering (similarities of players’ clusters) using advanced Visual-Analytics-Clustering for Forward Players. The similarities of the individual players are shown by the lines and their strength with the width of lines on clustering plot.



Figure 6. Clustering (similarities of players’ clusters) using advanced Visual-Analytics-Clustering for Forward Players. Similar clusters are closer to each other.



Figure 7. Typical performance of our Regression model’s Prediction for the rating of the Forward players (Prediction Vs. Actual). Train data for Forward Players.



Figure 8. Typical performance of our Regression model’s Prediction for the rating of the Forward players (Prediction Vs. Actual). Validation data for Forward Players.



Figure 9. Typical performance of our Regression model’s Prediction for the rating of the Forward players (Prediction Vs. Actual). Test data for Forward Players.



Figure 10. Typical performance of our Regression model’s Prediction for the rating of the players (Prediction Vs. Actual). Test data for Forward-MidField-Defensive Players.



Figure 11. Typical performance of our Regression model’s Prediction for the rating of the players (Prediction Vs. Actual). Validation data for Forward-MidField-Defensive Players.




Figure 12. Typical performance of our Regression model’s Prediction for the rating of the players (Prediction Vs. Actual). Test data for Forward-MidField-Defensive Players.



Figure 13. Committee Machine, and Intelligent Multi-Level-Aggregator Tree (MAT) platform.

mandag 13. juni 2016

HOW THE MODEL WORKS

At a high level, our approach is as follows. First, we estimate a regression model to predict the number of goals scored by a particular team (“team i”) against a particular opponent (“team j”) using the entire history of mandatory international matches since 1958, when the first European championship was played (a total of 4,719 matches).[1] Following the literature on predicting football matches, we assume that the number of goals scored by team i is described by a so-called Poisson distribution and explained by the following statistical factors:[2] 1. The difference in team performance as reflected in Elo ratings prior to the match. The Elo system was originally devised to rank chess players. It is a composite measure of national football team success that evolves depending on a team's results and the strength of its opponents. 2. The number of goals scored by team i in the last 10 competitive matches. 3. The number of goals conceded by team j in the last 2 competitive matches. 4. A home dummy. 5. A European Championship dummy to capture whether a team does systematically better at European Championships than in other competitive matches Second, we use these regression estimates and our assumed Poisson distribution in a Monte Carlo simulation with 100,000 draws to generate a distribution of outcomes for each of the 52 matches, from the opener between France and Romania on June 10 to the final on July 10. We use the rounded prediction of the goals scored to determine the outcome of each match during the group stage and the unrounded prediction to pick the winner in the knockout stage. Third, we use the estimation results to generate both a set of probabilities that a particular team reaches a particular stage of the tournament, up to and including the championship, and a modal—that is, single most likely—forecast for the outcome of each match, which we then run forward through the tournament until the final.


A SUMMARY OF PREDICTIONS
Our probabilities are shown in Exhibit 1. The model says that France has a 23% probability of winning the trophy, followed by Germany at 20%, Spain at 14%, and England at 11%. Although Germany has the highest Elo rating, France is favored because of its home advantage.




Exhibits 2 and 3 provide a different perspective by showing the modal prediction for the entire tournament. There are some interesting contrasts with the probabilities in Exhibit 1. For example, Exhibit 1 says that Germany is more likely than Spain to win the tournament because it is more likely to succeed across the entire range of possible tournament configurations. But Exhibit 3 says that in the single most likely case, Spain beats England in Semifinal 1, France beats Germany in Semifinal 2, and France then wins the final—i.e., Germany finishes behind Spain. Which approach is better, the probabilistic one in Exhibit 1 or the modal one in Exhibits 2 and 3? A modal forecast does have the advantage of being more “crisp.” The sentence “Goldman Sachs says France will win” has a better ring to it than “Goldman Sachs says France has a 23% probability of winning, with Germany close behind.” Nevertheless, we think that a probabilistic approach is more useful—for predicting the outcome of football tournaments and, increasingly, for our day-to-day work on economic forecasting.



Exhibit 4 provides more insight into the results by breaking down the probabilities of winning for the top four teams in a “waterfall chart” format. It shows that the most important factor is the Elo score, followed by home advantage and the European Championship dummy. The chart illustrates that the front-runner position for France derives largely from its home advantage, as its Elo rating is well below Germany’s and also a bit below Spain’s. Meanwhile, Germany benefits from the European Championship dummy, which picks up its historically strong tournament performance. 





HOW CONFIDENT CAN WE BE?

It is difficult to assess how much faith one should have in these predictions. On the plus side, our approach carefully considers the stochastic nature of the tournament using statistical methods, and we do think that the Elo rating—the most important input into our analysis—is a compelling summary of a team’s track record. On the minus side, we ignore a number of potentially important factors that are difficult to summarize statistically, including the quality of the individual players unless they are reflected in the team’s recent track record.[4] And there is no room for human judgment (which may not be such a bad thing given that none of us are really football experts but some are enthusiastic Germany supporters).[5]



One useful cross-check is to compare our results with bookmakers’ odds. Exhibit 5 plots our estimated championship probability against the average probability implied by the odds offered by five different bookmakers. The basic result is clear. Even though our model does not include bookmakers’ odds in any way, the probabilities are quite similar. A possible reason is that professional betting firms use many of the same inputs—such as Elo ratings—in their analysis and that they process the information in ways that are ultimately similar to ours. Another useful check is to evaluate the performance of our model for the 2014 World Cup, which followed an essentially identical approach to the one presented here.[6] It is safe to say that we had our hits and misses. First, performance in the group stage was not great. The model only identified 9 of the 16 advancing teams and failed to predict the elimination of heavyweights Spain and Italy, although it correctly anticipated that England would fly home early. Second, the model gave Brazil a 48% probability of winning the trophy, by far the highest of all the contestants. That failure illustrates a certain lack of imagination that is inherent in our approach. If the greatest football nation on earth—in terms of both past victories and its 2014 Elo rating—plays a World Cup at home, we are bound to project success. At least the probability was below 50%! Third, the model did correctly identify three of the four semifinalists before the start of the tournament, namely Argentina, Brazil, and Germany, although it incorrectly picked Spain over the Netherlands. Fourth, the fully updated version of the model—that is, the projection we sent out before each day of play on the basis of updated Elo ratings and other performance measures—was remarkably accurate during the knockout stage. It correctly predicted the winner of every match except the 7-1 semifinal between Germany and Brazil. But that was, by one estimate, the single most surprising result in World Cup history.[7] Ultimately, this last predictive failure might best capture the spirit of the exercise. As we said in our comment at the time: “Speaking as forecasters, we regret the miss. But, speaking as Germans, we would note that there are more important things than being right.” May the best team win and let’s hope that watching Euro 2016 is as much fun as it was to write this article!

søndag 5. juni 2016

10 Minutes to Data Science



I just followed John Hopkin's Executive Data Science team. In the first chapter of the course they talk,

*In Data Science, the importance is science and not data. Data Science is only useful when we use data to answer the question.*
It actually true in some point. I've actually seen too many companies that brag how big they data are but they don't actually know how to pose a question. If the data can't be used to answer the question that makes the company growth, it's not a good idea. They press even more to the point of data, data, data but really is in the end, machine learning will just feed into it, to make a better prediction to answer the question. It's critical to pose a question first, then try to get/build data to answer the question. And more importantly, don't be afraid to get other data from sources outside your company.
When investigating a problem and communicating to the broader audience, it's important to find the right question to answer, and then find the data related to answering the questions. This how all data science work will look like. Even in A/B testing when we measure the confidence interval between control and experiment group, the real question is still about how we can use data to answer our question.
In that course, Jeff Leek continues in term of Money Ball. We can find some evaluation metrics to measure player's skills, but the key important to answer questions is, "Can we be a winning team with a small budget?" Creating the best predictive model is not the most important, in the case of Netflix prize, one-million-dollar algorithm can't be implemented because it's impossible to scale with all of the customer combined.


Statistics and Machine Learning

Statistics mainly divided into two parts, Descriptive Statistics and Inferential Statistics. Descriptive Statistics, as the name implied, is using statistics to better understand the data. This includes using summary statistics and visualization to explore the data. Jake Vanderplas, the author of Python Data Science Handbook, showed how to use this method to understand the pattern of Seattle's Bicycle Habits in his blog.
While Inferential Statistics let you use Hypothesis testing and Confidence Interval to make an inference about your assumption. Suppose you have two group with numerical variable (female age vs male age), and you want to found whether these groups is significantly different with each other. Statistical Inference need you to follow experiment design, so that your inference can generalize well to your population of interest, and also found correlation that suggest causation. This method is useful to get insight, whether the relationship of two variable is correlate with each other.
Machine Learning is one of the fields in artificial intelligence that give a machine a capability to learn about your data. Thanks to the modern era, where computers have grown computation power and hype of data science , machine learning has grown into broad area. Two of the interesting topic is Supervised Learning and Unsupervised Learning. Supervised Learning is where given a set of input and output, machine learning tried to predict future output given future input. Think of it as a student that given a bunch of papers of quiz where it has a wrong and right answer, he learns and will able to answer the quiz. While the example of Unsupervised Learning is clustering algorithm like we discussed earlier.
Machine Learning is a different use case when compared to Statistical Inference. Have you seen Kaggle competitions? take a look around at their leaderboard, and all that score is extremely close. Often top 100 hundred is already a winner. They're willing to go into 2-3 times more complexity to get 1% increase. This is not practically possible, and we saw from Netflix prize, they give up on the one million dollar code because it's computation is expensive. So if you in for the accuracy games, go ahead! Otherwise, a simpler model is better.
So what do you use when you want to make a prediction? use Statistical modeling to understand what your prediction is. Use machine learning to make your prediction better. Statistical modeling concerns about the complexity model because we have to understand it, but machine learning scale as complexity increase. Moreover, Machine Learning concern about parameter tuning to performance, statistics concern about parsimonious model (get understanding bett


Software Engineering

So why is software engineering is important in data science? Because often you will have to get data using programming language. Sure there is some reporting that you can be download from Google Analytics or any dashboard in your company, but it's only summary and aggregation metrics. Things will get harder if you need advanced or specialized metrics that would need you to create aggregation yourself. Log data will always have some messy data. And if you have human-input data, there's going to be a human error. In order to do that, you need engineering skills. Pulling data from database alone need some programming or SQL skills. In case you need additional data from open data in the web, you also need programming to get data through API.
So engineering skill is a critical part of data science. In fact, it's so critical that you won't get the fun part, analyzing and making inference/prediction if you don't have engineering skills. You don't even know how to get data and clean it. At least software engineer alone can still do something. They can get some data and validate through analyzing inconsistency, and make some descriptive statistics to analyze the data.


Toolbox

One of data science toolbox is often a debate between choosing R or Python. But they are two different things. Python comes from software engineer background. Since Python famous first at web development, gathering and manipulating data has becomes very important. On the other hand, R has statistician background. There is widely variant of statistical packages available. And as statistician also use visualization to get insight about data, it also rich with visualization packages. So when processing the data use Python, and doing R when you want to analyze. Of course, sometimes these two overlaps, and you can choose to stick to one language. You can manipulate string in R, or do statistical analysis in Python. You have few choices when you want to present your result of analysis. If narrative, you can use Jupyter or Rmarkdown to storytelling your analysis in a narrative way. Sometimes you end-up want to engage your audience based on your findings. In this case, you want to create interactive visualization. D3.js is great in this area.
So when you talk about data science, think more about the question that you want to answer. Can you get some information if you have to answer the question? Do you have useful data to answer your question? If you could even answer it, is the answer practically possible? By doing this series of questions, it will avoid your missteps in the long run.

onsdag 1. juni 2016

10 Programming Languages You Should Learn in 2016

The tech sector is booming. If you've used a smartphone or logged on to a computer at least once in the last few years, you've probably noticed this.

As a result, coding skills are in high demand, with programming jobs paying significantly more than the average position. Even beyond the tech world, an understanding of at least one programming language makes an impressive addition to any resumé.
The in-vogue languages vary by employment sector. Financial and enterprise systems need to perform complicated functions and remain highly organized, requiring languages like Java and C#. Media- and design-related webpages and software will require dynamic, versatile and functional languages with minimal code, such as Ruby, PHP, JavaScript and Objective-C.
With some help from Lynda.com, we've compiled a list of 10 of the most sought-after programming languages to get you up to speed.

1. Java




Java

IMAGE: MASHABLE COMPOSITE. IMAGE: WIKIMEDIA COMMONS

What it is: Java is a class-based, object-oriented programming language developed by Sun Microsystems in the 1990s. It's one of the most in-demand programming languages, a standard for enterprise software, web-based content, games and mobile apps, as well as the Androidoperating system. Java is designed to work across multiple software platforms, meaning a program written on Mac OS X, for example, could also run on Windows.
Beginners are advised to learn C/C++ first, as Java is not the most user-friendly of languages.
Where to learn it: UdemyLynda.comOracle.comLearnJavaOnline.org.

2. C Language




C Language

IMAGE: MASHABLE COMPOSITE. IMAGE: WIKIMEDIA COMMONS

What it is: A general-purpose, imperative programming language developed in the early '70s, C is the oldest and most widely used language, providing the building blocks for other popular languages, such as C#, Java, JavaScript and Python. C is mostly used for implementing operating systems and embedded applications.
Because it provides the foundation for many other languages, it is advisable to learn C (and C++) before moving on to others.

3. C++




C Plus Plus

IMAGE: MASHABLE COMPOSITE. IMAGE: WIKIMEDIA COMMONS

What it is: C++ is an intermediate-level language with object-oriented programming features, originally designed to enhance the C language. C++ powers major software like FirefoxWinampand Adobe programs. It's used to develop systems software, application software, high-performance server and client applications and video games.

4. C#




C Sharp

IMAGE: MASHABLE COMPOSITE. IMAGE: WIKIMEDIA COMMONS

What it is: Pronounced "C-sharp," C# is a multi-paradigm language developed by Microsoft as part of its .NET initiative. Combining principles from C and C++, C# is a general-purpose language used to develop software for Microsoft and Windows platforms.

5. Objective-C




Objective-C

IMAGE: MASHABLE COMPOSITE. IMAGE: WIKIMEDIA COMMONS

What it is: Objective-C is a general-purpose, object-oriented programming language used by theApple operating system. It powers Apple's OS X and iOS, as well as its APIs, and can be used to create iPhone apps, which has generated a huge demand for this once-outmoded programming language.

6. PHP




PHP

IMAGE: MASHABLE COMPOSITE. IMAGE: WIKIMEDIA COMMONS

What it is: PHP (Hypertext Processor) is a free, server-side scripting language designed for dynamic websites and app development. It can be directly embedded into an HTML source document rather than an external file, which has made it a popular programming language for web developers. PHP powers more than 200 million websites, including WordpressDigg andFacebook.

7. Python




Python

IMAGE: MASHABLE COMPOSITE. IMAGE: WIKIMEDIA COMMONS

What it is: Python is a high-level, server-side scripting language for websites and mobile apps. It's considered a fairly easy language for beginners due to its readability and compact syntax, meaning developers can use fewer lines of code to express a concept than they would in other languages. It powers the web apps for InstagramPinterest and Rdio through its associated web framework, Django, and is used by GoogleYahoo! and NASA.
Where to learn it: UdemyCodecademyLynda.comLearnPython.orgPython.org.

8. Ruby




Ruby

IMAGE: MASHABLE COMPOSITE. IMAGE: WIKIMEDIA COMMONS

What it is: A dynamic, object-oriented scripting language for developing websites and mobile apps, Ruby was designed to be simple and easy to write. It powers the Ruby on Rails (or Rails) framework, which is used on ScribdGitHubGroupon and Shopify. Like Python, Ruby is considered a fairly user-friendly language for beginners.
Where to learn it: CodecademyCode SchoolTryRuby.orgRubyMonk.

9. JavaScript




JavaScript

IMAGE: MASHABLE COMPOSITE. IMAGE: WIKIMEDIA COMMONS

What it is: JavaScript is a client and server-side scripting language developed by Netscape that derives much of its syntax from C. It can be used across multiple web browsers and is considered essential for developing interactive or animated web functions. It is also used in game development and writing desktop applications. JavaScript interpreters are embedded in Google's Chrome extensions, Apple's Safari extensions, Adobe Acrobat and Reader, and Adobe's Creative Suite.
Where to learn it: CodecademyLynda.comCode SchoolTreehouseLearn-JS.org.

10. SQL




SQL


What it is: Structured Query Language (SQL) is a special-purpose language for managing data in relational database management systems. It is most commonly used for its "Query" function, which searches informational databases. SQL was standardized by the American National Standards Institute (ANSI) and the International Organization for Standardization (ISO) in the 1980s.