"""
XGBoost test on churn modeling data.

INSTALL:

1. brew install gcc
2. git clone --recursive https://github.com/dmlc/xgboost
3. cd xgboost
4. ./build.sh
5. cd python-package
6. python3 setup.py install
"""
import pandas as pd
from sklearn.metrics import confusion_matrix
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
from xgboost import XGBClassifier

df = pd.read_csv('./../../data/churn.modeling.csv')
X = df.iloc[:, 3:13].values
y = df.iloc[:, 13].values

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:]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
print("X shape / y shape: ", X.shape, y.shape)
print("X train / X test shape: ", X_train.shape, X_test.shape)
print("y train / y test shape: ", y_train.shape, y_test.shape)

classifier = XGBClassifier()
classifier.fit(X_train, y_train)
y_pred = classifier.predict(X_test)
cm = confusion_matrix(y_test, y_pred)
print("Confusion matrix:\n", cm)

accuracies = cross_val_score(estimator=classifier, X=X_train, y=y_train, cv=10)
print("Accuracy mean: ", accuracies.mean())
print("Accuracy standard deviation: ", accuracies.std())

"""
XGBoost test on churn modeling data.

INSTALL:

1. brew install gcc
2. git clone --recursive https://github.com/dmlc/xgboost
3. cd xgboost
4. ./build.sh
5. cd python-package
6. python3 setup.py install
"""
import pandas as pd
from sklearn.metrics import confusion_matrix
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
from xgboost import XGBClassifier

df = pd.read_csv('./../../data/churn.modeling.csv')
X = df.iloc[:, 3:13].values
y = df.iloc[:, 13].values

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:]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
print("X shape / y shape: ", X.shape, y.shape)
print("X train / X test shape: ", X_train.shape, X_test.shape)
print("y train / y test shape: ", y_train.shape, y_test.shape)

classifier = XGBClassifier()
classifier.fit(X_train, y_train)
y_pred = classifier.predict(X_test)
cm = confusion_matrix(y_test, y_pred)
print("Confusion matrix:\n", cm)

accuracies = cross_val_score(estimator=classifier, X=X_train, y=y_train, cv=10)
print("Accuracy mean: ", accuracies.mean())
print("Accuracy standard deviation: ", accuracies.std())

XGBoost test on churn modeling data.  INSTALL:  1. brew install gcc 2. git clone --recursive https://github.com/dmlc/xgboost 3. cd xgboost 4. ./build.sh 5. cd python-package 6. python3 setup.py install