Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend type hints in the classifiers and regressors #159

Open
adekusar-drl opened this issue Jul 13, 2021 · 4 comments
Open

Extend type hints in the classifiers and regressors #159

adekusar-drl opened this issue Jul 13, 2021 · 4 comments
Labels
good first issue Good for newcomers type: discussion 🗣️ General discussions and explanations type: enhancement ✨ Features or aspects to improve
Milestone

Comments

@adekusar-drl
Copy link
Collaborator

What is the expected behavior?

Since we are going to introduce categorical labels (and perhaps categorical features), I think, we can re-consider type hints for the classifiers and regressors and make them more like in Scikit-Learn: array_like. This may allow to pass plain lists or other types. As an example take a look at the interface here: https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html

This issue is just for discussion.

@adekusar-drl adekusar-drl added type: discussion 🗣️ General discussions and explanations priority: low labels Jul 14, 2021
@edoaltamura edoaltamura added good first issue Good for newcomers Changelog: New Feature Include in the Added section of the changelog type: enhancement ✨ Features or aspects to improve and removed priority: low type: discussion 🗣️ General discussions and explanations labels Feb 21, 2024
@edoaltamura edoaltamura self-assigned this Feb 26, 2024
@edoaltamura
Copy link
Collaborator

@adekusar-drl, could you please share an example or template of how you'd match the SKlearn type hinting for QML?

@adekusar-drl
Copy link
Collaborator Author

It has been a low priority for a long time, things might have changed. While scikit learn does not expose type hints by default, one of the possible options to take a look at https://numpy.org/doc/stable/reference/typing.html#module-numpy.typing. Numpy has ArrayLike type hint and it may work. This issue is more exploratory one rather something that can be easily implemented. Even if numpy's hinting is good enough, I'd first double check if such hinting brings in any value, not problems.

@edoaltamura edoaltamura removed their assignment Feb 29, 2024
@edoaltamura edoaltamura added type: discussion 🗣️ General discussions and explanations and removed Changelog: New Feature Include in the Added section of the changelog labels Feb 29, 2024
@edoaltamura
Copy link
Collaborator

For instance

def fit(
self, X: np.ndarray, y: np.ndarray, sample_weight: np.ndarray | None = None
) -> "PegasosQSVC":

would become

import numpy.typing as npt

def fit( 
     self, X: npt.ArrayLike, y: npt.ArrayLike, sample_weight: npt.ArrayLike | None = None 
 ) -> "PegasosQSVC": 

or, more strictly,

import numpy.typing as npt

def fit( 
     self, X: npt.NDArray[np.float64], y: npt.NDArray[np.float64], sample_weight: npt.NDArray[np.float64] | None = None 
 ) -> "PegasosQSVC": 

While young, the new typing in Numpy is covered by tests and CI, and made it into a major release. So I'd consider the basic features relatively stable.

@edoaltamura
Copy link
Collaborator

edoaltamura commented Nov 21, 2024

Mypy can also be configured to account for strongly typed Numpy objects as

[mypy]
plugins = numpy.typing.mypy_plugin

See https://numpy.org/doc/stable/reference/typing.html .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers type: discussion 🗣️ General discussions and explanations type: enhancement ✨ Features or aspects to improve
Projects
None yet
Development

No branches or pull requests

2 participants