Skip to content

Predict the winner of FIFA World Cup 2018 in Python

Notifications You must be signed in to change notification settings

nimitsolanki/FIFA-WC-2018

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FIFA-WC-2018

Predict the winner of FIFA World Cup 2018 with the help of LogisticRegression.

Python 3

  • pandas
  • numpy
  • matplotlib.pyplot
  • seaborn
  • matplotlib.ticker
  • sklearn.model_selection
  • sklearn.linear_model

# Load data

world_cup = pd.read_csv('datasets/World_Cup_2018_Dataset.csv')
results = pd.read_csv('datasets/results.csv')

# Team patcipating in the world cup

worldcup_teams = ['Australia', ' Iran', 'Japan', 'Korea Republic', 
            'Saudi Arabia', 'Egypt', 'Morocco', 'Nigeria', 
            'Senegal', 'Tunisia', 'Costa Rica', 'Mexico', 
            'Panama', 'Argentina', 'Brazil', 'Colombia', 
            'Peru', 'Uruguay', 'Belgium', 'Croatia', 
            'Denmark', 'England', 'France', 'Germany', 
            'Iceland', 'Poland', 'Portugal', 'Russia', 
            'Serbia', 'Spain', 'Sweden', 'Switzerland']
df_teams_home = results[results['home_team'].isin(worldcup_teams)]
df_teams_away = results[results['away_team'].isin(worldcup_teams)]
df_teams = pd.concat((df_teams_home, df_teams_away))
df_teams.drop_duplicates()
df_teams.count()

#Building the model Prediction label: The winning_team column will show "2" if the home team has won, "1" if it was a tie, and "0" if the away team has won.

df_teams_1930 = df_teams_1930.reset_index(drop=True)
df_teams_1930.loc[df_teams_1930.winning_team == df_teams_1930.home_team,'winning_team']=2
df_teams_1930.loc[df_teams_1930.winning_team == 'Draw', 'winning_team']=1
df_teams_1930.loc[df_teams_1930.winning_team == df_teams_1930.away_team, 'winning_team']=0

df_teams_1930.head()

Group matches

predictions = logreg.predict(pred_set)
for i in range(fixtures.shape[0]):
    print(backup_pred_set.iloc[i, 1] + " and " + backup_pred_set.iloc[i, 0])
    if predictions[i] == 2:
        print("Winner: " + backup_pred_set.iloc[i, 1])
    elif predictions[i] == 1:
        print("Draw")
    elif predictions[i] == 0:
        print("Winner: " + backup_pred_set.iloc[i, 0])
    print('Probability of ' + backup_pred_set.iloc[i, 1] + ' winning: ', '%.3f'%(logreg.predict_proba(pred_set)[i][2]))
    print('Probability of Draw: ', '%.3f'%(logreg.predict_proba(pred_set)[i][1]))
    print('Probability of ' + backup_pred_set.iloc[i, 0] + ' winning: ', '%.3f'%(logreg.predict_proba(pred_set)[i][0]))
    print("")

Group matches

Russia and Saudi Arabia
Winner: Russia
Probability of Russia winning: 0.664
Probability of Draw: 0.220
Probability of Saudi Arabia winning: 0.115

Uruguay and Egypt
Winner: Uruguay
Probability of Uruguay winning: 0.590
Probability of Draw: 0.341
Probability of Egypt winning: 0.069

Iran and Morocco
Draw
Probability of Iran winning: 0.236
Probability of Draw: 0.429
Probability of Morocco winning: 0.335

Portugal and Spain
Draw
Probability of Portugal winning: 0.297
Probability of Draw: 0.351
Probability of Spain winning: 0.351

France and Australia
Winner: France
Probability of France winning: 0.628
Probability of Draw: 0.222
Probability of Australia winning: 0.151

Argentina and Iceland
Winner: Argentina
Probability of Argentina winning: 0.822
Probability of Draw: 0.144
Probability of Iceland winning: 0.034

Peru and Denmark
Winner: Peru
Probability of Peru winning: 0.440
Probability of Draw: 0.166
Probability of Denmark winning: 0.394

Croatia and Nigeria
Winner: Croatia
Probability of Croatia winning: 0.579
Probability of Draw: 0.280
Probability of Nigeria winning: 0.141

