Predicting Football Match Results Using Machine Learning [Just tried]

match result using machine learning

Read Time21 Minute, 12 Second

Note: This is the first try of solving this kind of problem and needs improvement as the accuracy is very low. If you know these techniques, I would appreciate the help. Now let’s just see how I tried predicting a football match result using machine learning.

I tried multiple algorithms, and the SVM using Radial Basis Function  kernel was the best for accuracy. [Which still sucks though.]

Now, let’s just see what I tried to do. You can find the code with and without BoW on GitHub.

Predicting Football Match Results Using Machine Learning

  1. Downloaded the dataset from kaggle. The dataset is only about Liverpool FC matches from 1993 to 2018. [dataset by Rogelio Camargo)
  2. Then opened the ‘csv’ file using pandas.
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

dataset=pd.read_csv('C:\\Users\\shubh\\Downloads\\liverpoolfcstats.csv')

3. The file will look like this.

  Unnamed: 0      Date   HomeTeam        AwayTeam  FTHG  FTAG FTR  HTHG  \
0           4  14/08/93  Liverpool  Sheffield Weds     2     0   H   NaN   
1          20  18/08/93        QPR       Liverpool     1     3   A   NaN   
2          33  22/08/93    Swindon       Liverpool     0     5   A   NaN   
3          40  25/08/93  Liverpool       Tottenham     1     2   A   NaN   
4          49  28/08/93  Liverpool           Leeds     2     0   H   NaN   

   HTAG  HTR   Season  
0   NaN  NaN  1993-94  
1   NaN  NaN  1993-94  
2   NaN  NaN  1993-94  
3   NaN  NaN  1993-94  
4   NaN  NaN  1993-94  


4. Took only Home Team and Away team columns and combined them for making a vector for each row.

X=dataset.iloc[:,2:4]
for a in X:
    a.replace(" ","")

X['Match']=X['HomeTeam']+X['AwayTeam']
X2=X.iloc[:,2]
print(X2)

5. X2 will look like this.

0      LiverpoolSheffield Weds
1                 QPRLiverpool
2             SwindonLiverpool
3           LiverpoolTottenham
4               LiverpoolLeeds
                ...           
953       LiverpoolBournemouth
954         West BromLiverpool
955             LiverpoolStoke
956           ChelseaLiverpool
957          LiverpoolBrighton
Name: Match, Length: 958, dtype: object

6. Tried to one hot encode X2, but later did label encoding

from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
X2 = le.fit_transform(X2)
print(X2)
X2 = X2.reshape(len(X2),1)

The X2 will look like this.

