You are on page 1of 18

Artificial Intelligence – Lab

BSCS [6A]

FINAL TERM PROJECT REPORT

Submitted By [Group No. 1]:


• Abdul Wahab (Leader)
• Muhammad Hamza Khan
• Rehan Ejaz
• Muhammad Mahad Shahbaz
• Muhammad Mujtaba

Submitted to: Ms. Zupash Awais

CS:GO Round Winner Classification


Predict who wins in the tactical shooter

DEPARTMENT OF COMPUTER SCIENCES


BAHRIA UNIVERSITY, LAHORE CAMPUS
Table of Contents
Marks Distribution .................................................................................................................................. 4

Abstract ................................................................................................................................................... 5

1. Introduction ................................................................................................................................. 6

Name ................................................................................................................................................... 6

Context ................................................................................................................................................ 6

Content ................................................................................................................................................ 6

Inspiration ........................................................................................................................................... 6

Number of Observations ..................................................................................................................... 6

Number of Features............................................................................................................................. 6

Features names (Complete)................................................................................................................. 6

Features names (Used) ........................................................................................................................ 7

2. Problem Statement ...................................................................................................................... 8

3. Objectives ................................................................................................................................... 8

4. Methodology ............................................................................................................................... 8

Dataset............................................................................................................................................. 8
Libraries used .................................................................................................................................. 8
Algorithms used: ............................................................................................................................. 8
5. Results ......................................................................................................................................... 9

Decision Tree ...................................................................................................................................... 9

Random Forest .................................................................................................................................... 9

Liner Regression ............................................................................................................................... 10

KMeans Clustering ........................................................................................................................... 11

6. Code .......................................................................................................................................... 11

Decision Tree .................................................................................................................................... 11

Random Forest .................................................................................................................................. 12

Liner Regression ............................................................................................................................... 14

KMeans Clustering ........................................................................................................................... 15


7. References ................................................................................................................................. 18
Marks Distribution

------------------------------ For Instructor Use Only ----------------------------------

Project Grading Sheet


Sr. Max Obtained
Task Comments(if any)
No. Marks Marks
1. Report 05

2. Implementation 10
Viva
3. 15
(Oral/Task Based or Both)

Total 30 Signature:

---------------------------------------------------------------------------

-------------------------------------- Instructions -----------------------------------------

1. Follow the below given steps to design your report :

• Font Style : Times New Roman


• Font Size : First Heading (14 pts), Sub Headings (12 pts), Normal
Text (12pts)
• Justify you normal text under each heading

2. Deadline of the project : 22nd January, 2021 (08 :30 AM Submission)


(viva : 11:00 AM)

------------------------------------------------------------------------------------------------
Abstract
This report is based on the procedure of implementation of algorithms for data prediction
such as KMeans. Dataset is obtained from Kaggle. 80% of dataset is used for training and
20% of dataset is used for testing. Sklearn library is used for main purposes like prediction,
splitting, etc. For plotting data, matplotlib is used. For handling dataset, pandas is used.
1. Introduction

Name
CS: GO Round Winner Classification

Context
CS: GO is a tactical shooter, where two teams (CT and Terrorist) play for a
best of 30 rounds, with each round being 1 minute and 55 seconds. There are 5
players on each team (10 in total) and the first team to reach 16 rounds wins the game.
At the start, one team plays as CT and the other as Terrorist. After 15 rounds played,
the teams swap side. There are 7 different maps a game can be played on. You win a
round as Terrorist by either planting the bomb and making sure it explodes, or by
eliminating the other team. You win a round as CT by either eliminating the other
team, or by disarming the bomb, should it have been planted.

Content
The dataset was originally published by Skybox as part of their CS: GO AI
Challenge, running from Spring to Fall 2020. The data set consists of ~700 demos
from high level tournament play in 2019 and 2020. Warmup rounds and restarts have
been filtered, and for the remaining live rounds a round snapshot have been recorded
every 20 seconds until the round is decided. Following the initial publication, it has
been pre-processed and flattened to improve readability and make it easier for
algorithms to process. The total number of snapshots is 122411.

Inspiration
• What types of machine learning models perform best on this dataset?
• Which features are most indicative of which teams wins the round?
• Are some weapons favorable to others?
• What attributes should your team have to win? Health, armor or
money?

Number of Observations
The total number of observations is 122411.

Number of Features
The total number of features is 97.

Features names (Complete)