Costa Rica and Serbia
Winner: Costa Rica
Probability of Costa Rica winning: 0.338
Probability of Draw: 0.324
Probability of Serbia winning: 0.337

Germany and Mexico
Winner: Germany
Probability of Germany winning: 0.589
Probability of Draw: 0.258
Probability of Mexico winning: 0.153

Brazil and Switzerland
Winner: Brazil
Probability of Brazil winning: 0.756
Probability of Draw: 0.157
Probability of Switzerland winning: 0.087

Sweden and Korea Republic
Winner: Sweden
Probability of Sweden winning: 0.523
Probability of Draw: 0.312
Probability of Korea Republic winning: 0.166

Belgium and Panama
Winner: Belgium
Probability of Belgium winning: 0.771
Probability of Draw: 0.145
Probability of Panama winning: 0.084

England and Tunisia
Winner: England
Probability of England winning: 0.665
Probability of Draw: 0.277
Probability of Tunisia winning: 0.058

Colombia and Japan
Winner: Colombia
Probability of Colombia winning: 0.513
Probability of Draw: 0.204
Probability of Japan winning: 0.284

Poland and Senegal
Winner: Poland
Probability of Poland winning: 0.586
Probability of Draw: 0.248
Probability of Senegal winning: 0.166

Egypt and Russia
Winner: Russia
Probability of Egypt winning: 0.216
Probability of Draw: 0.289
Probability of Russia winning: 0.495

Portugal and Morocco
Winner: Portugal
Probability of Portugal winning: 0.512
Probability of Draw: 0.364
Probability of Morocco winning: 0.124

Uruguay and Saudi Arabia
Winner: Uruguay
Probability of Uruguay winning: 0.670
Probability of Draw: 0.252
Probability of Saudi Arabia winning: 0.078

Spain and Iran
Winner: Spain
Probability of Spain winning: 0.708
Probability of Draw: 0.242
Probability of Iran winning: 0.050

Denmark and Australia
Winner: Denmark
Probability of Denmark winning: 0.560
Probability of Draw: 0.225
Probability of Australia winning: 0.215

France and Peru
Winner: France
Probability of France winning: 0.633
Probability of Draw: 0.222
Probability of Peru winning: 0.145

Argentina and Croatia
Winner: Argentina
Probability of Argentina winning: 0.596
Probability of Draw: 0.259
Probability of Croatia winning: 0.145

Brazil and Costa Rica
Winner: Brazil
Probability of Brazil winning: 0.792
Probability of Draw: 0.160
Probability of Costa Rica winning: 0.048

Iceland and Nigeria
Winner: Nigeria
Probability of Iceland winning: 0.280
Probability of Draw: 0.285
Probability of Nigeria winning: 0.435

Switzerland and Serbia
Winner: Switzerland
Probability of Switzerland winning: 0.438
Probability of Draw: 0.231
Probability of Serbia winning: 0.331

Belgium and Tunisia
Winner: Belgium
Probability of Belgium winning: 0.622
Probability of Draw: 0.248
Probability of Tunisia winning: 0.130

Mexico and Korea Republic
Winner: Mexico
Probability of Mexico winning: 0.510
Probability of Draw: 0.313
Probability of Korea Republic winning: 0.177

Germany and Sweden
Winner: Germany
Probability of Germany winning: 0.585
Probability of Draw: 0.223
Probability of Sweden winning: 0.191

England and Panama
Winner: England
Probability of England winning: 0.792
Probability of Draw: 0.170
Probability of Panama winning: 0.037

Senegal and Japan
Winner: Japan
Probability of Senegal winning: 0.354
Probability of Draw: 0.290
Probability of Japan winning: 0.356

Poland and Colombia
Draw
Probability of Poland winning: 0.367
Probability of Draw: 0.400
Probability of Colombia winning: 0.233

Uruguay and Russia
Winner: Uruguay
Probability of Uruguay winning: 0.388
Probability of Draw: 0.385
Probability of Russia winning: 0.227

Egypt and Saudi Arabia
Winner: Egypt
Probability of Egypt winning: 0.548
Probability of Draw: 0.205
Probability of Saudi Arabia winning: 0.246

Portugal and Iran
Winner: Portugal
Probability of Portugal winning: 0.552
Probability of Draw: 0.357
Probability of Iran winning: 0.091

Spain and Morocco
Winner: Spain
Probability of Spain winning: 0.682
Probability of Draw: 0.248
Probability of Morocco winning: 0.070

