Skip to content
This repository was archived by the owner on Jan 15, 2026. It is now read-only.

Conversation

@PKGuo
Copy link
Contributor

@PKGuo PKGuo commented Nov 18, 2020

Replace some utility classes in 4_SparseKernelMethods.ipynb with appropriate sklearn classes and modify the corresponding text.

Copy link
Contributor

@rosecers rosecers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make similar changes as in #29 and re-request review.

@PKGuo PKGuo requested a review from rosecers November 18, 2020 15:57
@PKGuo PKGuo changed the title sklearnify NB4 Replace utility classes with sklearn classes in NB4 Nov 18, 2020
Copy link
Contributor

@rosecers rosecers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still argue that we should be using a precomputed kernel across the notebook. Recomputing the kernel with every model will greatly slow down the notebook.

"from utilities.kernels import linear_kernel, gaussian_kernel, center_kernel\n",
"from utilities.classes import KPCA, KRR, SparseKPCA, SparseKRR\n",
"from utilities.classes import KPCovR, SparseKPCovR\n",
"from utilities.kernels import linear_kernel, gaussian_kernel, center_kernel # to be replaced with functions from skcosmo\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can delete this if it is not used elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are used somewhere.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please adapt this like you did in #29. There shouldn't be any kernel-tutorials kernel functions in this notebook. You should use sklearn kernels and centerers from skcosmo (scikit-learn-contrib/scikit-matter#8)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.

Comment on lines 77 to 78
"kernel_func = gaussian_kernel\n",
"kernel_type = 'gaussian'"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these used anywhere? If not, delete.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, they are.
image
image
image

"# Implementation in `skcosmo`\n",
"\n",
"Classes from the utility module enable computing SparseKPCA, SparseKRR, and SparseKPCovR with a scikit.learn-like syntax. `SparseKPCovR` is located in `utilities/kpcovr.py`."
"Classes from the skcosmo module enable computing SparseKPCA, SparseKRR, and SparseKPCovR with a scikit.learn-like syntax. `SparseKPCovR` is located in `skcosmo/PCovR/KPCovR.py`."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not right

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

"ref_kpca.fit(X_train, K=K_train)\n",
"\n",
"table_from_dict([ref_kpca.statistics(X_train, K=K_train), \n",
"ref_kpca = KernelPCA(n_components=n_PC, kernel='rbf',gamma = 1.0, fit_inverse_transform=True)\n",
Copy link
Contributor Author

@PKGuo PKGuo Nov 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment on line 364

@PKGuo PKGuo requested a review from rosecers November 22, 2020 04:45
Copy link
Contributor

@rosecers rosecers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two outstanding questions with respect to kernel definitions.

"kernel_params = {\"kernel\": \"rbf\", \"gamma\": 1.0}\n",
"kernel_func = gaussian_kernel\n",
"kernel_params = {\"kernel\": \"precomputed\"}\n",
"kernel_func = rbf_kernel\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use functools to define

from functools import partial

kernel_func = partial(rbf_kernel, gamma=1.0)

to avoid having to repeat gamma everywhere below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! It works!

@PKGuo PKGuo requested a review from rosecers November 24, 2020 09:36
Copy link
Contributor

@rosecers rosecers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure this runs clean then feel free to merge

@rosecers rosecers merged commit eb2c2bf into lab-cosmo:master Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants