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

1.0.1 candidate has changes (many previously published elsehwere) for #93

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def main():
],
url='https://github.com/nok/sklearn-porter',
install_requires=[
'scikit-learn>=0.17,<=0.22a0',
'scikit-learn>=1.5',
'jinja2>=2.11',
'joblib>=1',
'loguru>=0.5',
Expand Down
32 changes: 16 additions & 16 deletions sklearn_porter/Estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def _load_est(estimator):

# Classifiers:
if name == 'DecisionTreeClassifier':
from sklearn.tree.tree import (
from sklearn.tree import (
DecisionTreeClassifier as DecisionTreeClassifierClass,
)

Expand All @@ -382,7 +382,7 @@ def _load_est(estimator):

return DecisionTreeClassifier(est)
elif name == 'AdaBoostClassifier':
from sklearn.ensemble.weight_boosting import (
from sklearn.ensemble import (
AdaBoostClassifier as AdaBoostClassifierClass,
)

Expand All @@ -393,7 +393,7 @@ def _load_est(estimator):

return AdaBoostClassifier(est)
elif name == 'RandomForestClassifier':
from sklearn.ensemble.forest import (
from sklearn.ensemble import (
RandomForestClassifier as RandomForestClassifierClass,
)

Expand All @@ -404,7 +404,7 @@ def _load_est(estimator):

return RandomForestClassifier(est)
elif name == 'ExtraTreesClassifier':
from sklearn.ensemble.forest import (
from sklearn.ensemble import (
ExtraTreesClassifier as ExtraTreesClassifierClass,
)

Expand Down Expand Up @@ -462,7 +462,7 @@ def _load_est(estimator):
return BernoulliNB(est)
elif name == 'MLPClassifier':
try:
from sklearn.neural_network.multilayer_perceptron import (
from sklearn.neural_network import (
MLPClassifier as MLPClassifierClass,
)
except ImportError:
Expand All @@ -480,7 +480,7 @@ def _load_est(estimator):
# Regressors:
elif name == 'MLPRegressor':
try:
from sklearn.neural_network.multilayer_perceptron import (
from sklearn.neural_network import (
MLPRegressor as MLPRegressorClass,
)
except ImportError:
Expand Down Expand Up @@ -851,14 +851,14 @@ def classifiers() -> Tuple:
"""

# scikit-learn version < 0.18.0
from sklearn.tree.tree import DecisionTreeClassifier
from sklearn.ensemble.weight_boosting import AdaBoostClassifier
from sklearn.ensemble.forest import RandomForestClassifier
from sklearn.ensemble.forest import ExtraTreesClassifier
from sklearn.svm.classes import LinearSVC
from sklearn.svm.classes import SVC
from sklearn.svm.classes import NuSVC
from sklearn.neighbors.classification import KNeighborsClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import AdaBoostClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.ensemble import ExtraTreesClassifier
from sklearn.svm import LinearSVC
from sklearn.svm import SVC
from sklearn.svm import NuSVC
from sklearn.neighbors import KNeighborsClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.naive_bayes import BernoulliNB

Expand All @@ -877,7 +877,7 @@ def classifiers() -> Tuple:

# scikit-learn version >= 0.18.0
try:
from sklearn.neural_network.multilayer_perceptron import (
from sklearn.neural_network import (
MLPClassifier,
)
except ImportError:
Expand All @@ -903,7 +903,7 @@ def regressors() -> Tuple:

# scikit-learn version >= 0.18.0
try:
from sklearn.neural_network.multilayer_perceptron import (
from sklearn.neural_network import (
MLPRegressor,
)
except ImportError:
Expand Down
2 changes: 1 addition & 1 deletion sklearn_porter/__version__.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
1.0.1
7 changes: 4 additions & 3 deletions sklearn_porter/estimator/DecisionTreeClassifier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from loguru import logger as L

# scikit-learn
from sklearn.tree.tree import \
from sklearn.tree import \
DecisionTreeClassifier as DecisionTreeClassifierClass

# sklearn-porter
Expand Down Expand Up @@ -67,14 +67,15 @@ def __init__(self, estimator: DecisionTreeClassifierClass):

# Is the estimator fitted?
try:
getattr(est, 'n_features_') # for sklearn > 0.19
getattr(est, 'n_features_in_') # for sklearn >= 1.50
#getattr(est, 'n_features_') # for sklearn > 0.19
getattr(est.tree_, 'value') # for sklearn <= 0.18
except AttributeError:
raise exception.NotFittedEstimatorError(self.estimator_name)

# Extract and save meta information:
self.meta_info = dict(
n_features=est.n_features_,
n_features=est.n_features_in_,
n_classes=len(est.tree_.value.tolist()[0][0]),
)
L.info('Meta info (keys): {}'.format(self.meta_info.keys()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void predict_proba(double *result, double features[N_FEATURES], int node) {
}
}

#ifdef STANDALONE
int main(int argc, const char *argv[]) {

/* Features: */
Expand Down Expand Up @@ -98,4 +99,5 @@ int main(int argc, const char *argv[]) {

return 0;
}
{% endblock %}
#endif
{% endblock %}