Showing posts with label 【PYTHON】split train test. Show all posts
Showing posts with label 【PYTHON】split train test. Show all posts

Tuesday, May 25, 2021

【PYTHON】split train test

 from pandas import read_csv

from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression

filename = 'pima-indians-diabetes.csv'
#url = 'https://myfilecsv.com/test.csv'
names = ['preg', 'plas', 'pres', 'skin', 'test', 'mass', 'pedi', 'age', 'class']
dataframe = read_csv(filename, names=names)

array = dataframe.values

#splitting the array to input and output
X = array[:,0:8]
Y = array[:,8]

test_size = 0.33
seed = 7
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=test_size, random_state=seed)

model = LogisticRegression(solver='liblinear')
model.fit(X_train, Y_train)

result = model.score(X_test, Y_test)
print("Accuracy: %.3f%%" % (result*100.0))