def heart(dataType): title = '{0} Ada Boost'.format(dataType) package = data.createData(dataType) xTrain = package.xTrain xTest = package.xTest yTrain = package.yTrain yTest = package.yTest param_range = list(range(1, 160, 10)) param = 'n_estimators' params = {'algorithm': 'SAMME.R'} clf = AdaBoostClassifier() clf.set_params(**params) plotter.plotValidationCurve(clf, xTrain, yTrain, param, param_range, graphTitle=title) plotter.plotLearningCurve(clf, title=title, xTrain=xTrain, yTrain=yTrain) title = 'Heart' clf.fit(xTrain, yTrain) plotter.plotConfusion(clf, title, ['Diameter narrowing ', 'Diameter not narrowing'], xTest, yTest)
def heart(dataType): package = data.createData(dataType) xTrain = package.xTrain xTest = package.xTest yTrain = package.yTrain yTest = package.yTest title = '{0} Decision Tree'.format(dataType) xLabel = 'Depth' scoreList = util.ScoreList(xLabel) param_range = list(range(1, 20)) param = 'max_depth' params = { 'class_weight': None, 'criterion': 'entropy', 'max_features': None, 'min_samples_leaf': 10, 'splitter': 'best' } clf_tree = DecisionTreeClassifier(random_state=util.randState) clf_tree.set_params(**params) plotter.plotValidationCurve(clf_tree, xTrain, yTrain, param, param_range, graphTitle=title + ' Max Depth ') plotter.plotLearningCurve(clf_tree, title=title + 'Max Depth', xTrain=xTrain, yTrain=yTrain) clf_tree = DecisionTreeClassifier(random_state=util.randState) clf_tree.set_params(**params) clf_tree.max_depth = 8 param_range = [10, 50, 75, 100] param = 'min_samples_leaf' plotter.plotValidationCurve(clf_tree, xTrain, yTrain, param, param_range, graphTitle=title + ' Min Samples Leaf ') clf_tree.min_samples_leaf = 10 title = 'Heart' # plotter.plotLearningCurve(clf_tree, title=title + 'Min Samples Leaf', xTrain=xTrain, yTrain=yTrain) plotter.plotLearningCurve(clf_tree, title=title, xTrain=xTrain, yTrain=yTrain) clf_tree.fit(xTrain, yTrain) plotter.plotConfusion(clf_tree, title, ['Diameter narrowing ', 'Diameter not narrowing'], xTest, yTest)
def adult(dataType): package = data.createData(dataType) xTrain = package.xTrain xTest = package.xTest yTrain = package.yTrain yTest = package.yTest xLabel = 'Network Layers' scoreList = util.ScoreList(xLabel) title = '{0} Neural Network'.format(dataType) params = { 'activation': 'relu', 'learning_rate': 'adaptive', 'solver': 'sgd' } params = { 'activation': 'relu', 'learning_rate': 'invscaling', 'solver': 'lbfgs' } # params = searcher.searchNetwork(xTrain, yTrain, xTest, yTest) clf = MLPClassifier(max_iter=250) input = package.features.shape[1] input = int(.7 * input) # hiddenLayers = (input, 20) # hiddenLayers = (input,) # param_range = [(input,1,2), (input,2,2),(input,3,2),(input,4,2),(input,5,2),(input,6,2),(input,7,2),(input,8,2),(input,9,2), (input,10,2)] # xRange = [1, 2, 3, 4, 5, 6, 7 , 8, 9, 10] # plotter.plotValidationCurve(clf, xTrain, yTrain, 'hidden_layer_sizes', param_range, title + ' Hidden Layers ', xRange) # clf = MLPClassifier(hidden_layer_sizes = (input,7,2)) # clf.set_params(**params) # param_range = [50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300, 400, 500, 600, 700, 800] # plotter.plotValidationCurve(clf, xTrain, yTrain, 'max_iter', param_range, graphTitle=title + ' Max Iterations ') clf = MLPClassifier(hidden_layer_sizes=(input, 7, 2)) clf.max_iter = 150 plotter.plotLearningCurves(clf, title=title, xTrain=xTrain, yTrain=yTrain) title = 'Adult' clf.fit(xTrain, yTrain) plotter.plotConfusion(clf, title, ['>50K', '<=50K'], xTest, yTest) return
def heart(dataType): package = data.createData(dataType) xTrain = package.xTrain xTest = package.xTest yTrain = package.yTrain yTest = package.yTest xLabel = 'K' scoreList = util.ScoreList(xLabel) title = '{0} KNN'.format(dataType) # searcher.searchKNN(xTrain, yTrain, xTest, yTest) params = {'algorithm': 'auto', 'p': 1, 'weights': 'uniform'} params = {'algorithm': 'ball_tree', 'p': 1, 'weights': 'distance'} # params = searcher.searchKNN(xTrain, yTrain, xTest, yTest) param = 'n_neighbors' param_range = list(range(1, 50)) #np.linspace(1, 50, 50) clf = KNeighborsClassifier() clf.set_params(**params) plotter.plotValidationCurve(clf, xTrain, yTrain, param, param_range, graphTitle=title) clf = KNeighborsClassifier() clf.set_params(**params) clf.n_neighbors = 12 plotter.plotLearningCurve(clf, title=title, xTrain=xTrain, yTrain=yTrain) # plotter.plotAll(clf, title, param, param_range, xTrain, yTrain, xTest, yTest) title = 'Heart' clf.fit(xTrain, yTrain) plotter.plotConfusion(clf, title, ['Diameter narrowing ', 'Diameter not narrowing'], xTest, yTest)
def adult(dataType): package = data.createData(dataType) xTrain = package.xTrain xTest = package.xTest yTrain = package.yTrain yTest = package.yTest xLabel = 'Degrees' title = '{0} SVM'.format(dataType) param_range = list(range(1,8)) # polyparams = searcher.searchSVMPoly(xTrain, yTrain, xTest, yTest) polyparams = {'C': 0.1, 'degree': 1, 'gamma': 50, 'kernel': 'poly'} clf = createBaseSVC() clf.set_params(**polyparams) plotter.plotValidationCurve(clf, xTrain, yTrain, 'degree', param_range, graphTitle=title + ' Poly degree ') clf.degree = 1 plotter.plotLearningCurve(clf, title=title + ' Poly degree ', xTrain=xTrain, yTrain=yTrain) # rbfParams = searcher.searchSVMRBF(xTrain, yTrain, xTest, yTest) rbfParams = {'C': 1000, 'gamma': 0.01, 'kernel': 'rbf'} clf = createBaseSVC() clf.set_params(**rbfParams) param = 'C' # param_range = [0.01,0.05,1,10,50,100,200,300,500, 1000] param_range = [0.01,0.05,1,10,15] plotter.plotValidationCurve(clf, xTrain, yTrain, param, param_range, graphTitle=title+ ' RBF - C ') clf.C = 10 plotter.plotLearningCurve(clf, title=title + ' RBF', xTrain=xTrain, yTrain=yTrain) title = 'Adult' clf.fit(xTrain, yTrain) plotter.plotConfusion(clf, title, ['>50K', '<=50K'], xTest, yTest)
def heart(dataType): package = data.createData(dataType) xTrain = package.xTrain xTest = package.xTest yTrain = package.yTrain yTest = package.yTest title = '{0} SVM'.format(dataType) param_range = list(range(1,8)) # polyparams = searcher.searchSVMPoly(xTrain, yTrain, xTest, yTest) # polyparams = {'kernel': 'poly', 'gamma': 'scale'} polyparams = {'C': 0.01, 'degree': 3, 'gamma': 10, 'kernel': 'poly'} clf = createBaseSVC() clf.set_params(**polyparams) plotter.plotValidationCurve(clf, xTrain, yTrain, 'degree', param_range, graphTitle=title + ' Poly Degree ') clf.degree = 3 plotter.plotLearningCurve(clf, title=title + ' Poly degree ', xTrain=xTrain, yTrain=yTrain) # rbfParams = searcher.searchSVMRBF(xTrain, yTrain, xTest, yTest) rbfParams = {'C': 1, 'gamma': 1, 'kernel': 'rbf'} clf = createBaseSVC() clf.set_params(**rbfParams) param = 'C' param_range = [0.01,0.05,0.25, 0.5, 1] plotter.plotValidationCurve(clf, xTrain, yTrain, param, param_range, graphTitle=title + ' RBF - C ') clf.C = 0.5 plotter.plotLearningCurve(clf, title=title + ' RBF', xTrain=xTrain, yTrain=yTrain) title = 'Heart' clf.fit(xTrain, yTrain) plotter.plotConfusion(clf, title, ['Diameter narrowing ', 'Diameter not narrowing'], xTest, yTest)