Beispiel #1
0
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)
Beispiel #2
0
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)
Beispiel #3
0
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)
Beispiel #4
0
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)
Beispiel #5
0
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)