def test_with_sparse_code(components=np.loadtxt('components_of_convfeat.txt')): (X_train, y_train), (X_test, y_test) = util.load_feat_vec() X_train_codes = np.loadtxt('sparse_codes_of_convfeat.txt') clf = LogisticRegression(penalty='l1', multi_class='ovr') clf.fit(X_train_codes, y_train) X_test_codes = sparse_encode(X_test, components) print "mean accuracy", clf.score(X_test_codes, y_test)
def selecting_non_zero_coef(): """ No End """ (X_train, y_train), (X_test, y_test) = util.load_feat_vec() print "original X_train shape", X_train.shape X_new = LinearSVC(C=0.01, penalty="l1", dual=False).fit_transform(X_train, y_train) print "selected X_new shape", X_new.shape
def main(): n = 1000 (X_train, y_train), (X_test, y_test) = util.load_feat_vec() digits_proj = TSNE(random_state=130).fit_transform(X_train[:n]) del X_train del X_test del y_test scatter(digits_proj, y_train[:n]) plt.savefig('t-sne_embedding_{}.png'.format(n), dpi=120)
def sparse_logisitic_regression(): """ If convolutional neural network features are highly overfitting. Then we could select features from sparse model. >> mean accuracy 0.352866 """ (X_train, y_train), (X_test, y_test) = util.load_feat_vec() clf = LogisticRegression(penalty='l1', multi_class='ovr') clf.fit(X_train, y_train) print "mean accuracy", clf.score(X_test, y_test)