Terrorism classification using XGB framework
XGB or XGBoost stands for eXtreme Gradient Boosting. It tries to predict models using a gradient boosting framework. A large number of developers contribute to the XGB open-source. It has nearly 4000 commits on GitHub. Some of the special features of this algorithm are:-
- Solves a variety of problems such as classification, regression, etc.
- Platform independent
- Easily attaches to different cloud services.
- Supports various programming languages such as c,c++, java,python,etc.
The three main forms of gradient boosting which are gradient boosting, Regularised gradient boosting and Stochastic gradient boosting is supported in the XGB algorithm.
It can be easily installed by cloning it from its Github repository.
https://github.com/dmlc/xgboost
Now, let us try to code the classifier into python:
# Write Python3 code here # Importing the libraries import numpy as np import matplotlib.pyplot as plt import pandas as pd # Importing the dataset dataset = pd.read_csv('Churn_Modelling.csv') X = dataset.iloc[:, 3:13].values y = dataset.iloc[:, 13].values # Encoding categorical data from sklearn.preprocessing import LabelEncoder, OneHotEncoder labelencoder_X_1 = LabelEncoder() X[:, 1] = labelencoder_X_1.fit_transform(X[:, 1]) labelencoder_X_2 = LabelEncoder() X[:, 2] = labelencoder_X_2.fit_transform(X[:, 2]) onehotencoder = OneHotEncoder(categorical_features = [1]) X = onehotencoder.fit_transform(X).toarray() X = X[:, 1:] # Splitting the dataset into the Training set and Test set from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split( X, y, test_size = 0.2, random_state = 0) # Fitting XGBoost to the training data import xgboost as xgb my_model = xgb.XGBClassifier() my_model.fit(X_train, y_train) # Predicting the Test set results y_pred = my_model.predict(X_test) # Making the Confusion Matrix from sklearn.metrics import confusion_matrix cm = confusion_matrix(y_test, y_pred)
Output:
Accuracy will be about 0.8645
Implement this algorithm on the Global Terrorism Database(GTD) for the required result.
I hope you would have clearly understood the concept of the XGB classier algorithm. For any classification and suggestions comment down below.
Leave a Reply