Skip to content

Instantly share code, notes, and snippets.

@madaan
Created December 24, 2013 17:51
Show Gist options
  • Save madaan/8116195 to your computer and use it in GitHub Desktop.
Save madaan/8116195 to your computer and use it in GitHub Desktop.
KNN with Adaboose
def cvalidate():
from sklearn import cross_validation
trainset = np.genfromtxt(open('train.csv','r'), delimiter=',')[1:]
X = np.array([x[1:8] for x in trainset])
y = np.array([x[8] for x in trainset])
#print X,y
import math
for i, x in enumerate(X):
for j, xx in enumerate(x):
if(math.isnan(xx)):
X[i][j] = 25.6
#print X[0:3]
#print y[0:3]
X_train, X_test, y_train, y_test = cross_validation.train_test_split(X, y, test_size = 0.3, random_state = 0)
X_train, X_test = decomposition_pca(X_train, X_test)
bdt = AdaBoostClassifier(base_estimator = KNeighborsClassifier(n_neighbors=20, algorithm = 'auto'), algorithm="SAMME", n_estimators = 200)
bdt.fit(X_train, y_train)
print bdt.score(X_test, y_test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment