Skip to content

Instantly share code, notes, and snippets.

@madaan
Created December 13, 2013 16:52
Show Gist options
  • Save madaan/7947316 to your computer and use it in GitHub Desktop.
Save madaan/7947316 to your computer and use it in GitHub Desktop.
Using svm as a weak learner for Adaboost. Working edition.
def main():
targetset = np.genfromtxt(open('trainLabels.csv','r'), dtype='f16')
target = [x for x in targetset]
trainset = np.genfromtxt(open('train.csv','r'), delimiter=',', dtype='f16')
train = np.array([x for x in trainset])
testset = np.genfromtxt(open('test.csv','r'), delimiter = ',', dtype='f16')
train, testset = decomposition_pca(train, testset)
#bdt = AdaBoostClassifier(DecisionTreeClassifier(max_depth=10),
# algorithm="SAMME",
# n_estimators=200)
parameters = {'kernel':('linear', 'rbf'), 'C':[1, 10]}
c_range = 10.0 ** np.arange(6.5,7.5,.25)
gamma_range = 10.0 ** np.arange(-2.5,0.5,.25)
parameters = {'kernel':['rbf'], 'C':c_range, 'gamma':gamma_range}
svr = SVC(probability=True)
clf = grid_search.GridSearchCV(svr, parameters)
clf.fit(train, target)
bdt = AdaBoostClassifier(base_estimator = clf.best_estimator_,
algorithm="SAMME",
n_estimators=200)
bdt.fit(train, target)
print 'Id,Solution'
for i, t in enumerate(testset):
print '%d,%d' % (i + 1, int(bdt.predict(t)[0]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment