I'm studying the following code, which
cross_val_score_ was used as well as
.std(). I read many documentation of the meanings, but didn't get what each of the above does.
import pandas as pd import numpy as np from sklearn import tree import graphviz from sklearn.model_selection import cross_val_score #importing the dataset d = pd.read_csv('student-por.csv', sep= ';') d['pass'] = d.apply(lambda row: 1 if (row['G1']+ row['G2']+ row ['G3']) >= 35 else 0 , axis=1) d = d.drop(['G1', 'G2','G3'], axis=1 ) #Doing one-hot encoding d=pd.get_dummies(d, columns =['sex','activities','school', 'address', 'famsize','Pstatus','Mjob','Fjob','reason','guardian','schoolsup','famsup','paid','nursery','higher','internet','romantic']) #shuffle rows d = d.sample(frac=1) #split traning and test d_train = d[:500] d_test = d[500:] d_train_att = d_train.drop(['pass'], axis=1) d_train_pass= d_train['pass'] d_test_att = d_test.drop(['pass'], axis=1) d_test_pass= d_test['pass'] d_att = d.drop(['pass'], axis=1) d_pass = d['pass'] t = tree.DecisionTreeClassifier(criterion ='entropy', max_depth = 5) t= t.fit (d_train_att, d_train_pass) #to export the tree dot_data = tree.export_graphviz(t,out_file = 'students-tree.png', label ='all', impurity=False, proportion= True, feature_names=list(d_train_att), class_names=['fail', 'pass'], filled = True, rounded=True) t.score (d_test_att, d_test_pass) scores = cross_val_score(t, d_att,d_pass, cv=5) print ('Acuracy %0.2f (+/- %0.2f)' % (scores.mean(), scores.std() *2))
in short this is what I need to know:
scores = cross_val_score(t, d_att,d_pass, cv=5) print ('Acuracy %0.2f (+/- %0.2f)' % (scores.mean(), scores.std() *2))
one more thing, am I suppose to get the same score as in the original code publisher? because I didn't.