In [1]:
#Dibuat Oleh Muhammad Ullil Fahri
# https://ullilfahri.skb.ovh/
In [2]:
#Import Libaray

import pandas as pd       
import matplotlib.pyplot as plt
import  seaborn as sns    
In [3]:
#Set Searbon
sns.set(style="white",color_codes=True)  
In [4]:
#data                                                  
bola = pd.read_csv("../data/databola.csv")             
print(bola.head())                                     
   HOME  DRAW  AWAY HASIL
0  1.36  4.75  8.50     H
1  3.75  3.75  1.85     A
2  1.90  3.75  3.75     A
3  2.15  3.60  3.10     A
4  6.50  4.00  1.50     A
In [5]:
#Cek Apakah Ada Missing value
missing = pd.DataFrame(bola)   
print("===================")   
print(missing.isnull)          
print("------------------")    
                               
===================
<bound method DataFrame.isnull of       HOME  DRAW  AWAY HASIL
0     1.36  4.75  8.50     H
1     3.75  3.75  1.85     A
2     1.90  3.75  3.75     A
3     2.15  3.60  3.10     A
4     6.50  4.00  1.50     A
...    ...   ...   ...   ...
7274  1.57  4.00  5.25     H
7275  2.75  3.30  2.50     D
7276  1.72  3.80  4.50     H
7277  1.57  3.80  5.75     A
7278  3.80  3.60  1.95     H

[7279 rows x 4 columns]>
------------------
In [6]:
#hting banyak label                                            
label = bola["HASIL"].value_counts()                           
print(label)                                                   
                                                               
H    3274
A    2213
D    1792
Name: HASIL, dtype: int64
In [7]:
#visualisasi plot Perbandingan Home Dan Draw          
sns.jointplot(x="HOME",y="DRAW",data=bola,size=5)    
/home/mfahri/conda/lib/python3.8/site-packages/seaborn/axisgrid.py:2264: UserWarning: The `size` parameter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
Out[7]:
<seaborn.axisgrid.JointGrid at 0x7f4e602cd550>
In [8]:
#visualisasi plot Perbandingan Home Dan AWAY         
sns.jointplot(x="HOME",y="AWAY",data=bola,size=5)   
Out[8]:
<seaborn.axisgrid.JointGrid at 0x7f4e331b8550>
In [9]:
#visualisasi plot Perbandingan DRAW DAN AWAY                
sns.jointplot(x="DRAW",y="AWAY",data=bola,size=5)          
Out[9]:
<seaborn.axisgrid.JointGrid at 0x7f4e602cd250>
In [10]:
sns.boxplot(x="HASIL",y="HOME",data=bola)    
Out[10]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f4e32dedc10>
In [11]:
#normalisasi data                                    
from sklearn import preprocessing                    
X = bola[["HOME","AWAY","DRAW"]]                     
print(X)                                             
                                                     
X_transform = preprocessing.scale(X)                 
print(X_transform)                                   
      HOME  AWAY  DRAW
0     1.36  8.50  4.75
1     3.75  1.85  3.75
2     1.90  3.75  3.75
3     2.15  3.10  3.60
4     6.50  1.50  4.00
...    ...   ...   ...
7274  1.57  5.25  4.00
7275  2.75  2.50  3.30
7276  1.72  4.50  3.80
7277  1.57  5.75  3.80
7278  3.80  1.95  3.60

[7279 rows x 3 columns]
[[-0.67518625  0.94794976  0.46986415]
 [ 0.42656992 -0.69768312 -0.25146548]
 [-0.42625389 -0.2275023  -0.25146548]
 ...
 [-0.50923135 -0.04190461 -0.215399  ]
 [-0.57837922  0.26742488 -0.215399  ]
 [ 0.44961921 -0.67293676 -0.35966492]]
In [12]:
#mULAI pREDIKSI dENGA
                     
Y = bola["HASIL"]    
In [13]:
#naive bayes                                                        
                                                                    
from sklearn.naive_bayes import GaussianNB                          
                                                                    
gnb = GaussianNB()                                                  
                                                                    
training = gnb.fit(X_transform,Y)                                   
prediksi = gnb.predict(X_transform)                                 
In [14]:
#neurel network                                                        
from  sklearn.neural_network import MLPClassifier                      
nn = MLPClassifier(hidden_layer_sizes=(10))                            
                                                                       
trainingnn = nn.fit(X_transform,Y)                                     
prediksinn = nn.predict(X_transform)                                   
                                                                       
In [15]:
from  sklearn.tree import  DecisionTreeClassifier     
dc = DecisionTreeClassifier()                         
traingdc = dc.fit(X_transform,Y)                      
prediksidc = dc.predict(X_transform)                  
                                                      
In [16]:
#menghitung akurasi                                                               
from sklearn import  metrics                                                      
akurasi = metrics.accuracy_score(Y,prediksi)                                      
akurasinn = metrics.accuracy_score(Y,prediksinn)                                  
akurasidc = metrics.accuracy_score(Y,prediksidc)                                  
                                                                                  
print("Akurasi naive Bayes : ", akurasi * 100 , " %" )                            
print("Akurasi Neurel Network  ", akurasinn * 100 , " %")                         
print("Akurasi Decision Tree ", akurasidc * 100 , " %")                           
                                                                                  
Akurasi naive Bayes :  44.56656134084353  %
Akurasi Neurel Network   53.949718367907685  %
Akurasi Decision Tree  69.89971149883226  %
In [17]:
#Prediksi Dengan Decision Tree Lebih besar.

#Contoh 
#Terdapat Pertandingan Antara Totentham Vs Manc.City
#Nilai ODDS Home : 4.00
#Nilai Odds Away : 1.80
#Nilai Odds Draw : 4.00

#TIM Mana Yang Akan menang ? 
In [18]:
home=4                                                         
away=1.8                                                       
draw=4                                                         
                                                               
x_prediksi = [[home,away,draw]]                                
prediksi1=gnb.predict(x_prediksi)                              
print("Prediksi Naive Bayes : " , prediksi1 )                  
                                                               
prediksi2=nn.predict(x_prediksi)                               
print("Prediksi Neural Network : ", prediksi2)                 
                                                               
prediksi3 = dc.predict(x_prediksi)                             
print("Prediksi Decision Tree : ", prediksi3)                  
                                                               
Prediksi Naive Bayes :  ['A']
Prediksi Neural Network :  ['A']
Prediksi Decision Tree :  ['A']
In [19]:
#output
#H = Home Menang , D = Hasil Draw , A = Away Menang
In [ ]: