def datly(): # import features_train, labels_train, features_test, labels_test = makeTerrainData( ) def plotly(grade_fast, bumpy_fast, grade_slow, bumpy_slow): plt.xlim(0.0, 1.0) plt.ylim(0.0, 1.0) plt.scatter(bumpy_fast, grade_fast, color="b", label="fast") plt.scatter(grade_slow, bumpy_slow, color="r", label="slow") plt.legend() plt.xlabel("bumpiness") plt.ylabel("grade") plt.show() def composite(): # обучающие данные (features_train, labels_train) # имеют как "быстрый", так и " медленный" точки смешиваются # вместе-разделите их, чтобы мы могли дать им разные цвета # в диаграмме рассеяния и определить их визуально grade_fast = [ features_train[ii][0] for ii in range(0, len(features_train)) if labels_train[ii] == 0 ] bumpy_fast = [ features_train[ii][1] for ii in range(0, len(features_train)) if labels_train[ii] == 0 ] grade_slow = [ features_train[ii][0] for ii in range(0, len(features_train)) if labels_train[ii] == 1 ] bumpy_slow = [ features_train[ii][1] for ii in range(0, len(features_train)) if labels_train[ii] == 1 ] plt = plotly(grade_fast, bumpy_fast, grade_slow, bumpy_slow) return features_train, labels_train, features_test, labels_test, plt
from os import path import sys sys.path.append(path.dirname(path.dirname(path.abspath(__file__)))) from choose_your_own.class_vis import prettyPicture, output_image from choose_your_own.prep_terrain_data import makeTerrainData import matplotlib.pyplot as plt import numpy as np import pylab as pl features_train, labels_train, features_test, labels_test = makeTerrainData() ################################################################################# ########################## DECISION TREE ################################# # create/fit the classifier from sklearn import tree clf2 = tree.DecisionTreeClassifier(min_samples_split=2) clf2.fit(features_train, labels_train) clf50 = tree.DecisionTreeClassifier(min_samples_split=50) clf50.fit(features_train, labels_train) # preds pred2 = clf2.predict(features_test) pred50 = clf50.predict(features_test) #prettyPicture(clf, features_test, labels_test) #plt.show()