from numpy import loadtxt
import xgboost as xgb
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score

# load the dataset
dataset = loadtxt('data/pima-indians-diabetes.data.txt', delimiter=',')

# split data into X and Y
X = dataset[:, 0:8]
Y = dataset[:, 8]


# split the data into train and test set
seed = 7
test_size = 0.33
X_train, X_test, y_train, y_test = train_test_split(
    X, Y, test_size=test_size)

# create an empty model and fit the model
model = xgb.XGBClassifier()
model.fit(X_train, y_train)

# this is the model and its default values
# more parameters here: https://xgboost.readthedocs.io/en/latest//parameter.html
print(model)


# predict for the test data
y_pred = model.predict(X_test)
predictions = [round(value) for value in y_pred]

# evaluate the predictions
accuracy = accuracy_score(y_test, predictions)
print(f'Accuracy: {round(accuracy*100.0, 2)}')

# and the important features
print(model.feature_importances_)
