-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayPlayer-1.py
77 lines (52 loc) · 2.02 KB
/
PlayPlayer-1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from sklearn import tree
import pandas as pd
from sklearn.neighbors import KNeighborsClassifier
from sklearn import preprocessing
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
# step1 : load data
def playpredictor(filename):
data = pd.read_csv(filename,index_col=0)
print("Size of dataset : ",len(data))
# step 2 :clean prepare and manipulate data
feature_name = ["Whether","Temperature"]
whether = data.Whether
temperature = data.Temperature
play = data.Play
# print(whether)
# print(temperature)
# print(play)
print("Name of Features",feature_name)
data_train,data_test,target_train,target_test = train_test_split(whether,play,test_size = 0.5)
#creating labelEncoder
le = preprocessing.LabelEncoder()
# converting string lable into number
whether_encoded = le.fit_transform(whether)
print(whether_encoded)
temp_encoded = le.fit_transform(temperature)
print(temp_encoded)
label = le.fit_transform(play)
# combining weather and temp into single list of tuple
features = list(zip(whether_encoded,temp_encoded))
# step 3 : train data
model = KNeighborsClassifier(n_neighbors = 3)
# train the model using training sets
model.fit(features,label)
# step 4 :test model
predicted = model.predict([[0,2]]) #0 overcast 2 mild
print(predicted)
# accuracy = accuracy_score(target_test,predicted)
# print("The Accuracy of our model is : ",accuracy)
# return predicted
def main():
print("_______marvellous infosystem_________")
print("Machine learning algorithm")
print("Play predictor application using k nearest knighbor algorithm")
dataset = r"C:\Users\91774\Desktop\Marvellous_Infosystem_Code\Assignment\Assignment 14\PlayPredictor.csv"
result = playpredictor(dataset)
if result:
print("Yes")
else:
print("NO")
if __name__ == "__main__":
main()