Created
July 6, 2019 05:02
-
-
Save xeb/e41cd60a4980576d83f5dce387f24755 to your computer and use it in GitHub Desktop.
XGBoost Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#!pip install sklearn xgboost | |
#!wget https://raw.githubusercontent.com/jbrownlee/Datasets/master/pima-indians-diabetes.data.csv | |
from numpy import loadtxt | |
from xgboost import XGBClassifier | |
from sklearn.model_selection import train_test_split | |
from sklearn.metrics import accuracy_score | |
import pprint | |
pp = pprint.PrettyPrinter(indent=4) | |
dataset = loadtxt('pima-indians-diabetes.data.csv', delimiter=",") | |
pp.pprint(dataset[0]) | |
X = dataset[:,0:8] | |
Y = dataset[:,8] | |
print("X == ") | |
pp.pprint(X[0]) | |
print("Y == ") | |
pp.pprint(Y[0]) | |
seed = 7 | |
test_size = 0.33 | |
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=test_size, random_state=seed) | |
model = XGBClassifier() | |
model.fit(X_train, y_train) | |
pp.pprint(model) | |
print("Making predictions") | |
y_pred = model.predict(X_test) | |
predictions = [round(value) for value in y_pred] | |
accuracy = accuracy_score(y_test, predictions) | |
print("Accuracy: %.2f%%" % (accuracy * 100.0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment