Skip to content

Instantly share code, notes, and snippets.

@kadnan
Created September 23, 2016 06:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kadnan/dcc675ca3bdca170ed21bcea2f6cb48e to your computer and use it in GitHub Desktop.
Save kadnan/dcc675ca3bdca170ed21bcea2f6cb48e to your computer and use it in GitHub Desktop.
Prediction of Match results by running Naive Bayes
"""
Labels : Lost, Draw, Won [-1,0,1]
Features
==========
Toss(Lost,Won) = [-1,1]
Bat(First, Second) = [-1,1]
"""
# Import Library of Gaussian Naive Bayes model
from sklearn.naive_bayes import GaussianNB
from sklearn.metrics import accuracy_score
import numpy as np
from sklearn.metrics import precision_recall_fscore_support as score
# Assigning Features
features = np.genfromtxt('train.csv',delimiter=',',usecols=(1,2),dtype=int)
labels = np.genfromtxt('train.csv',delimiter=',',usecols=(0),dtype=int)
features_test = np.genfromtxt('test.csv',delimiter=',',usecols=(1,2),dtype=int)
labels_test = np.genfromtxt('test.csv',delimiter=',',usecols=(0),dtype=int)
# Create a Gaussian Classifier
model = GaussianNB()
#
# # Train the model using the training sets
model.fit(features, labels)
#
# # Predict Output
predicted = model.predict(features_test)
# print(predicted)
acc = accuracy_score(labels_test,predicted)
print(acc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment