Skip to content

Commit

Permalink
Kernel Pca implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
LordSomen committed Aug 6, 2018
1 parent 85af583 commit 7bd4e2e
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion dimension_reduction/dimension_red.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,30 @@

#%%
rnd_pca = PCA(n_components=154, svd_solver="randomized")
X_reduced = rnd_pca.fit_transform(X)
X_reduced = rnd_pca.fit_transform(X)

#%%
from sklearn.decomposition import KernelPCA
rbf_pca = KernelPCA(n_components = 2, kernel="rbf", gamma=0.02)
X_reduced = rbf_pca.fit_transform(X)

#%%
from sklearn.model_selection import GridSearchCV
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import Pipeline
clf = Pipeline([
("kpca", KernelPCA(n_components=2)),
("log_reg", LogisticRegression())
])
param_grid = [{
"kpca__gamma": np.linspace(0.03, 0.05, 10),
"kpca__kernel": ["rbf", "sigmoid"]
}]
grid_search = GridSearchCV(clf, param_grid, cv=3)
grid_search.fit(X, Y)

#%%
rbf_pca = KernelPCA(n_components = 2, kernel="rbf", gamma=0.0433,
fit_inverse_transform=True)
X_reduced = rbf_pca.fit_transform(X)
X_preimage = rbf_pca.inverse_transform(X_reduced)

0 comments on commit 7bd4e2e

Please sign in to comment.