[60 82 90 66 46 14 28 17 13 24 55 73 61 69 77 25 85 57 65 91 84 71 21 49
 80 48 78 86 22 38  4 41 37  0 74 59 96 45 52 94 53  1 15 24 86 69 74 77
 60 25  4 71 21 82 54 37 17 66 14 39 13 23 48 22 53 45 41 79 57 85 52 38
 49 91 61 46  0 73 47 78 96  1 94 28 60 22 91 57 96 28 30 74 38 86 48 77
 41 94 76 61  6 49 24 13 54 85 46  1 66 82  4 25 71 37 79 52 14 69 17 51
  0 73 76 24 63 14 61 23 37 94 74 40  4 22 41 71 91 60 51 54 77 47 86 13
 69 25 16 46 28  1 52 79  0 38 88 17 49 66 96 85 96 47  4 22 60 86 25 94
 37 17 40  6 66 26  0 49 15 38 46 77 71 23 52 28 61 85 41  1 30 91  2 74
 39 14 13 69 24 16 86 24 77 38 94 36 74 37 17 54 23 40 46  1 28 91 96 60
 76 52  0 61 14 51 12 69 13 16 41 79 22 25 47  4 66 49 85 71 85 67 76 22
 24 49 23 41  1 37 86 69 32 40 88 94 60 38 77 71 91 92 51 46  0 74 63 25
 16 52 14 66 96 17 13 47 61  8 32  0 86 25 48 94 63 13 16 47 41 22 38 91
 77 36 45 74 24 76 61  1 51 73 69 88 23 40 49 21 46 17 66 14  8 52 37 12
 69  6 25 17 66 77 46 23 12 49  4 63 16 51 42 13 24  1 94 30 86  0 61 74
 47 22 21 41 18 52 76 37 36 88 40 91 28 45  1 61  4 52 27  6 68 73 37 22
 66 69 75 63 18 49 12 88 41 28  0 77 25 86 24 94 50  3 30 91 46 74 42 17
 36 93 48 13 37  1 66 17  4 47 12 24 81 46 18 49 76 27 77 61 30 73 13 25
 91 97 41  6 48 22 86 56 72 23 28  0 36 42 74 51  3 52 91 48  6 68 74 53
 13 18 36  4 27 39 76 24  1 17 56 52 93 61 37 78 49 86 12 42  3 77 28 41
 30 73 66 81 15 51  0 25 76 63 91 49  3 37 28 18 69  1 56 73 88 70 51 52
 17 68  6 66 74 27 13 12 95 24 48 36  0 42 77 41 93 30  4 94 25 81 84 69
 17 13 52 66  6 28 74 25 58  0 76 48 56 95 42 12 67  4 91 30 92 37 94 41
 77 59 49  1 24 83 73 51 70 81 18 36  1 37 88 40 81 27 95 66 17 24  4 42
 77 30 83 49 56 16 73 70 76 25 94 63 13 51  6 69 52 58 74 41  0 28 18  3
 48 91 88 51  1 49 62 17 73 70 13 56 91 68  6 42 69  4 44  0 30 77 87 41
 95 37 81 48 76 63 74 25 18 28 24 20 52 94 93 66 91 62 25  6 34 94 44 13
 88 49 18 27 48 17  4 24 70 81 72  1 87 66 97 30 41  0 73 28 95 56 74 63
  3 42 69 10 37 20 24 73 68  3 74 63 29 17 28  6 37 95 87 69 91 25 77 72
 30  4  5 41 97 42 62 13 70 94 49 88 93 48  0 27 52 18 66  1 63  0 30 87
 91 72 17 49 53 93 64 13 48 18 57  1 95 28 52 73 62  6 97 66 74 24 88 41
 82 70 77 25  4 68 78 42 37 89 93 48 24 88 49 78 62 58 17 52 13 70 89 91
 61 94 25 42 87 82 63 74 53  0 73 68 64 95 66 86  1 69 83 37 77 41 18 57
 62  1 49 89 61 88 39 77 68  0 42 17 20 53 69 91 35 73 13 44 87 25 41 93
 24 18 64 86 74 11 63 66 94 48 78 37 15 52 61 73 91 25 94 41 68 82 44 77
 37 15 62 23 63 74 24 10 64 47 88  1 69 17 66 86 48 34 89 49  0 52 93 20
 57 13 39 87 87 31  0 69 74 53 25 17 91 61 13 39 73 64 77 68 92 47 88 94
 24 49 78 23 63  1 48 15 86 66 62  7 41 52 89 67 37 93  0 10 91 47 13 44
 89 49 68 15 67 86 63  7 69 76 17 62 48 88 74 64 37 20 66 23 24 34 73 41
 31 87 93 39 92 61 94 51 92 39 24 73 34 23 77 49 91 43 94 61 37 87  9 41
 68  7  0 64 47 10 48 89 19 66 86 69 52 74 67 15 17 31 93 62 13 33]

7. Took 5th column from the dataset as dependent as we have to predict the result.