France and Denmark
Winner: France
Probability of France winning: 0.623
Probability of Draw: 0.160
Probability of Denmark winning: 0.218

Peru and Australia
Winner: Peru
Probability of Peru winning: 0.461
Probability of Draw: 0.237
Probability of Australia winning: 0.302

Argentina and Nigeria
Winner: Argentina
Probability of Argentina winning: 0.717
Probability of Draw: 0.220
Probability of Nigeria winning: 0.063

Croatia and Iceland
Winner: Croatia
Probability of Croatia winning: 0.739
Probability of Draw: 0.184
Probability of Iceland winning: 0.077

Mexico and Sweden
Winner: Mexico
Probability of Mexico winning: 0.455
Probability of Draw: 0.263
Probability of Sweden winning: 0.282

Germany and Korea Republic
Winner: Germany
Probability of Germany winning: 0.623
Probability of Draw: 0.264
Probability of Korea Republic winning: 0.113

Brazil and Serbia
Winner: Brazil
Probability of Brazil winning: 0.719
Probability of Draw: 0.174
Probability of Serbia winning: 0.108

Switzerland and Costa Rica
Winner: Switzerland
Probability of Switzerland winning: 0.604
Probability of Draw: 0.222
Probability of Costa Rica winning: 0.174

Poland and Japan
Winner: Poland
Probability of Poland winning: 0.532
Probability of Draw: 0.255
Probability of Japan winning: 0.212

Colombia and Senegal
Winner: Colombia
Probability of Colombia winning: 0.573
Probability of Draw: 0.200
Probability of Senegal winning: 0.227

Tunisia and Panama
Winner: Tunisia
Probability of Tunisia winning: 0.638
Probability of Draw: 0.254
Probability of Panama winning: 0.108

Belgium and England
Winner: England
Probability of Belgium winning: 0.261
Probability of Draw: 0.242
Probability of England winning: 0.497

Group 16

Portugal and Uruguay
Winner: Portugal
Probability of Portugal winning: 0.428
Probability of Draw: 0.285
Probability of Uruguay winning: 0.287

France and Croatia
Winner: France
Probability of France winning: 0.481
Probability of Draw: 0.252
Probability of Croatia winning: 0.267

Brazil and Mexico
Winner: Brazil
Probability of Brazil winning: 0.695
Probability of Draw: 0.209
Probability of Mexico winning: 0.096

England and Colombia
Winner: England
Probability of England winning: 0.516
Probability of Draw: 0.368
Probability of Colombia winning: 0.116

Spain and Russia
Winner: Spain
Probability of Spain winning: 0.529
Probability of Draw: 0.280
Probability of Russia winning: 0.191

Argentina and Peru
Winner: Argentina
Probability of Argentina winning: 0.713
Probability of Draw: 0.212
Probability of Peru winning: 0.075

Germany and Switzerland
Winner: Germany
Probability of Germany winning: 0.672
Probability of Draw: 0.192
Probability of Switzerland winning: 0.137

Belgium and Poland
Winner: Belgium
Probability of Belgium winning: 0.513
Probability of Draw: 0.202
Probability of Poland winning: 0.285

Quarters

Portugal and France
Winner: Portugal
Probability of Portugal winning: 0.437
Probability of Draw: 0.256
Probability of France winning: 0.307

Argentina and Spain
Winner: Argentina
Probability of Argentina winning: 0.518
Probability of Draw: 0.262
Probability of Spain winning: 0.220

Brazil and England
Winner: Brazil
Probability of Brazil winning: 0.525
Probability of Draw: 0.216
Probability of England winning: 0.260

Germany and Belgium
Winner: Germany
Probability of Germany winning: 0.563
Probability of Draw: 0.269
Probability of Belgium winning: 0.167

Semifinal

Brazil and Portugal
Winner: Brazil
Probability of Brazil winning: 0.705
Probability of Draw: 0.152
Probability of Portugal winning: 0.143

Germany and Argentina
Winner: Germany
Probability of Germany winning: 0.441
Probability of Draw: 0.264
Probability of Argentina winning: 0.295

Final

Germany and Brazil
Winner: Brazil
Probability of Germany winning: 0.359
Probability of Draw: 0.220
Probability of Brazil winning: 0.421

Releases

No releases published

Packages

No packages published