import pandas as pd from common.class_vis import prettyPicture from common.prep_terrain_data import makeTerrainData from save_fig import save_fig from sklearn.tree import DecisionTreeClassifier from sklearn.metrics import roc_curve from sklearn.metrics import accuracy_score from sklearn.metrics import confusion_matrix from sklearn.metrics import classification_report from sklearn.model_selection import cross_val_score from sklearn.model_selection import GridSearchCV from matplotlib import pyplot as plt # create data X, y, features_train, labels_train, features_test, labels_test = makeTerrainData( ) # define classification clf = DecisionTreeClassifier(max_depth=2) name = 'max_depth 2' # fit train data clf.fit(features_train, labels_train) # predict train and test pred_train = clf.predict(features_train) pred_test = clf.predict(features_test) # calculate accuracy accuracy_test = accuracy_score(labels_test, pred_test) accuracy_train = accuracy_score(labels_train, pred_train)
""" import pandas as pd from sklearn import datasets from sklearn.svm import SVC from sklearn.tree import DecisionTreeClassifier from sklearn.model_selection import train_test_split from sklearn.model_selection import cross_val_score from sklearn.model_selection import GridSearchCV from sklearn.model_selection import RandomizedSearchCV from common.prep_terrain_data import makeTerrainData # create data features, labels, features_train_data, labels_train_data, features_test_data, labels_test_data = makeTerrainData( ) # # load data # iris = datasets.load_iris() # features = iris.data # labels = iris.target # split data features_train, features_test, labels_train, labels_test = train_test_split( features, labels, test_size=0.4, random_state=0) # SVC classifier clf = SVC(kernel="linear", C=1.) clf.fit(features_train, labels_train) print(clf.score(features_test, labels_test))