y=dataset.iloc[:,6].values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D' 'A'
 'H' 'A' 'H' 'H' 'A' 'D' 'D' 'D' 'A' 'D' 'A' 'H' 'H' 'A' 'H' 'D' 'A' 'A'
 'H' 'D' 'H' 'H' 'H' 'D' 'H' 'H' 'H' 'A' 'H' 'H' 'H' 'H' 'A' 'D' 'H' 'D'
 'H' 'A' 'H' 'A' 'A' 'A' 'H' 'H' 'A' 'H' 'A' 'A' 'D' 'H' 'H' 'H' 'A' 'A'
 'H' 'D' 'H' 'A' 'D' 'H' 'A' 'H' 'H' 'A' 'D' 'H' 'D' 'A' 'H' 'D' 'A' 'A'
 'H' 'D' 'H' 'A' 'H' 'H' 'A' 'A' 'H' 'H' 'D' 'H' 'H' 'D' 'A' 'H' 'A' 'H'
 'D' 'A' 'H' 'D' 'H' 'D' 'D' 'D' 'A' 'A' 'A' 'H' 'H' 'D' 'H' 'H' 'A' 'H'
 'D' 'A' 'A' 'H' 'D' 'A' 'H' 'A' 'H' 'D' 'H' 'A' 'H' 'D' 'H' 'H' 'D' 'D'
 'A' 'H' 'D' 'H' 'A' 'H' 'A' 'D' 'H' 'A' 'H' 'D' 'H' 'H' 'D' 'A' 'A' 'H'
 'H' 'D' 'D' 'A' 'D' 'H' 'H' 'H' 'H' 'H' 'D' 'H' 'D' 'A' 'A' 'A' 'A' 'D'
 'A' 'H' 'D' 'H' 'H' 'H' 'D' 'A' 'D' 'D' 'H' 'H' 'A' 'H' 'D' 'A' 'A' 'D'
 'D' 'A' 'D' 'H' 'H' 'A' 'H' 'H' 'A' 'D' 'A' 'H' 'H' 'H' 'H' 'A' 'D' 'H'
 'D' 'D' 'H' 'H']

9. After label encoding X2, did the same for y.

from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
y = le.fit_transform(y)
print(y)
y = y.reshape(len(y),1)

Now y will look like this

[2 0 0 0 2 2 0 2 2 1 2 1 2 2 2 2 2 2 1 1 1 1 0 1 0 2 1 2 2 2 2 2 2 2 2 0 1
 2 0 0 0 2 0 2 0 1 2 1 2 2 2 2 0 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1 1 1 1 2 2 1 2 0 2 2 2 2 2 1 2 0 1 2 0 0 2 1 2 1 0 0 2 0 2 2 2 0 1
 1 0 1 1 2 0 1 1 1 2 0 1 2 2 0 2 0 2 1 0 2 0 0 2 2 2 0 0 2 0 2 2 2 2 2 1 1
 0 1 0 2 2 2 0 1 2 1 2 2 2 1 2 2 2 2 2 1 1 2 0 0 1 1 2 2 1 2 1 0 2 2 0 2 1
 2 2 2 2 2 0 2 2 2 1 0 2 2 0 1 2 2 0 2 2 1 2 2 0 0 2 1 0 2 2 2 2 0 1 1 0 1
 0 1 2 2 0 1 1 2 2 1 2 0 1 2 0 2 2 2 0 2 1 0 0 0 0 2 2 2 1 0 1 0 0 1 2 1 1
 1 2 1 2 2 0 0 2 2 0 2 2 2 1 1 0 2 0 2 2 0 1 1 1 0 1 0 2 2 0 2 1 0 0 2 1 2
 2 2 1 2 2 2 0 2 2 2 2 0 1 2 1 2 0 2 0 0 0 2 2 0 2 0 0 1 2 2 2 0 0 2 1 2 0
 1 2 0 2 2 0 1 2 1 0 2 1 0 0 2 1 2 0 2 2 0 0 2 2 1 2 2 1 0 2 0 2 1 0 2 1 2
 1 1 1 0 0 0 2 2 1 2 2 0 2 1 0 0 2 1 0 2 0 2 1 2 0 2 1 2 2 1 1 0 2 1 2 0 2
 0 1 2 0 2 1 2 2 1 0 0 2 2 1 1 0 1 2 2 2 2 2 1 2 1 0 0 0 0 1 0 2 1 2 2 2 1
 0 1 1 2 2 0 2 1 0 0 1 1 0 1 2 2 0 2 2 0 1 0 2 2 2 2 0 1 2 1 1 2 2]

10. Splitting the data into training and test sets.

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X2, y, test_size = 1/3, random_state = 0)

11. Did standard scaling.

from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
print(X_train)
print(X_test)

12. Training SVM

from sklearn.svm import SVC
classifier = SVC(kernel = 'rbf', random_state = 0)
classifier.fit(X_train, y_train)

13. Predicting on New Data

