from pandas import read_csv
from sklearn.model_selection import KFold
from sklearn.model_selection import cross_val_score
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.svm import SVC
from sklearn.ensemble import VotingClassifier

#Load dataset
file = 'files/pima-indians-diabetes.csv'
names = ['preg', 'plas', 'pres', 'skin', 'test', 'mass', 'pedi', 'age', 'class']
dataframe = read_csv(file, names=names)

#print(dataframe)
array = dataframe.values

X = array[:, 0:8]
Y = array[:, 8]

kfold = KFold(n_splits=10, random_state=None)

#create the sub models

estimators = []
model1 = LogisticRegression(solver='liblinear')
estimators.append(('logisticRegression', model1))

model2 = DecisionTreeClassifier()
estimators.append(('CART', model2))

model3 = SVC(gamma='auto')
estimators.append(('SVC', model3))

#create the ensemble model
ensemble = VotingClassifier(estimators)
results = cross_val_score(ensemble, X, Y, cv=kfold)
print("Mean Estimated Accuracy Ensemble using Voting =", results.mean())