# Classifying Threat using Extra Tree Classifier

Extra Tree Classifier is a type of machine learning algorithm which is closely related to the decision tree algorithm. It collects the result of various decision trees into a forest to print the final result.

The extra tree in this algorithm is created by the original training dataset. Then the tree is given a random sample of features from the set. Here the tree selects the best feature to split the data on the basis of some mathematical method. This process creates many correlated decision trees.

Now let us try to implement the extra tree classifier algorithm in python.

• Import libraries
```import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.ensemble import ExtraTreesClassifier
```
• Clean the Data
```# Changing the working location to the location of the file
cd C:\Users\Dev\Desktop\Kaggle

# Seperating the dependent and independent variables
y = df['Play Tennis']
X = df.drop('Play Tennis', axis = 1)

```
• Build The extra tree
```# Building the model
extra_tree_forest = ExtraTreesClassifier(n_estimators = 5, criterion ='entropy', max_features = 2)

# Training the model
extra_tree_forest.fit(X, y)

# Computing the importance of each feature
feature_importance = extra_tree_forest.feature_importances_

# Normalizing the individual importances
feature_importance_normalized = np.std([tree.feature_importances_ for tree in extra_tree_forest.estimators_], axis = 0)
```
• Plotting the result
```# Plotting a Bar Graph to compare the models
plt.bar(X.columns, feature_importance_normalized)
plt.xlabel('Feature Labels')
plt.ylabel('Feature Importances')
plt.title('Comparison of different Feature Importances')
plt.show()
```

The above figure clearly states the result according to the extra tree algorithm.

Implement this algorithm on the Global Terrorism Database(GTD) for the required result.

I hope you have clearly understood the concept of the extra tree classifier algorithm. For any clarifications and suggestions comment down below.