'time_left', 'ct_score', 't_score', 'map', 'bomb_planted', 'ct_health',
't_health', 'ct_armor', 't_armor', 'ct_money', 't_money', 'ct_helmets',
't_helmets', 'ct_defuse_kits', 'ct_players_alive', 't_players_alive',
'ct_weapon_ak47', 't_weapon_ak47', 'ct_weapon_aug', 't_weapon_aug',
'ct_weapon_awp', 't_weapon_awp', 'ct_weapon_bizon', 't_weapon_bizon',
'ct_weapon_cz75auto', 't_weapon_cz75auto', 'ct_weapon_elite',
't_weapon_elite', 'ct_weapon_famas', 't_weapon_famas',
'ct_weapon_g3sg1', 't_weapon_g3sg1', 'ct_weapon_galilar',
't_weapon_galilar', 'ct_weapon_glock', 't_weapon_glock',
'ct_weapon_m249', 't_weapon_m249', 'ct_weapon_m4a1s', 't_weapon_m4a1s',
'ct_weapon_m4a4', 't_weapon_m4a4', 'ct_weapon_mac10', 't_weapon_mac10',
'ct_weapon_mag7', 't_weapon_mag7', 'ct_weapon_mp5sd', 't_weapon_mp5sd',
'ct_weapon_mp7', 't_weapon_mp7', 'ct_weapon_mp9', 't_weapon_mp9',
'ct_weapon_negev', 't_weapon_negev', 'ct_weapon_nova', 't_weapon_nova',
'ct_weapon_p90', 't_weapon_p90', 'ct_weapon_r8revolver',
't_weapon_r8revolver', 'ct_weapon_sawedoff', 't_weapon_sawedoff',
'ct_weapon_scar20', 't_weapon_scar20', 'ct_weapon_sg553',
't_weapon_sg553', 'ct_weapon_ssg08', 't_weapon_ssg08',
'ct_weapon_ump45', 't_weapon_ump45', 'ct_weapon_xm1014',
't_weapon_xm1014', 'ct_weapon_deagle', 't_weapon_deagle',
'ct_weapon_fiveseven', 't_weapon_fiveseven', 'ct_weapon_usps',
't_weapon_usps', 'ct_weapon_p250', 't_weapon_p250', 'ct_weapon_p2000',
't_weapon_p2000', 'ct_weapon_tec9', 't_weapon_tec9',
'ct_grenade_hegrenade', 't_grenade_hegrenade', 'ct_grenade_flashbang',
't_grenade_flashbang', 'ct_grenade_smokegrenade',
't_grenade_smokegrenade', 'ct_grenade_incendiarygrenade',
't_grenade_incendiarygrenade', 'ct_grenade_molotovgrenade',
't_grenade_molotovgrenade', 'ct_grenade_decoygrenade',
't_grenade_decoygrenade', 'round_winner'

Features names (Used)


1. time_left
2. ct_score
3. t_score
4. bomb_planted
5. ct_health
6. t_health
7. ct_armor
8. t_armor
9. ct_money
10. t_money
11. ct_helmets
12. t_helmets
13. ct_defuse_kits
14. ct_players_alive
15. t_players_alive
2. Problem Statement
• To predict the round winner.

3. Objectives
After completing this project, we learn the following concepts:
• Basics of machine learning
• Numpy library
• Matplotlib library
• Sklearn library
• Pandas library
• And some other concepts

4. Methodology
Dataset: Downloaded from Kaggle.com

Libraries used: Numpy, matplotlib, sklearn, pandas

Algorithms used:
KMeans: k-means clustering is a method of vector quantization, originally from signal
processing, that aims to partition n observations into k clusters in which each observation
belongs to the cluster with the nearest mean, serving as a prototype of the cluster.

Linear Regression: Linear Regression Algorithm is a machine learning algorithm based on


supervised learning. Linear regression is a part of regression analysis. Regression analysis is a
technique of predictive modelling that helps you to find out the relationship between Input
and the target variable.

Random forest: Random forests or random decision forests are an ensemble learning
method for classification, regression and other tasks that operate by constructing a multitude
of decision trees at training time and outputting the class that is the mode of the classes
(classification) or mean/average prediction (regression) of the individual trees. Random
decision forests correct for decision trees' habit of overfitting to their training set. Random
forests generally outperform decision trees, but their accuracy is lower than gradient boosted
trees. However, data characteristics can affect their performance

Decision Tree: Decision Tree algorithm belongs to the family of supervised learning
algorithms. Unlike other supervised learning algorithms, decision tree algorithm can be used
for solving regression and classification problems too. The general motive of using Decision
Tree is to create a training model which can use to predict class or value of target variables by
learning decision rules inferred from prior data(training data).
5. Results

Decision Tree

Random Forest
Liner Regression
KMeans Clustering

6. Code

