Professional Documents
Culture Documents
import pandas as pd
df=pd.read_csv("play_tennis.csv")
df
df.describe()
del df['day']
df
----------------------------------------------------------------------
-----
KeyError Traceback (most recent call
last)
~\anaconda3\lib\site-packages\pandas\core\indexes\base.py in
get_loc(self, key, method, tolerance)
3360 try:
-> 3361 return self._engine.get_loc(casted_key)
3362 except KeyError as err:
~\anaconda3\lib\site-packages\pandas\_libs\index.pyx in
pandas._libs.index.IndexEngine.get_loc()
~\anaconda3\lib\site-packages\pandas\_libs\index.pyx in
pandas._libs.index.IndexEngine.get_loc()
pandas\_libs\hashtable_class_helper.pxi in
pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas\_libs\hashtable_class_helper.pxi in
pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'day'
The above exception was the direct cause of the following exception:
~\anaconda3\lib\site-packages\pandas\core\generic.py in
__delitem__(self, key)
3961 # there was no match, this call should raise the
appropriate
3962 # exception:
-> 3963 loc = self.axes[-1].get_loc(key)
3964 self._mgr = self._mgr.idelete(loc)
3965
~\anaconda3\lib\site-packages\pandas\core\indexes\base.py in
get_loc(self, key, method, tolerance)
3361 return self._engine.get_loc(casted_key)
3362 except KeyError as err:
-> 3363 raise KeyError(key) from err
3364
3365 if is_scalar(key) and isna(key) and not self.hasnans:
KeyError: 'day'
feature_cols=df.columns[1:-1]
feature_cols
df.shape
(14, 6)
b=df.columns[:-1]
df.head()
a=df.columns[-1:]
a
Index(['play'], dtype='object')
x = df.drop(a,axis=1)
y = df[a]
DecisionTreeClassifier()
y_pred = classifier.predict(x_test)
accuracy 0.67 3
macro avg 0.75 0.75 0.67 3
weighted avg 0.83 0.67 0.67 3
print("Accuracy:",metrics.accuracy_score(y_test, y_pred))
Accuracy: 0.6666666666666666