-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayPredictor.py
192 lines (92 loc) · 2.29 KB
/
PlayPredictor.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/env python
# coding: utf-8
# # Loading some important libraries for loading data
# In[ ]:
################################
## Name - Mallinath Elekar
## Data Set -
## Independent Variable - Wether
## Dependent Variable - Play
## We have to predict whether he can play or not
## df is used as variable to store the data
## This dataset has no null values
## 1)Load the data using pandas
## 2)Preprocessing,Data Analysis
## 3)Train the data
## 4)Test the data
## 5) Improve the accuracy
##
##
##
################################
# In[ ]:
# In[14]:
import pandas as pd
# # Load the data
# In[15]:
df=pd.read_csv('Play.csv')
df.head()
# # Data Analysis
# In[16]:
#How big is the data
df.shape
# In[17]:
#datatype of columns
df.info()
# In[18]:
#is there any missing value
df.isnull().sum()
# In[19]:
#how does the data look mathematically
df.describe()
# In[20]:
#are there any duplicate values
df.duplicated().sum()
# # Generating Profile Report For Data Analysis
# In[21]:
from pandas_profiling import ProfileReport
prof=ProfileReport(df)
prof.to_file(output_file='output.html')
# In[22]:
df.head()
# # Converting Categorical Data Into Numeric Using Label Encoder
# In[23]:
from sklearn.preprocessing import LabelEncoder
le=LabelEncoder()
# In[24]:
df['Wether_N']=le.fit_transform(df['Wether'])
df.head()
# In[25]:
df['Temperature_N']=le.fit_transform(df['Temperature'])
df.head()
# In[26]:
df['Play_N']=le.fit_transform(df['Play'])
df.head()
# # Dropping the old columns
# In[27]:
df1=df.drop(['Wether','Temperature','Play'],axis=1)
df1.head()
# In[31]:
X=df[['Wether_N','Temperature_N']]
Y=df[['Play_N']]
# In[32]:
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
# In[33]:
X_train,X_test,Y_train,Y_test=train_test_split(X,Y,test_size=0.5)
# In[34]:
from sklearn import tree
clf=tree.DecisionTreeClassifier()
model=clf.fit(X_train,Y_train)
result=model.predict(X_test)
Percentage=accuracy_score(result,Y_test)
print('Accuarcy is',Percentage*100)
# In[35]:
from sklearn.neighbors import KNeighborsClassifier
# In[39]:
clf=KNeighborsClassifier()
model=clf.fit(X_train,Y_train)
result=model.predict(X_test)
percentage=accuracy_score(result,Y_test)
print("Accuracy is",percentage*100)
# In[ ]: