-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprediction.py
More file actions
34 lines (26 loc) · 957 Bytes
/
prediction.py
File metadata and controls
34 lines (26 loc) · 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'''
This is a first playground for XGboost, an implementation of gradient boosting
Which is a subset of ensemble learning.
Here we are experimenting with a binary classifier..
A relatively simple task. but just for the sake of using XGboost
'''
import pandas as pd
import numpy as np
from xgboost import XGBClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
df = pd.read_csv('pima-indians-diabetes.data.txt')
df_array = df.values
X = df_array[:,:8]
y = df_array[:,8]
#Split training to 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, random_state=seed)
model = XGBClassifier()
model.fit(X_train,y_train)
#Make predictions for the test data
y_pred = model.predict(X_test)
predictions = [round(value) for value in y_pred]
accuracy = accuracy_score(y_test,predictions)
print("Accuracy of this model is: ", accuracy)