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

Replace utility classes with sklearn classes in NB4#30

Merged
rosecers merged 6 commits into
lab-cosmo:masterfrom
PKGuo:sklearnify_NB4
Nov 24, 2020
Merged

Replace utility classes with sklearn classes in NB4#30
rosecers merged 6 commits into
lab-cosmo:masterfrom
PKGuo:sklearnify_NB4

Conversation

@PKGuo

@PKGuo PKGuo commented Nov 18, 2020

Copy link
Copy Markdown
Contributor

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

@rosecers rosecers left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread notebooks/4_SparseKernelMethods.ipynb Outdated
Comment thread notebooks/4_SparseKernelMethods.ipynb Outdated
Comment thread notebooks/4_SparseKernelMethods.ipynb Outdated
Comment thread notebooks/4_SparseKernelMethods.ipynb Outdated
Comment thread notebooks/4_SparseKernelMethods.ipynb Outdated
@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

@rosecers rosecers left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread notebooks/4_SparseKernelMethods.ipynb Outdated
"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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay.

Comment thread notebooks/4_SparseKernelMethods.ipynb Outdated
Comment on lines 77 to 78
"kernel_func = gaussian_kernel\n",
"kernel_type = 'gaussian'"

Copy link
Copy Markdown
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
Copy Markdown
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

Comment thread notebooks/4_SparseKernelMethods.ipynb Outdated
Comment thread notebooks/4_SparseKernelMethods.ipynb Outdated
Comment thread notebooks/4_SparseKernelMethods.ipynb Outdated
Comment thread notebooks/4_SparseKernelMethods.ipynb Outdated
"# 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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment thread notebooks/4_SparseKernelMethods.ipynb
Comment thread notebooks/4_SparseKernelMethods.ipynb
"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",

@PKGuo PKGuo Nov 20, 2020

Copy link
Copy Markdown
Contributor Author

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

@rosecers rosecers left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread notebooks/4_SparseKernelMethods.ipynb Outdated
"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
Copy Markdown
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
Copy Markdown
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!

Comment thread notebooks/4_SparseKernelMethods.ipynb
@PKGuo PKGuo requested a review from rosecers November 24, 2020 09:36

@rosecers rosecers left a comment

Copy link
Copy Markdown
Contributor

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