Decision Tree on Classification Lab ML - Jupyter Notebook
Decision Tree on Classification Lab ML - Jupyter Notebook
In [5]: poke
Out[5]:
Type Sp. Sp.
# Name Type 1 Total HP Attack Defense Speed
2 Atk Def
VenusaurMega
3 3 Grass Poison 625 80 100 123 122 120 80
Venusaur
... ... ... ... ... ... ... ... ... ... ... ...
795 719 Diancie Rock Fairy 600 50 100 150 100 150 50
DiancieMega
796 719 Rock Fairy 700 50 160 110 160 110 110
Diancie
HoopaHoopa
797 720 Psychic Ghost 600 80 110 60 150 130 70
Confined
HoopaHoopa
798 720 Psychic Dark 680 80 160 60 170 130 80
Unbound
In [6]: poke.head()
Out[6]:
Type Type Sp. Sp.
# Name Total HP Attack Defense Speed Gene
1 2 Atk Def
VenusaurMega
3 3 Grass Poison 625 80 100 123 122 120 80
Venusaur
(https://getlin
4 4 Charmander Fire NaN 309 39 52 43 60 50 65
In [8]: poke.head()
Out[8]:
Sp. S
# Name Primary_type Secondary_type Total HP Attack Defense
Atk D
VenusaurMega
3 3 Grass Poison 625 80 100 123 122 12
Venusaur
Out[9]: 0 True
1 True
2 True
3 True
4 False
...
795 False
796 False
797 False
798 False
799 False
Name: Primary_type, Length: 800, dtype: bool
Out[10]:
S
# Name Primary_type Secondary_type Total HP Attack Defense
At
70 rows × 13 columns
In [12]: grass_pokemon.head()
Out[12]:
Sp.
# Name Primary_type Secondary_type Total HP Attack Defense
Atk
VenusaurMega
3 3 Grass Poison 625 80 100 123 122
Venusaur
In [14]: water_pokemon.head()
Out[14]:
Sp.
# Name Primary_type Secondary_type Total HP Attack Defense
Atk
BlastoiseMega
12 9 Water NaN 630 79 103 120 135
Blastoise
(https://getlin
59 54 Psyduck Water NaN 320 50 52 48 65
In [16]: fire_pokemon.head()
Out[16]:
Sp. S
# Name Primary_type Secondary_type Total HP Attack Defense
Atk D
CharizardMega
7 6 Fire Dragon 634 78 130 111 130
Charizard X
CharizardMega
8 6 Fire Flying 634 78 104 78 159 1
Charizard Y
In [17]: poke.shape
In [18]: grass_pokemon.shape
In [19]: fire_pokemon.shape
In [20]: water_pokemon.shape
Out[21]: 0.2925
In [22]: grass_pokemon.head()
Out[22]:
Sp.
# Name Primary_type Secondary_type Total HP Attack Defense
Atk
VenusaurMega
3 3 Grass Poison 625 80 100 123 122
Venusaur
(https://getlin
In [30]: grass_pokemon.describe()
Out[30]:
# Total HP Attack Defense Sp. Atk Sp.
In [31]: water_pokemon.head()
Out[31]:
Sp.
# Name Primary_type Secondary_type Total HP Attack Defense
Atk
BlastoiseMega
12 9 Water NaN 630 79 103 120 135
Blastoise
In [35]: sns.histplot(water_pokemon['Speed'])
plt.show()
(https://getlin
In [41]: water_pokemon.describe()
Out[41]:
# Total HP Attack Defense Sp. Atk Sp.
In [42]: grass_pokemon.describe()
Out[42]:
# Total HP Attack Defense Sp. Atk Sp.
(https://getlin
In [46]: fire_pokemon.describe()
Out[46]:
# Total HP Attack Defense Sp. Atk Sp.
In [47]: water_pokemon.describe()
Out[47]:
# Total HP Attack Defense Sp. Atk Sp.
In [48]: #sp def, sp attack and speed both higher in fire pokemon. mean also hig
#water pokemon loses from fire pokemon
#till now data analysis was done
Out[49]:
Sp. S
# Name Primary_type Secondary_type Total HP Attack Defense
Atk D
VenusaurMega
3 3 Grass Poison 625 80 100 123 122 12
Venusaur
In [50]: poke['Legendary'].value_counts()
In [51]: #if we are comparing 2 features , presense of one fetaure is more than
#non legandary pokemons presence is much more than legandary
65/800
Out[51]: 0.08125
In [54]: x = poke[['Speed']]
y = poke[['Legendary']]
In [55]: #divide data in traning and testing set and predict on test set
#for train and test set use sklearn
from sklearn.model_selection import train_test_split
x_train, x_test,y_train, y_test = train_test_split(x,y,test_size=0.3)
#means 30 % observations in test set rest 70 % training set observat
(https://getlin
Out[57]: DecisionTreeClassifier()
Out[62]: 0.9041666666666667
In [63]: #left diagonal shows correctly classified value and right diagonal show
#so i divide correctly classified values with all classified value so 9
#so implementation of decision tree done
In [ ]:
(https://getlin