I=input('Enter match as LiverpoolLeeds')
from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
I = le.fit_transform([I])
I = I.reshape(len(I),1)
print(sc.transform(I))
print(classifier.predict(sc.transform(I)))

Output will look like this

Enter match as LiverpoolLeedsLiverpoolLeeds
[[-1.70802806]]
[0]

14. Printing out predicted values and actual test values.

print(np.concatenate((y_pred.reshape(len(y_pred),1), y_test.reshape(len(y_test),1)),1))

The output will be:

[[2 2]
 [0 0]
 [2 2]
 [0 0]
 [2 2]
 [2 2]
 [0 2]
 [0 0]
 [2 2]
 [0 1]
 [2 2]
 [2 2]
 [2 0]
 [0 2]
 [2 0]
 [2 2]
 [0 2]
 [2 2]
 [2 1]
 [0 1]
 [2 0]
 [2 2]
 [2 2]
 [2 0]
 [0 1]
 [2 0]
 [0 0]
 [2 1]
 [2 2]
 [2 2]
 [2 2]
 [2 0]
 [2 2]
 [2 2]
 [2 0]
 [2 1]
 [2 2]
 [0 1]
 [0 0]
 [2 2]
 [2 0]
 [2 1]
 [2 2]
 [2 0]
 [0 0]
 [2 2]
 [2 2]
 [2 2]
 [2 2]
 [2 2]
 [0 0]
 [2 0]
 [2 0]
 [0 2]
 [2 2]
 [0 0]
 [0 2]
 [2 2]
 [0 2]
 [2 2]
 [2 2]
 [0 0]
 [2 2]
 [0 0]
 [2 2]
 [2 0]
 [0 1]
 [2 2]
 [2 2]
 [2 2]
 [0 0]
 [2 0]
 [2 0]
 [2 1]
 [2 0]
 [2 0]
 [0 0]
 [0 1]
 [0 1]
 [2 1]
 [2 2]
 [0 0]
 [0 2]
 [2 1]
 [2 2]
 [2 1]
 [2 2]
 [0 0]
 [0 2]
 [2 0]
 [2 2]
 [0 1]
 [2 1]
 [2 1]
 [2 2]
 [2 1]
 [2 2]
 [2 1]
 [0 0]
 [2 2]
 [2 2]
 [2 2]
 [2 1]
 [2 2]
 [2 1]
 [2 0]
 [2 1]
 [2 2]
 [0 2]
 [2 2]
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2 2]
 [2 2]
 [0 0]
 [0 0]
 [2 0]
 [2 0]
 [0 2]
 [2 0]
 [2 1]
 [0 0]
 [0 2]
 [2 0]
 [2 2]
 [0 0]
 [2 2]
 [0 1]
 [2 1]
 [0 1]
 [2 2]
 [2 2]
 [2 1]
 [0 2]
 [0 2]
 [2 1]
 [2 1]
 [0 1]
 [2 2]
 [0 1]
 [2 2]
 [0 0]
 [2 2]
 [2 2]
 [2 0]
 [2 2]
 [0 2]
 [2 2]
 [2 2]
 [2 2]
 [2 2]
 [0 0]
 [2 2]
 [2 2]
 [2 1]
 [2 1]
 [0 2]
 [2 2]
 [2 2]
 [2 1]
 [2 0]
 [2 2]
 [2 1]
 [2 1]
 [2 2]
 [2 2]
 [2 1]
 [2 0]
 [2 1]
 [2 2]
 [2 2]
 [2 0]
 [0 1]
 [2 2]
 [2 2]
 [2 0]]

15. Now, to find the accuracy.

y_pred = classifier.predict(X_test)
from sklearn.metrics import confusion_matrix, accuracy_score
cm = confusion_matrix(y_test, y_pred)
print(cm)
accuracy_score(y_test, y_pred)

15. Accuracy did suck, to be honest at only 51.25% and one of the reasons might be the encoding technique. Still, compared with other algorithms, this was better with the Radial Basis Function kernel. Even using the other kernels gave less accuracy.

If you have read this article, ‘predicting a football match result using machine learning’, comment on what we must do to improve accuracy, and how.

You might also like: How Machine Learning (ML) is Used in Cyber Security

Follow us: TwitterInstagram to stay updated every minute.

Image: Pexels