text_plain_output_1.png
from sklearn.ensemble import RandomForestClassifier

from sklearn.feature_selection import SelectKBest, f_classif

from sklearn.naive_bayes import GaussianNB

from sklearn.neighbors import KNeighborsClassifier

import time

k = 15
selector = SelectKBest(score_func=f_classif, k=k)
X_train_selected = selector.fit_transform(X_train, y_train)
X_test_selected = selector.transform(X_test)

from sklearn.neighbors import KNeighborsClassifier
res1 = time.time()
knn = KNeighborsClassifier()
knn = knn.fit(X_train_selected, y_train)
knn
res2 = time.time()

res1 = time.time()
rf = RandomForestClassifier()
rf.fit(X_train_selected, y_train)
res2 = time.time()

from sklearn.naive_bayes import GaussianNB
res1 = time.time()
gnb = GaussianNB()
gnb.fit(X_train_selected, y_train)
res2 = time.time()
print('GNB  took ', res2 - res1, 'seconds')