Decision Tree
import pandas as pd
import numpy as np
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn import metrics

dataset = pd.read_csv("csgo_round_snapshots.csv")

X = dataset[[
'time_left',
'ct_score',
't_score',
'bomb_planted',
'ct_health',
't_health',
'ct_armor',
't_armor',
'ct_money',
't_money',
'ct_helmets',
't_helmets',
'ct_defuse_kits',
'ct_players_alive',
't_players_alive'
]].values
y = dataset[['round_winner']]

label_mapping = {
"CT":1,
"T":0
}

y["round_winner"] = y["round_winner"].map(label_mapping)
y = np.array(y)

X_train, X_test, y_train, y_test = train_test_split(X, y ,test_size = 0.2)

model = DecisionTreeClassifier(criterion = 'entropy')


model.fit(X_train, y_train)
prediction = model.predict(X_test)

print("predictions: ", prediction)


print("accuracy: ", accuracy_score(y_test, prediction))
print('Mean Absolute Error:', metrics.mean_absolute_error(y_test, prediction))
print('Mean Squared Error:', metrics.mean_squared_error(y_test, prediction))
print('Root Mean Squared Error:', np.sqrt(metrics.mean_squared_error(y_test, prediction)))

#print(pd.crosstab(y_train, label))

i = 100
AV = y[i] == 0 and "Terroists" or "Counter terrorists"
PV = model.predict(X)[i] < 1 and "Terroists" or "Counter terrorists"

print("According to actual value, {} wins.".format(AV))


print("According to prediction, {} wins.".format(PV))

Random Forest
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn.ensemble import RandomForestRegressor
from sklearn import metrics
import os
import matplotlib.pyplot as plt

dataset = pd.read_csv("csgo_round_snapshots.csv")
X = dataset[[
'time_left',
'ct_score',
't_score',
'bomb_planted',
'ct_health',
't_health',
'ct_armor',
't_armor',
'ct_money',
't_money',
'ct_helmets',
't_helmets',
'ct_defuse_kits',
'ct_players_alive',
't_players_alive'
]].values

y = dataset[['round_winner']]

label_mapping = {
"CT":1,
"T":0
}

y["round_winner"] = y["round_winner"].map(label_mapping)
y = np.array(y)

X_train, X_test, y_train, y_test = train_test_split(X, y ,test_size = 0.2)

regressor = RandomForestRegressor(n_estimators=20, random_state=0)


regressor.fit(X_train, y_train)
prediction = regressor.predict(X_test)
os.system("CLS")
print("predictions: ", prediction)
#print("accuracy: ", accuracy_score(y_test, prediction))
print('Mean Absolute Error:', metrics.mean_absolute_error(y_test, prediction))
print('Mean Squared Error:', metrics.mean_squared_error(y_test, prediction))
print('Root Mean Squared Error:', np.sqrt(metrics.mean_squared_error(y_test, prediction)))

#print(pd.crosstab(y_train, label))

i = 200
#x = a > b and 10 or 11
AV = y[i] == 0 and "Terroists" or "Counter terrorists"
PV = regressor.predict(X)[i] < 1 and "Terroists" or "Counter terrorists"

print("According to actual value, {} wins.".format(AV))


print("According to prediction, {} wins.".format(PV))

Liner Regression
import numpy as np
import pandas as pd
from sklearn import linear_model
from sklearn.metrics import accuracy_score

from sklearn.model_selection import train_test_split, cross_val_predict


import matplotlib.pyplot as plt
import os
from sklearn import metrics

dataset = pd.read_csv("csgo_round_snapshots.csv")

X = dataset[[
'time_left',
'ct_score',
't_score',
'bomb_planted',
'ct_health',
't_health',
'ct_armor',
't_armor',
'ct_money',
't_money',
'ct_helmets',
't_helmets',
'ct_defuse_kits',
'ct_players_alive',
't_players_alive'
]].values

y = dataset[['round_winner']]

label_mapping = {
"CT":1,
"T":0
}

y["round_winner"] = y["round_winner"].map(label_mapping)
y = np.array(y)

X_train, X_test, y_train, y_test = train_test_split(X, y ,test_size = 0.2)

linear_regression_model = linear_model.LinearRegression()
#plt.scatter(X.T[14], y)
#plt.show()

model = linear_regression_model.fit(X_train, y_train)


prediction = model.predict(X_test)
os.system("CLS")

print("predictions: ", prediction)


#print("accuracy: ", accuracy_score(y_test, prediction)*100)
#ValueError: Classification metrics can't handle a mix of binary and continuous targets

print("R^2 score: ", linear_regression_model.score(X,y))


print("coedd: ", linear_regression_model.coef_)
print("intercept: ", linear_regression_model.intercept_)
print('Mean Absolute Error:', metrics.mean_absolute_error(y_test, prediction))
print('Mean Squared Error:', metrics.mean_squared_error(y_test, prediction))
print('Root Mean Squared Error:', np.sqrt(metrics.mean_squared_error(y_test, prediction)))

i = 100
AV = y[i] == 0 and "Terroists" or "Counter terrorists"
PV = model.predict(X)[i] < 1 and "Terroists" or "Counter terrorists"

print("According to actual value, {} wins.".format(AV))


print("According to prediction, {} wins.".format(PV))

predicted = cross_val_predict(model, X, y, cv=5)

fig, ax = plt.subplots()
ax.scatter(y, predicted)
ax.plot([y.min(), y.max()], [y.min(), y.max()], 'k--', lw=3)
ax.set_xlabel('Measured')
ax.set_ylabel('Predicted')
plt.show()

KMeans Clustering
import pandas as pd
import numpy as np
from sklearn.cluster import KMeans
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn.preprocessing import scale
from sklearn.decomposition import PCA
import matplotlib.pyplot as plt
from sklearn import metrics
dataset = pd.read_csv("csgo_round_snapshots.csv")

X = dataset[[
'time_left',
'ct_score',
't_score',
'bomb_planted',
'ct_health',
't_health',
'ct_armor',
't_armor',
'ct_money',
't_money',
'ct_helmets',
't_helmets',
'ct_defuse_kits',
'ct_players_alive',
't_players_alive'
]].values

y = dataset[['round_winner']]

label_mapping = {
"CT":1,
"T":0
}

y["round_winner"] = y["round_winner"].map(label_mapping)
y = np.array(y)

X_train, X_test, y_train, y_test = train_test_split(X, y ,test_size = 0.2)

model = KMeans(n_clusters = 2, random_state = 0)


model.fit(X_train)
prediction = model.predict(X_test)
label = model.labels_

print("lables", label)
print("predictions: ", prediction)
print("accuracy: ", accuracy_score(y_test, prediction)*100)
print("actual: ", y_test)
print('Mean Absolute Error:', metrics.mean_absolute_error(y_test, prediction))
print('Mean Squared Error:', metrics.mean_squared_error(y_test, prediction))
print('Root Mean Squared Error:', np.sqrt(metrics.mean_squared_error(y_test, prediction)))
#print(pd.crosstab(y_train, label))

i = 100
AV = y[i] == 0 and "Terroists" or "Counter terrorists"
PV = model.predict(X)[i] < 1 and "Terroists" or "Counter terrorists"
print("According to actual value, {} wins.".format(AV))
print("According to prediction, {} wins.".format(PV))

reduced_data = PCA(n_components=2).fit_transform(X)
kmeans = KMeans(init='k-means++', n_clusters=2, n_init=10)
kmeans.fit(reduced_data)

#error while ploting: numpy.core._exceptions.MemoryError:


#Unable to allocate 199. TiB for an array with shape (4872677, 5624705) and data type float
64
'''
# Step size of the mesh. Decrease to increase the quality of the VQ.
h = .02 # point in the mesh [x_min, x_max]x[y_min, y_max].

# Plot the decision boundary. For that, we will assign a color to each
x_min, x_max = reduced_data[:, 0].min() - 1, reduced_data[:, 0].max() + 1
y_min, y_max = reduced_data[:, 1].min() - 1, reduced_data[:, 1].max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))

# Obtain labels for each point in mesh. Use last trained model.
Z = kmeans.predict(np.c_[xx.ravel(), yy.ravel()])

# Put the result into a color plot


Z = Z.reshape(xx.shape)
plt.figure(1)
plt.clf()
plt.imshow(Z, interpolation='nearest',
extent=(xx.min(), xx.max(), yy.min(), yy.max()),
cmap=plt.cm.Paired,
aspect='auto', origin='lower')

plt.plot(reduced_data[:, 0], reduced_data[:, 1], 'k.', markersize=2)


# Plot the centroids as a white X
centroids = kmeans.cluster_centers_
plt.scatter(centroids[:, 0], centroids[:, 1],
marker='x', s=169, linewidths=3,
color='w', zorder=10)
plt.title('K-means clustering on the digits dataset (PCA-reduced data)\n'
'Centroids are marked with white cross')
plt.xlim(x_min, x_max)
plt.ylim(y_min, y_max)
plt.xticks(())
plt.yticks(())
plt.show()
'''

7. References
www.youtube.com
www.stackoverflow.com
https://towardsdatascience.com/

You might also like