snowflake-ml-python 1.4.0__py3-none-any.whl → 1.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- snowflake/ml/_internal/env_utils.py +77 -32
- snowflake/ml/_internal/exceptions/dataset_error_messages.py +5 -0
- snowflake/ml/_internal/exceptions/dataset_errors.py +24 -0
- snowflake/ml/_internal/exceptions/error_codes.py +3 -0
- snowflake/ml/_internal/lineage/data_source.py +10 -0
- snowflake/ml/_internal/lineage/dataset_dataframe.py +44 -0
- snowflake/ml/_internal/utils/identifier.py +3 -1
- snowflake/ml/_internal/utils/sql_identifier.py +2 -6
- snowflake/ml/dataset/__init__.py +10 -0
- snowflake/ml/dataset/dataset.py +454 -129
- snowflake/ml/dataset/dataset_factory.py +53 -0
- snowflake/ml/dataset/dataset_metadata.py +103 -0
- snowflake/ml/dataset/dataset_reader.py +202 -0
- snowflake/ml/feature_store/feature_store.py +531 -332
- snowflake/ml/feature_store/feature_view.py +40 -23
- snowflake/ml/fileset/embedded_stage_fs.py +146 -0
- snowflake/ml/fileset/sfcfs.py +56 -54
- snowflake/ml/fileset/snowfs.py +159 -0
- snowflake/ml/fileset/stage_fs.py +49 -17
- snowflake/ml/model/__init__.py +2 -2
- snowflake/ml/model/_api.py +16 -1
- snowflake/ml/model/_client/model/model_impl.py +27 -0
- snowflake/ml/model/_client/model/model_version_impl.py +137 -50
- snowflake/ml/model/_client/ops/model_ops.py +159 -40
- snowflake/ml/model/_client/sql/model.py +25 -2
- snowflake/ml/model/_client/sql/model_version.py +131 -2
- snowflake/ml/model/_deploy_client/image_builds/server_image_builder.py +5 -1
- snowflake/ml/model/_deploy_client/image_builds/templates/dockerfile_template +1 -0
- snowflake/ml/model/_deploy_client/snowservice/deploy.py +2 -0
- snowflake/ml/model/_deploy_client/utils/constants.py +0 -5
- snowflake/ml/model/_deploy_client/utils/snowservice_client.py +21 -50
- snowflake/ml/model/_model_composer/model_composer.py +22 -1
- snowflake/ml/model/_model_composer/model_manifest/model_manifest.py +38 -51
- snowflake/ml/model/_model_composer/model_manifest/model_manifest_schema.py +19 -1
- snowflake/ml/model/_model_composer/model_method/model_method.py +6 -10
- snowflake/ml/model/_packager/model_env/model_env.py +41 -0
- snowflake/ml/model/_packager/model_handlers/catboost.py +206 -0
- snowflake/ml/model/_packager/model_handlers/lightgbm.py +218 -0
- snowflake/ml/model/_packager/model_handlers/sklearn.py +3 -0
- snowflake/ml/model/_packager/model_meta/_core_requirements.py +1 -1
- snowflake/ml/model/_packager/model_meta/model_meta.py +37 -11
- snowflake/ml/model/_packager/model_meta/model_meta_schema.py +20 -1
- snowflake/ml/model/_packager/model_meta_migrator/migrator_plans.py +3 -1
- snowflake/ml/model/_packager/model_packager.py +2 -5
- snowflake/ml/model/{_model_composer/model_runtime/_runtime_requirements.py → _packager/model_runtime/_snowml_inference_alternative_requirements.py} +1 -1
- snowflake/ml/model/_packager/model_runtime/model_runtime.py +137 -0
- snowflake/ml/model/type_hints.py +21 -2
- snowflake/ml/modeling/_internal/estimator_utils.py +16 -11
- snowflake/ml/modeling/_internal/local_implementations/pandas_handlers.py +4 -1
- snowflake/ml/modeling/_internal/local_implementations/pandas_trainer.py +55 -3
- snowflake/ml/modeling/_internal/ml_runtime_implementations/ml_runtime_handlers.py +34 -18
- snowflake/ml/modeling/_internal/model_trainer.py +7 -0
- snowflake/ml/modeling/_internal/model_trainer_builder.py +42 -9
- snowflake/ml/modeling/_internal/snowpark_implementations/distributed_hpo_trainer.py +13 -14
- snowflake/ml/modeling/_internal/snowpark_implementations/snowpark_handlers.py +29 -7
- snowflake/ml/modeling/_internal/snowpark_implementations/snowpark_trainer.py +261 -16
- snowflake/ml/modeling/calibration/calibrated_classifier_cv.py +246 -175
- snowflake/ml/modeling/cluster/affinity_propagation.py +246 -175
- snowflake/ml/modeling/cluster/agglomerative_clustering.py +246 -175
- snowflake/ml/modeling/cluster/birch.py +248 -175
- snowflake/ml/modeling/cluster/bisecting_k_means.py +248 -175
- snowflake/ml/modeling/cluster/dbscan.py +246 -175
- snowflake/ml/modeling/cluster/feature_agglomeration.py +248 -175
- snowflake/ml/modeling/cluster/k_means.py +248 -175
- snowflake/ml/modeling/cluster/mean_shift.py +246 -175
- snowflake/ml/modeling/cluster/mini_batch_k_means.py +248 -175
- snowflake/ml/modeling/cluster/optics.py +246 -175
- snowflake/ml/modeling/cluster/spectral_biclustering.py +246 -175
- snowflake/ml/modeling/cluster/spectral_clustering.py +246 -175
- snowflake/ml/modeling/cluster/spectral_coclustering.py +246 -175
- snowflake/ml/modeling/compose/column_transformer.py +248 -175
- snowflake/ml/modeling/compose/transformed_target_regressor.py +246 -175
- snowflake/ml/modeling/covariance/elliptic_envelope.py +246 -175
- snowflake/ml/modeling/covariance/empirical_covariance.py +246 -175
- snowflake/ml/modeling/covariance/graphical_lasso.py +246 -175
- snowflake/ml/modeling/covariance/graphical_lasso_cv.py +246 -175
- snowflake/ml/modeling/covariance/ledoit_wolf.py +246 -175
- snowflake/ml/modeling/covariance/min_cov_det.py +246 -175
- snowflake/ml/modeling/covariance/oas.py +246 -175
- snowflake/ml/modeling/covariance/shrunk_covariance.py +246 -175
- snowflake/ml/modeling/decomposition/dictionary_learning.py +248 -175
- snowflake/ml/modeling/decomposition/factor_analysis.py +248 -175
- snowflake/ml/modeling/decomposition/fast_ica.py +248 -175
- snowflake/ml/modeling/decomposition/incremental_pca.py +248 -175
- snowflake/ml/modeling/decomposition/kernel_pca.py +248 -175
- snowflake/ml/modeling/decomposition/mini_batch_dictionary_learning.py +248 -175
- snowflake/ml/modeling/decomposition/mini_batch_sparse_pca.py +248 -175
- snowflake/ml/modeling/decomposition/pca.py +248 -175
- snowflake/ml/modeling/decomposition/sparse_pca.py +248 -175
- snowflake/ml/modeling/decomposition/truncated_svd.py +248 -175
- snowflake/ml/modeling/discriminant_analysis/linear_discriminant_analysis.py +248 -175
- snowflake/ml/modeling/discriminant_analysis/quadratic_discriminant_analysis.py +246 -175
- snowflake/ml/modeling/ensemble/ada_boost_classifier.py +246 -175
- snowflake/ml/modeling/ensemble/ada_boost_regressor.py +246 -175
- snowflake/ml/modeling/ensemble/bagging_classifier.py +246 -175
- snowflake/ml/modeling/ensemble/bagging_regressor.py +246 -175
- snowflake/ml/modeling/ensemble/extra_trees_classifier.py +246 -175
- snowflake/ml/modeling/ensemble/extra_trees_regressor.py +246 -175
- snowflake/ml/modeling/ensemble/gradient_boosting_classifier.py +246 -175
- snowflake/ml/modeling/ensemble/gradient_boosting_regressor.py +246 -175
- snowflake/ml/modeling/ensemble/hist_gradient_boosting_classifier.py +246 -175
- snowflake/ml/modeling/ensemble/hist_gradient_boosting_regressor.py +246 -175
- snowflake/ml/modeling/ensemble/isolation_forest.py +246 -175
- snowflake/ml/modeling/ensemble/random_forest_classifier.py +246 -175
- snowflake/ml/modeling/ensemble/random_forest_regressor.py +246 -175
- snowflake/ml/modeling/ensemble/stacking_regressor.py +248 -175
- snowflake/ml/modeling/ensemble/voting_classifier.py +248 -175
- snowflake/ml/modeling/ensemble/voting_regressor.py +248 -175
- snowflake/ml/modeling/feature_selection/generic_univariate_select.py +248 -175
- snowflake/ml/modeling/feature_selection/select_fdr.py +248 -175
- snowflake/ml/modeling/feature_selection/select_fpr.py +248 -175
- snowflake/ml/modeling/feature_selection/select_fwe.py +248 -175
- snowflake/ml/modeling/feature_selection/select_k_best.py +248 -175
- snowflake/ml/modeling/feature_selection/select_percentile.py +248 -175
- snowflake/ml/modeling/feature_selection/sequential_feature_selector.py +248 -175
- snowflake/ml/modeling/feature_selection/variance_threshold.py +248 -175
- snowflake/ml/modeling/framework/_utils.py +8 -1
- snowflake/ml/modeling/framework/base.py +72 -37
- snowflake/ml/modeling/gaussian_process/gaussian_process_classifier.py +246 -175
- snowflake/ml/modeling/gaussian_process/gaussian_process_regressor.py +246 -175
- snowflake/ml/modeling/impute/iterative_imputer.py +248 -175
- snowflake/ml/modeling/impute/knn_imputer.py +248 -175
- snowflake/ml/modeling/impute/missing_indicator.py +248 -175
- snowflake/ml/modeling/kernel_approximation/additive_chi2_sampler.py +248 -175
- snowflake/ml/modeling/kernel_approximation/nystroem.py +248 -175
- snowflake/ml/modeling/kernel_approximation/polynomial_count_sketch.py +248 -175
- snowflake/ml/modeling/kernel_approximation/rbf_sampler.py +248 -175
- snowflake/ml/modeling/kernel_approximation/skewed_chi2_sampler.py +248 -175
- snowflake/ml/modeling/kernel_ridge/kernel_ridge.py +246 -175
- snowflake/ml/modeling/lightgbm/lgbm_classifier.py +246 -175
- snowflake/ml/modeling/lightgbm/lgbm_regressor.py +246 -175
- snowflake/ml/modeling/linear_model/ard_regression.py +246 -175
- snowflake/ml/modeling/linear_model/bayesian_ridge.py +246 -175
- snowflake/ml/modeling/linear_model/elastic_net.py +246 -175
- snowflake/ml/modeling/linear_model/elastic_net_cv.py +246 -175
- snowflake/ml/modeling/linear_model/gamma_regressor.py +246 -175
- snowflake/ml/modeling/linear_model/huber_regressor.py +246 -175
- snowflake/ml/modeling/linear_model/lars.py +246 -175
- snowflake/ml/modeling/linear_model/lars_cv.py +246 -175
- snowflake/ml/modeling/linear_model/lasso.py +246 -175
- snowflake/ml/modeling/linear_model/lasso_cv.py +246 -175
- snowflake/ml/modeling/linear_model/lasso_lars.py +246 -175
- snowflake/ml/modeling/linear_model/lasso_lars_cv.py +246 -175
- snowflake/ml/modeling/linear_model/lasso_lars_ic.py +246 -175
- snowflake/ml/modeling/linear_model/linear_regression.py +246 -175
- snowflake/ml/modeling/linear_model/logistic_regression.py +246 -175
- snowflake/ml/modeling/linear_model/logistic_regression_cv.py +246 -175
- snowflake/ml/modeling/linear_model/multi_task_elastic_net.py +246 -175
- snowflake/ml/modeling/linear_model/multi_task_elastic_net_cv.py +246 -175
- snowflake/ml/modeling/linear_model/multi_task_lasso.py +246 -175
- snowflake/ml/modeling/linear_model/multi_task_lasso_cv.py +246 -175
- snowflake/ml/modeling/linear_model/orthogonal_matching_pursuit.py +246 -175
- snowflake/ml/modeling/linear_model/passive_aggressive_classifier.py +246 -175
- snowflake/ml/modeling/linear_model/passive_aggressive_regressor.py +246 -175
- snowflake/ml/modeling/linear_model/perceptron.py +246 -175
- snowflake/ml/modeling/linear_model/poisson_regressor.py +246 -175
- snowflake/ml/modeling/linear_model/ransac_regressor.py +246 -175
- snowflake/ml/modeling/linear_model/ridge.py +246 -175
- snowflake/ml/modeling/linear_model/ridge_classifier.py +246 -175
- snowflake/ml/modeling/linear_model/ridge_classifier_cv.py +246 -175
- snowflake/ml/modeling/linear_model/ridge_cv.py +246 -175
- snowflake/ml/modeling/linear_model/sgd_classifier.py +246 -175
- snowflake/ml/modeling/linear_model/sgd_one_class_svm.py +246 -175
- snowflake/ml/modeling/linear_model/sgd_regressor.py +246 -175
- snowflake/ml/modeling/linear_model/theil_sen_regressor.py +246 -175
- snowflake/ml/modeling/linear_model/tweedie_regressor.py +246 -175
- snowflake/ml/modeling/manifold/isomap.py +248 -175
- snowflake/ml/modeling/manifold/mds.py +248 -175
- snowflake/ml/modeling/manifold/spectral_embedding.py +248 -175
- snowflake/ml/modeling/manifold/tsne.py +248 -175
- snowflake/ml/modeling/mixture/bayesian_gaussian_mixture.py +246 -175
- snowflake/ml/modeling/mixture/gaussian_mixture.py +246 -175
- snowflake/ml/modeling/model_selection/grid_search_cv.py +63 -41
- snowflake/ml/modeling/model_selection/randomized_search_cv.py +80 -38
- snowflake/ml/modeling/multiclass/one_vs_one_classifier.py +246 -175
- snowflake/ml/modeling/multiclass/one_vs_rest_classifier.py +246 -175
- snowflake/ml/modeling/multiclass/output_code_classifier.py +246 -175
- snowflake/ml/modeling/naive_bayes/bernoulli_nb.py +246 -175
- snowflake/ml/modeling/naive_bayes/categorical_nb.py +246 -175
- snowflake/ml/modeling/naive_bayes/complement_nb.py +246 -175
- snowflake/ml/modeling/naive_bayes/gaussian_nb.py +246 -175
- snowflake/ml/modeling/naive_bayes/multinomial_nb.py +246 -175
- snowflake/ml/modeling/neighbors/k_neighbors_classifier.py +246 -175
- snowflake/ml/modeling/neighbors/k_neighbors_regressor.py +246 -175
- snowflake/ml/modeling/neighbors/kernel_density.py +246 -175
- snowflake/ml/modeling/neighbors/local_outlier_factor.py +246 -175
- snowflake/ml/modeling/neighbors/nearest_centroid.py +246 -175
- snowflake/ml/modeling/neighbors/nearest_neighbors.py +246 -175
- snowflake/ml/modeling/neighbors/neighborhood_components_analysis.py +248 -175
- snowflake/ml/modeling/neighbors/radius_neighbors_classifier.py +246 -175
- snowflake/ml/modeling/neighbors/radius_neighbors_regressor.py +246 -175
- snowflake/ml/modeling/neural_network/bernoulli_rbm.py +248 -175
- snowflake/ml/modeling/neural_network/mlp_classifier.py +246 -175
- snowflake/ml/modeling/neural_network/mlp_regressor.py +246 -175
- snowflake/ml/modeling/pipeline/pipeline.py +517 -35
- snowflake/ml/modeling/preprocessing/binarizer.py +1 -5
- snowflake/ml/modeling/preprocessing/k_bins_discretizer.py +1 -5
- snowflake/ml/modeling/preprocessing/label_encoder.py +1 -5
- snowflake/ml/modeling/preprocessing/max_abs_scaler.py +1 -5
- snowflake/ml/modeling/preprocessing/min_max_scaler.py +10 -12
- snowflake/ml/modeling/preprocessing/normalizer.py +1 -5
- snowflake/ml/modeling/preprocessing/one_hot_encoder.py +13 -5
- snowflake/ml/modeling/preprocessing/ordinal_encoder.py +1 -5
- snowflake/ml/modeling/preprocessing/polynomial_features.py +248 -175
- snowflake/ml/modeling/preprocessing/robust_scaler.py +1 -5
- snowflake/ml/modeling/preprocessing/standard_scaler.py +11 -11
- snowflake/ml/modeling/semi_supervised/label_propagation.py +246 -175
- snowflake/ml/modeling/semi_supervised/label_spreading.py +246 -175
- snowflake/ml/modeling/svm/linear_svc.py +246 -175
- snowflake/ml/modeling/svm/linear_svr.py +246 -175
- snowflake/ml/modeling/svm/nu_svc.py +246 -175
- snowflake/ml/modeling/svm/nu_svr.py +246 -175
- snowflake/ml/modeling/svm/svc.py +246 -175
- snowflake/ml/modeling/svm/svr.py +246 -175
- snowflake/ml/modeling/tree/decision_tree_classifier.py +246 -175
- snowflake/ml/modeling/tree/decision_tree_regressor.py +246 -175
- snowflake/ml/modeling/tree/extra_tree_classifier.py +246 -175
- snowflake/ml/modeling/tree/extra_tree_regressor.py +246 -175
- snowflake/ml/modeling/xgboost/xgb_classifier.py +246 -175
- snowflake/ml/modeling/xgboost/xgb_regressor.py +246 -175
- snowflake/ml/modeling/xgboost/xgbrf_classifier.py +246 -175
- snowflake/ml/modeling/xgboost/xgbrf_regressor.py +246 -175
- snowflake/ml/registry/model_registry.py +3 -149
- snowflake/ml/registry/registry.py +1 -1
- snowflake/ml/version.py +1 -1
- {snowflake_ml_python-1.4.0.dist-info → snowflake_ml_python-1.5.0.dist-info}/METADATA +129 -57
- snowflake_ml_python-1.5.0.dist-info/RECORD +380 -0
- snowflake/ml/model/_model_composer/model_runtime/model_runtime.py +0 -97
- snowflake/ml/registry/_artifact_manager.py +0 -156
- snowflake/ml/registry/artifact.py +0 -46
- snowflake_ml_python-1.4.0.dist-info/RECORD +0 -370
- {snowflake_ml_python-1.4.0.dist-info → snowflake_ml_python-1.5.0.dist-info}/LICENSE.txt +0 -0
- {snowflake_ml_python-1.4.0.dist-info → snowflake_ml_python-1.5.0.dist-info}/WHEEL +0 -0
- {snowflake_ml_python-1.4.0.dist-info → snowflake_ml_python-1.5.0.dist-info}/top_level.txt +0 -0
@@ -33,6 +33,15 @@ from snowflake.ml.modeling._internal.transformer_protocols import (
|
|
33
33
|
BatchInferenceKwargsTypedDict,
|
34
34
|
ScoreKwargsTypedDict
|
35
35
|
)
|
36
|
+
from snowflake.ml.model._signatures import utils as model_signature_utils
|
37
|
+
from snowflake.ml.model.model_signature import (
|
38
|
+
BaseFeatureSpec,
|
39
|
+
DataType,
|
40
|
+
FeatureSpec,
|
41
|
+
ModelSignature,
|
42
|
+
_infer_signature,
|
43
|
+
_rename_signature_with_snowflake_identifiers,
|
44
|
+
)
|
36
45
|
|
37
46
|
from snowflake.ml.modeling._internal.model_transformer_builder import ModelTransformerBuilder
|
38
47
|
|
@@ -43,16 +52,6 @@ from snowflake.ml.modeling._internal.estimator_utils import (
|
|
43
52
|
validate_sklearn_args,
|
44
53
|
)
|
45
54
|
|
46
|
-
from snowflake.ml.model.model_signature import (
|
47
|
-
DataType,
|
48
|
-
FeatureSpec,
|
49
|
-
ModelSignature,
|
50
|
-
_infer_signature,
|
51
|
-
_rename_signature_with_snowflake_identifiers,
|
52
|
-
BaseFeatureSpec,
|
53
|
-
)
|
54
|
-
from snowflake.ml.model._signatures import utils as model_signature_utils
|
55
|
-
|
56
55
|
_PROJECT = "ModelDevelopment"
|
57
56
|
# Derive subproject from module name by removing "sklearn"
|
58
57
|
# and converting module name from underscore to CamelCase
|
@@ -61,12 +60,6 @@ _SUBPROJECT = "".join([s.capitalize() for s in "sklearn.tree".replace("sklearn."
|
|
61
60
|
|
62
61
|
DATAFRAME_TYPE = Union[DataFrame, pd.DataFrame]
|
63
62
|
|
64
|
-
def _is_fit_transform_method_enabled() -> Callable[[Any], bool]:
|
65
|
-
def check(self: BaseTransformer) -> TypeGuard[Callable[..., object]]:
|
66
|
-
return False and callable(getattr(self._sklearn_object, "fit_transform", None))
|
67
|
-
return check
|
68
|
-
|
69
|
-
|
70
63
|
class ExtraTreeClassifier(BaseTransformer):
|
71
64
|
r"""An extremely randomized tree classifier
|
72
65
|
For more details on this class, see [sklearn.tree.ExtraTreeClassifier]
|
@@ -322,12 +315,7 @@ class ExtraTreeClassifier(BaseTransformer):
|
|
322
315
|
)
|
323
316
|
return selected_cols
|
324
317
|
|
325
|
-
|
326
|
-
project=_PROJECT,
|
327
|
-
subproject=_SUBPROJECT,
|
328
|
-
custom_tags=dict([("autogen", True)]),
|
329
|
-
)
|
330
|
-
def fit(self, dataset: Union[DataFrame, pd.DataFrame]) -> "ExtraTreeClassifier":
|
318
|
+
def _fit(self, dataset: Union[DataFrame, pd.DataFrame]) -> "ExtraTreeClassifier":
|
331
319
|
"""Build a decision tree classifier from the training set (X, y)
|
332
320
|
For more details on this function, see [sklearn.tree.ExtraTreeClassifier.fit]
|
333
321
|
(https://scikit-learn.org/stable/modules/generated/sklearn.tree.ExtraTreeClassifier.html#sklearn.tree.ExtraTreeClassifier.fit)
|
@@ -354,12 +342,14 @@ class ExtraTreeClassifier(BaseTransformer):
|
|
354
342
|
|
355
343
|
self._snowpark_cols = dataset.select(self.input_cols).columns
|
356
344
|
|
357
|
-
|
345
|
+
# If we are already in a stored procedure, no need to kick off another one.
|
358
346
|
if SNOWML_SPROC_ENV in os.environ:
|
359
347
|
statement_params = telemetry.get_function_usage_statement_params(
|
360
348
|
project=_PROJECT,
|
361
349
|
subproject=_SUBPROJECT,
|
362
|
-
function_name=telemetry.get_statement_params_full_func_name(
|
350
|
+
function_name=telemetry.get_statement_params_full_func_name(
|
351
|
+
inspect.currentframe(), ExtraTreeClassifier.__class__.__name__
|
352
|
+
),
|
363
353
|
api_calls=[Session.call],
|
364
354
|
custom_tags=dict([("autogen", True)]) if self._autogenerated else None,
|
365
355
|
)
|
@@ -380,27 +370,24 @@ class ExtraTreeClassifier(BaseTransformer):
|
|
380
370
|
)
|
381
371
|
self._sklearn_object = model_trainer.train()
|
382
372
|
self._is_fitted = True
|
383
|
-
self.
|
373
|
+
self._generate_model_signatures(dataset)
|
384
374
|
return self
|
385
375
|
|
386
376
|
def _batch_inference_validate_snowpark(
|
387
377
|
self,
|
388
378
|
dataset: DataFrame,
|
389
379
|
inference_method: str,
|
390
|
-
) ->
|
391
|
-
"""Util method to run validate that batch inference can be run on a snowpark dataframe
|
392
|
-
return the available package that exists in the snowflake anaconda channel
|
380
|
+
) -> None:
|
381
|
+
"""Util method to run validate that batch inference can be run on a snowpark dataframe.
|
393
382
|
|
394
383
|
Args:
|
395
384
|
dataset: snowpark dataframe
|
396
385
|
inference_method: the inference method such as predict, score...
|
397
|
-
|
386
|
+
|
398
387
|
Raises:
|
399
388
|
SnowflakeMLException: If the estimator is not fitted, raise error
|
400
389
|
SnowflakeMLException: If the session is None, raise error
|
401
390
|
|
402
|
-
Returns:
|
403
|
-
A list of available package that exists in the snowflake anaconda channel
|
404
391
|
"""
|
405
392
|
if not self._is_fitted:
|
406
393
|
raise exceptions.SnowflakeMLException(
|
@@ -418,9 +405,7 @@ class ExtraTreeClassifier(BaseTransformer):
|
|
418
405
|
"Session must not specified for snowpark dataset."
|
419
406
|
),
|
420
407
|
)
|
421
|
-
|
422
|
-
return pkg_version_utils.get_valid_pkg_versions_supported_in_snowflake_conda_channel(
|
423
|
-
pkg_versions=self._get_dependencies(), session=session, subproject=_SUBPROJECT)
|
408
|
+
|
424
409
|
|
425
410
|
@available_if(original_estimator_has_callable("predict")) # type: ignore[misc]
|
426
411
|
@telemetry.send_api_usage_telemetry(
|
@@ -456,7 +441,9 @@ class ExtraTreeClassifier(BaseTransformer):
|
|
456
441
|
# when it is classifier, infer the datatype from label columns
|
457
442
|
if expected_type_inferred == "" and 'predict' in self.model_signatures:
|
458
443
|
# Batch inference takes a single expected output column type. Use the first columns type for now.
|
459
|
-
label_cols_signatures = [
|
444
|
+
label_cols_signatures = [
|
445
|
+
row for row in self.model_signatures['predict'].outputs if row.name in self.output_cols
|
446
|
+
]
|
460
447
|
if len(label_cols_signatures) == 0:
|
461
448
|
error_str = f"Output columns {self.output_cols} do not match model signatures {self.model_signatures['predict'].outputs}."
|
462
449
|
raise exceptions.SnowflakeMLException(
|
@@ -464,25 +451,23 @@ class ExtraTreeClassifier(BaseTransformer):
|
|
464
451
|
original_exception=ValueError(error_str),
|
465
452
|
)
|
466
453
|
|
467
|
-
expected_type_inferred = convert_sp_to_sf_type(
|
468
|
-
label_cols_signatures[0].as_snowpark_type()
|
469
|
-
)
|
454
|
+
expected_type_inferred = convert_sp_to_sf_type(label_cols_signatures[0].as_snowpark_type())
|
470
455
|
|
471
|
-
self.
|
472
|
-
|
456
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
457
|
+
self._deps = self._get_dependencies()
|
458
|
+
assert isinstance(
|
459
|
+
dataset._session, Session
|
460
|
+
) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
473
461
|
|
474
462
|
transform_kwargs = dict(
|
475
|
-
session
|
476
|
-
dependencies
|
477
|
-
drop_input_cols
|
478
|
-
expected_output_cols_type
|
463
|
+
session=dataset._session,
|
464
|
+
dependencies=self._deps,
|
465
|
+
drop_input_cols=self._drop_input_cols,
|
466
|
+
expected_output_cols_type=expected_type_inferred,
|
479
467
|
)
|
480
468
|
|
481
469
|
elif isinstance(dataset, pd.DataFrame):
|
482
|
-
transform_kwargs = dict(
|
483
|
-
snowpark_input_cols = self._snowpark_cols,
|
484
|
-
drop_input_cols = self._drop_input_cols
|
485
|
-
)
|
470
|
+
transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
|
486
471
|
|
487
472
|
transform_handlers = ModelTransformerBuilder.build(
|
488
473
|
dataset=dataset,
|
@@ -522,7 +507,7 @@ class ExtraTreeClassifier(BaseTransformer):
|
|
522
507
|
Transformed dataset.
|
523
508
|
"""
|
524
509
|
super()._check_dataset_type(dataset)
|
525
|
-
inference_method="transform"
|
510
|
+
inference_method = "transform"
|
526
511
|
|
527
512
|
# This dictionary contains optional kwargs for batch inference. These kwargs
|
528
513
|
# are specific to the type of dataset used.
|
@@ -552,24 +537,19 @@ class ExtraTreeClassifier(BaseTransformer):
|
|
552
537
|
if all(x == output_types[0] for x in output_types) and len(output_types) == len(self.output_cols):
|
553
538
|
expected_dtype = convert_sp_to_sf_type(output_types[0])
|
554
539
|
|
555
|
-
self.
|
556
|
-
|
557
|
-
inference_method=inference_method,
|
558
|
-
)
|
540
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
541
|
+
self._deps = self._get_dependencies()
|
559
542
|
assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
560
543
|
|
561
544
|
transform_kwargs = dict(
|
562
|
-
session
|
563
|
-
dependencies
|
564
|
-
drop_input_cols
|
565
|
-
expected_output_cols_type
|
545
|
+
session=dataset._session,
|
546
|
+
dependencies=self._deps,
|
547
|
+
drop_input_cols=self._drop_input_cols,
|
548
|
+
expected_output_cols_type=expected_dtype,
|
566
549
|
)
|
567
550
|
|
568
551
|
elif isinstance(dataset, pd.DataFrame):
|
569
|
-
transform_kwargs = dict(
|
570
|
-
snowpark_input_cols = self._snowpark_cols,
|
571
|
-
drop_input_cols = self._drop_input_cols
|
572
|
-
)
|
552
|
+
transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
|
573
553
|
|
574
554
|
transform_handlers = ModelTransformerBuilder.build(
|
575
555
|
dataset=dataset,
|
@@ -588,7 +568,11 @@ class ExtraTreeClassifier(BaseTransformer):
|
|
588
568
|
return output_df
|
589
569
|
|
590
570
|
@available_if(original_estimator_has_callable("fit_predict")) # type: ignore[misc]
|
591
|
-
def fit_predict(
|
571
|
+
def fit_predict(
|
572
|
+
self,
|
573
|
+
dataset: Union[DataFrame, pd.DataFrame],
|
574
|
+
output_cols_prefix: str = "fit_predict_",
|
575
|
+
) -> Union[DataFrame, pd.DataFrame]:
|
592
576
|
""" Method not supported for this class.
|
593
577
|
|
594
578
|
|
@@ -613,22 +597,104 @@ class ExtraTreeClassifier(BaseTransformer):
|
|
613
597
|
)
|
614
598
|
output_result, fitted_estimator = model_trainer.train_fit_predict(
|
615
599
|
drop_input_cols=self._drop_input_cols,
|
616
|
-
expected_output_cols_list=
|
600
|
+
expected_output_cols_list=(
|
601
|
+
self.output_cols if self.output_cols else self._get_output_column_names(output_cols_prefix)
|
602
|
+
),
|
617
603
|
)
|
618
604
|
self._sklearn_object = fitted_estimator
|
619
605
|
self._is_fitted = True
|
620
606
|
return output_result
|
621
607
|
|
608
|
+
|
609
|
+
@available_if(original_estimator_has_callable("fit_transform")) # type: ignore[misc]
|
610
|
+
def fit_transform(self, dataset: Union[DataFrame, pd.DataFrame], output_cols_prefix: str = "fit_transform_",) -> Union[DataFrame, pd.DataFrame]:
|
611
|
+
""" Method not supported for this class.
|
612
|
+
|
622
613
|
|
623
|
-
|
624
|
-
|
625
|
-
|
614
|
+
Raises:
|
615
|
+
TypeError: Supported dataset types: snowpark.DataFrame, pandas.DataFrame.
|
616
|
+
|
617
|
+
Args:
|
618
|
+
dataset: Union[snowflake.snowpark.DataFrame, pandas.DataFrame]
|
619
|
+
Snowpark or Pandas DataFrame.
|
620
|
+
output_cols_prefix: Prefix for the response columns
|
626
621
|
Returns:
|
627
622
|
Transformed dataset.
|
628
623
|
"""
|
629
|
-
self.
|
630
|
-
|
631
|
-
|
624
|
+
self._infer_input_output_cols(dataset)
|
625
|
+
super()._check_dataset_type(dataset)
|
626
|
+
model_trainer = ModelTrainerBuilder.build_fit_transform(
|
627
|
+
estimator=self._sklearn_object,
|
628
|
+
dataset=dataset,
|
629
|
+
input_cols=self.input_cols,
|
630
|
+
label_cols=self.label_cols,
|
631
|
+
sample_weight_col=self.sample_weight_col,
|
632
|
+
autogenerated=self._autogenerated,
|
633
|
+
subproject=_SUBPROJECT,
|
634
|
+
)
|
635
|
+
output_result, fitted_estimator = model_trainer.train_fit_transform(
|
636
|
+
drop_input_cols=self._drop_input_cols,
|
637
|
+
expected_output_cols_list=self.output_cols,
|
638
|
+
)
|
639
|
+
self._sklearn_object = fitted_estimator
|
640
|
+
self._is_fitted = True
|
641
|
+
return output_result
|
642
|
+
|
643
|
+
|
644
|
+
def _get_output_column_names(self, output_cols_prefix: str, output_cols: Optional[List[str]] = None) -> List[str]:
|
645
|
+
""" Returns the list of output columns for predict_proba(), decision_function(), etc.. functions.
|
646
|
+
Returns a list with output_cols_prefix as the only element if the estimator is not a classifier.
|
647
|
+
"""
|
648
|
+
output_cols_prefix = identifier.resolve_identifier(output_cols_prefix)
|
649
|
+
# The following condition is introduced for kneighbors methods, and not used in other methods
|
650
|
+
if output_cols:
|
651
|
+
output_cols = [
|
652
|
+
identifier.concat_names([output_cols_prefix, identifier.resolve_identifier(c)])
|
653
|
+
for c in output_cols
|
654
|
+
]
|
655
|
+
elif getattr(self._sklearn_object, "classes_", None) is None:
|
656
|
+
output_cols = [output_cols_prefix]
|
657
|
+
elif self._sklearn_object is not None:
|
658
|
+
classes = self._sklearn_object.classes_
|
659
|
+
if isinstance(classes, numpy.ndarray):
|
660
|
+
output_cols = [f'{output_cols_prefix}{str(c)}' for c in classes.tolist()]
|
661
|
+
elif isinstance(classes, list) and len(classes) > 0 and isinstance(classes[0], numpy.ndarray):
|
662
|
+
# If the estimator is a multioutput estimator, classes_ will be a list of ndarrays.
|
663
|
+
output_cols = []
|
664
|
+
for i, cl in enumerate(classes):
|
665
|
+
# For binary classification, there is only one output column for each class
|
666
|
+
# ndarray as the two classes are complementary.
|
667
|
+
if len(cl) == 2:
|
668
|
+
output_cols.append(f'{output_cols_prefix}{i}_{cl[0]}')
|
669
|
+
else:
|
670
|
+
output_cols.extend([
|
671
|
+
f'{output_cols_prefix}{i}_{c}' for c in cl.tolist()
|
672
|
+
])
|
673
|
+
else:
|
674
|
+
output_cols = []
|
675
|
+
|
676
|
+
# Make sure column names are valid snowflake identifiers.
|
677
|
+
assert output_cols is not None # Make MyPy happy
|
678
|
+
rv = [identifier.rename_to_valid_snowflake_identifier(c) for c in output_cols]
|
679
|
+
|
680
|
+
return rv
|
681
|
+
|
682
|
+
def _align_expected_output_names(
|
683
|
+
self, method: str, dataset: DataFrame, expected_output_cols_list: List[str], output_cols_prefix: str
|
684
|
+
) -> List[str]:
|
685
|
+
# in case the inferred output column names dimension is different
|
686
|
+
# we use one line of snowpark dataframe and put it into sklearn estimator using pandas
|
687
|
+
output_df_pd = getattr(self, method)(dataset.limit(1).to_pandas(), output_cols_prefix)
|
688
|
+
output_df_columns = list(output_df_pd.columns)
|
689
|
+
output_df_columns_set: Set[str] = set(output_df_columns) - set(dataset.columns)
|
690
|
+
if self.sample_weight_col:
|
691
|
+
output_df_columns_set -= set(self.sample_weight_col)
|
692
|
+
# if the dimension of inferred output column names is correct; use it
|
693
|
+
if len(expected_output_cols_list) == len(output_df_columns_set):
|
694
|
+
return expected_output_cols_list
|
695
|
+
# otherwise, use the sklearn estimator's output
|
696
|
+
else:
|
697
|
+
return sorted(list(output_df_columns_set), key=lambda x: output_df_columns.index(x))
|
632
698
|
|
633
699
|
@available_if(original_estimator_has_callable("predict_proba")) # type: ignore[misc]
|
634
700
|
@telemetry.send_api_usage_telemetry(
|
@@ -662,24 +728,26 @@ class ExtraTreeClassifier(BaseTransformer):
|
|
662
728
|
# are specific to the type of dataset used.
|
663
729
|
transform_kwargs: BatchInferenceKwargsTypedDict = dict()
|
664
730
|
|
731
|
+
expected_output_cols = self._get_output_column_names(output_cols_prefix)
|
732
|
+
|
665
733
|
if isinstance(dataset, DataFrame):
|
666
|
-
self.
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
734
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
735
|
+
self._deps = self._get_dependencies()
|
736
|
+
assert isinstance(
|
737
|
+
dataset._session, Session
|
738
|
+
) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
671
739
|
transform_kwargs = dict(
|
672
740
|
session=dataset._session,
|
673
741
|
dependencies=self._deps,
|
674
|
-
drop_input_cols
|
742
|
+
drop_input_cols=self._drop_input_cols,
|
675
743
|
expected_output_cols_type="float",
|
676
744
|
)
|
745
|
+
expected_output_cols = self._align_expected_output_names(
|
746
|
+
inference_method, dataset, expected_output_cols, output_cols_prefix
|
747
|
+
)
|
677
748
|
|
678
749
|
elif isinstance(dataset, pd.DataFrame):
|
679
|
-
transform_kwargs = dict(
|
680
|
-
snowpark_input_cols = self._snowpark_cols,
|
681
|
-
drop_input_cols = self._drop_input_cols
|
682
|
-
)
|
750
|
+
transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
|
683
751
|
|
684
752
|
transform_handlers = ModelTransformerBuilder.build(
|
685
753
|
dataset=dataset,
|
@@ -691,7 +759,7 @@ class ExtraTreeClassifier(BaseTransformer):
|
|
691
759
|
output_df: DATAFRAME_TYPE = transform_handlers.batch_inference(
|
692
760
|
inference_method=inference_method,
|
693
761
|
input_cols=self.input_cols,
|
694
|
-
expected_output_cols=
|
762
|
+
expected_output_cols=expected_output_cols,
|
695
763
|
**transform_kwargs
|
696
764
|
)
|
697
765
|
return output_df
|
@@ -723,29 +791,30 @@ class ExtraTreeClassifier(BaseTransformer):
|
|
723
791
|
Output dataset with log probability of the sample for each class in the model.
|
724
792
|
"""
|
725
793
|
super()._check_dataset_type(dataset)
|
726
|
-
inference_method="predict_log_proba"
|
794
|
+
inference_method = "predict_log_proba"
|
795
|
+
expected_output_cols = self._get_output_column_names(output_cols_prefix)
|
727
796
|
|
728
797
|
# This dictionary contains optional kwargs for batch inference. These kwargs
|
729
798
|
# are specific to the type of dataset used.
|
730
799
|
transform_kwargs: BatchInferenceKwargsTypedDict = dict()
|
731
800
|
|
732
801
|
if isinstance(dataset, DataFrame):
|
733
|
-
self.
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
802
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
803
|
+
self._deps = self._get_dependencies()
|
804
|
+
assert isinstance(
|
805
|
+
dataset._session, Session
|
806
|
+
) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
738
807
|
transform_kwargs = dict(
|
739
808
|
session=dataset._session,
|
740
809
|
dependencies=self._deps,
|
741
|
-
drop_input_cols
|
810
|
+
drop_input_cols=self._drop_input_cols,
|
742
811
|
expected_output_cols_type="float",
|
743
812
|
)
|
813
|
+
expected_output_cols = self._align_expected_output_names(
|
814
|
+
inference_method, dataset, expected_output_cols, output_cols_prefix
|
815
|
+
)
|
744
816
|
elif isinstance(dataset, pd.DataFrame):
|
745
|
-
transform_kwargs = dict(
|
746
|
-
snowpark_input_cols = self._snowpark_cols,
|
747
|
-
drop_input_cols = self._drop_input_cols
|
748
|
-
)
|
817
|
+
transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
|
749
818
|
|
750
819
|
transform_handlers = ModelTransformerBuilder.build(
|
751
820
|
dataset=dataset,
|
@@ -758,7 +827,7 @@ class ExtraTreeClassifier(BaseTransformer):
|
|
758
827
|
output_df: DATAFRAME_TYPE = transform_handlers.batch_inference(
|
759
828
|
inference_method=inference_method,
|
760
829
|
input_cols=self.input_cols,
|
761
|
-
expected_output_cols=
|
830
|
+
expected_output_cols=expected_output_cols,
|
762
831
|
**transform_kwargs
|
763
832
|
)
|
764
833
|
return output_df
|
@@ -784,30 +853,32 @@ class ExtraTreeClassifier(BaseTransformer):
|
|
784
853
|
Output dataset with results of the decision function for the samples in input dataset.
|
785
854
|
"""
|
786
855
|
super()._check_dataset_type(dataset)
|
787
|
-
inference_method="decision_function"
|
856
|
+
inference_method = "decision_function"
|
788
857
|
|
789
858
|
# This dictionary contains optional kwargs for batch inference. These kwargs
|
790
859
|
# are specific to the type of dataset used.
|
791
860
|
transform_kwargs: BatchInferenceKwargsTypedDict = dict()
|
792
861
|
|
862
|
+
expected_output_cols = self._get_output_column_names(output_cols_prefix)
|
863
|
+
|
793
864
|
if isinstance(dataset, DataFrame):
|
794
|
-
self.
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
865
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
866
|
+
self._deps = self._get_dependencies()
|
867
|
+
assert isinstance(
|
868
|
+
dataset._session, Session
|
869
|
+
) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
799
870
|
transform_kwargs = dict(
|
800
871
|
session=dataset._session,
|
801
872
|
dependencies=self._deps,
|
802
|
-
drop_input_cols
|
873
|
+
drop_input_cols=self._drop_input_cols,
|
803
874
|
expected_output_cols_type="float",
|
804
875
|
)
|
876
|
+
expected_output_cols = self._align_expected_output_names(
|
877
|
+
inference_method, dataset, expected_output_cols, output_cols_prefix
|
878
|
+
)
|
805
879
|
|
806
880
|
elif isinstance(dataset, pd.DataFrame):
|
807
|
-
transform_kwargs = dict(
|
808
|
-
snowpark_input_cols = self._snowpark_cols,
|
809
|
-
drop_input_cols = self._drop_input_cols
|
810
|
-
)
|
881
|
+
transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
|
811
882
|
|
812
883
|
transform_handlers = ModelTransformerBuilder.build(
|
813
884
|
dataset=dataset,
|
@@ -820,7 +891,7 @@ class ExtraTreeClassifier(BaseTransformer):
|
|
820
891
|
output_df: DATAFRAME_TYPE = transform_handlers.batch_inference(
|
821
892
|
inference_method=inference_method,
|
822
893
|
input_cols=self.input_cols,
|
823
|
-
expected_output_cols=
|
894
|
+
expected_output_cols=expected_output_cols,
|
824
895
|
**transform_kwargs
|
825
896
|
)
|
826
897
|
return output_df
|
@@ -849,17 +920,17 @@ class ExtraTreeClassifier(BaseTransformer):
|
|
849
920
|
Output dataset with probability of the sample for each class in the model.
|
850
921
|
"""
|
851
922
|
super()._check_dataset_type(dataset)
|
852
|
-
inference_method="score_samples"
|
923
|
+
inference_method = "score_samples"
|
853
924
|
|
854
925
|
# This dictionary contains optional kwargs for batch inference. These kwargs
|
855
926
|
# are specific to the type of dataset used.
|
856
927
|
transform_kwargs: BatchInferenceKwargsTypedDict = dict()
|
857
928
|
|
929
|
+
expected_output_cols = self._get_output_column_names(output_cols_prefix)
|
930
|
+
|
858
931
|
if isinstance(dataset, DataFrame):
|
859
|
-
self.
|
860
|
-
|
861
|
-
inference_method=inference_method,
|
862
|
-
)
|
932
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
933
|
+
self._deps = self._get_dependencies()
|
863
934
|
assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
864
935
|
transform_kwargs = dict(
|
865
936
|
session=dataset._session,
|
@@ -867,6 +938,9 @@ class ExtraTreeClassifier(BaseTransformer):
|
|
867
938
|
drop_input_cols = self._drop_input_cols,
|
868
939
|
expected_output_cols_type="float",
|
869
940
|
)
|
941
|
+
expected_output_cols = self._align_expected_output_names(
|
942
|
+
inference_method, dataset, expected_output_cols, output_cols_prefix
|
943
|
+
)
|
870
944
|
|
871
945
|
elif isinstance(dataset, pd.DataFrame):
|
872
946
|
transform_kwargs = dict(
|
@@ -885,7 +959,7 @@ class ExtraTreeClassifier(BaseTransformer):
|
|
885
959
|
output_df: DATAFRAME_TYPE = transform_handlers.batch_inference(
|
886
960
|
inference_method=inference_method,
|
887
961
|
input_cols=self.input_cols,
|
888
|
-
expected_output_cols=
|
962
|
+
expected_output_cols=expected_output_cols,
|
889
963
|
**transform_kwargs
|
890
964
|
)
|
891
965
|
return output_df
|
@@ -920,17 +994,15 @@ class ExtraTreeClassifier(BaseTransformer):
|
|
920
994
|
transform_kwargs: ScoreKwargsTypedDict = dict()
|
921
995
|
|
922
996
|
if isinstance(dataset, DataFrame):
|
923
|
-
self.
|
924
|
-
|
925
|
-
inference_method="score",
|
926
|
-
)
|
997
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method="score")
|
998
|
+
self._deps = self._get_dependencies()
|
927
999
|
selected_cols = self._get_active_columns()
|
928
1000
|
if len(selected_cols) > 0:
|
929
1001
|
dataset = dataset.select(selected_cols)
|
930
1002
|
assert isinstance(dataset._session, Session) # keep mypy happy
|
931
1003
|
transform_kwargs = dict(
|
932
1004
|
session=dataset._session,
|
933
|
-
dependencies=
|
1005
|
+
dependencies=self._deps,
|
934
1006
|
score_sproc_imports=['sklearn'],
|
935
1007
|
)
|
936
1008
|
elif isinstance(dataset, pd.DataFrame):
|
@@ -995,11 +1067,8 @@ class ExtraTreeClassifier(BaseTransformer):
|
|
995
1067
|
|
996
1068
|
if isinstance(dataset, DataFrame):
|
997
1069
|
|
998
|
-
self.
|
999
|
-
|
1000
|
-
inference_method=inference_method,
|
1001
|
-
|
1002
|
-
)
|
1070
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
1071
|
+
self._deps = self._get_dependencies()
|
1003
1072
|
assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
1004
1073
|
transform_kwargs = dict(
|
1005
1074
|
session = dataset._session,
|
@@ -1032,50 +1101,84 @@ class ExtraTreeClassifier(BaseTransformer):
|
|
1032
1101
|
)
|
1033
1102
|
return output_df
|
1034
1103
|
|
1104
|
+
|
1105
|
+
|
1106
|
+
def to_sklearn(self) -> Any:
|
1107
|
+
"""Get sklearn.tree.ExtraTreeClassifier object.
|
1108
|
+
"""
|
1109
|
+
if self._sklearn_object is None:
|
1110
|
+
self._sklearn_object = self._create_sklearn_object()
|
1111
|
+
return self._sklearn_object
|
1112
|
+
|
1113
|
+
def to_xgboost(self) -> Any:
|
1114
|
+
raise exceptions.SnowflakeMLException(
|
1115
|
+
error_code=error_codes.METHOD_NOT_ALLOWED,
|
1116
|
+
original_exception=AttributeError(
|
1117
|
+
modeling_error_messages.UNSUPPORTED_MODEL_CONVERSION.format(
|
1118
|
+
"to_xgboost()",
|
1119
|
+
"to_sklearn()"
|
1120
|
+
)
|
1121
|
+
),
|
1122
|
+
)
|
1123
|
+
|
1124
|
+
def to_lightgbm(self) -> Any:
|
1125
|
+
raise exceptions.SnowflakeMLException(
|
1126
|
+
error_code=error_codes.METHOD_NOT_ALLOWED,
|
1127
|
+
original_exception=AttributeError(
|
1128
|
+
modeling_error_messages.UNSUPPORTED_MODEL_CONVERSION.format(
|
1129
|
+
"to_lightgbm()",
|
1130
|
+
"to_sklearn()"
|
1131
|
+
)
|
1132
|
+
),
|
1133
|
+
)
|
1134
|
+
|
1135
|
+
def _get_dependencies(self) -> List[str]:
|
1136
|
+
return self._deps
|
1137
|
+
|
1035
1138
|
|
1036
|
-
def
|
1139
|
+
def _generate_model_signatures(self, dataset: Union[DataFrame, pd.DataFrame]) -> None:
|
1037
1140
|
self._model_signature_dict = dict()
|
1038
1141
|
|
1039
1142
|
PROB_FUNCTIONS = ["predict_log_proba", "predict_proba", "decision_function"]
|
1040
1143
|
|
1041
|
-
inputs = list(_infer_signature(dataset[self.input_cols], "input"))
|
1144
|
+
inputs = list(_infer_signature(dataset[self.input_cols], "input", use_snowflake_identifiers=True))
|
1042
1145
|
outputs: List[BaseFeatureSpec] = []
|
1043
1146
|
if hasattr(self, "predict"):
|
1044
1147
|
# keep mypy happy
|
1045
|
-
assert self._sklearn_object is not None and hasattr(self._sklearn_object, "_estimator_type")
|
1148
|
+
assert self._sklearn_object is not None and hasattr(self._sklearn_object, "_estimator_type")
|
1046
1149
|
# For classifier, the type of predict is the same as the type of label
|
1047
|
-
if self._sklearn_object._estimator_type ==
|
1048
|
-
|
1150
|
+
if self._sklearn_object._estimator_type == "classifier":
|
1151
|
+
# label columns is the desired type for output
|
1049
1152
|
outputs = list(_infer_signature(dataset[self.label_cols], "output", use_snowflake_identifiers=True))
|
1050
1153
|
# rename the output columns
|
1051
1154
|
outputs = list(model_signature_utils.rename_features(outputs, self.output_cols))
|
1052
|
-
self._model_signature_dict["predict"] = ModelSignature(
|
1053
|
-
|
1054
|
-
|
1155
|
+
self._model_signature_dict["predict"] = ModelSignature(
|
1156
|
+
inputs, ([] if self._drop_input_cols else inputs) + outputs
|
1157
|
+
)
|
1055
1158
|
# For mixture models that use the density mixin, `predict` returns the argmax of the log prob.
|
1056
1159
|
# For outlier models, returns -1 for outliers and 1 for inliers.
|
1057
|
-
# Clusterer returns int64 cluster labels.
|
1160
|
+
# Clusterer returns int64 cluster labels.
|
1058
1161
|
elif self._sklearn_object._estimator_type in ["DensityEstimator", "clusterer", "outlier_detector"]:
|
1059
1162
|
outputs = [FeatureSpec(dtype=DataType.INT64, name=c) for c in self.output_cols]
|
1060
|
-
self._model_signature_dict["predict"] = ModelSignature(
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1163
|
+
self._model_signature_dict["predict"] = ModelSignature(
|
1164
|
+
inputs, ([] if self._drop_input_cols else inputs) + outputs
|
1165
|
+
)
|
1166
|
+
|
1064
1167
|
# For regressor, the type of predict is float64
|
1065
|
-
elif self._sklearn_object._estimator_type ==
|
1168
|
+
elif self._sklearn_object._estimator_type == "regressor":
|
1066
1169
|
outputs = [FeatureSpec(dtype=DataType.DOUBLE, name=c) for c in self.output_cols]
|
1067
|
-
self._model_signature_dict["predict"] = ModelSignature(
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1170
|
+
self._model_signature_dict["predict"] = ModelSignature(
|
1171
|
+
inputs, ([] if self._drop_input_cols else inputs) + outputs
|
1172
|
+
)
|
1173
|
+
|
1071
1174
|
for prob_func in PROB_FUNCTIONS:
|
1072
1175
|
if hasattr(self, prob_func):
|
1073
1176
|
output_cols_prefix: str = f"{prob_func}_"
|
1074
1177
|
output_column_names = self._get_output_column_names(output_cols_prefix)
|
1075
1178
|
outputs = [FeatureSpec(dtype=DataType.DOUBLE, name=c) for c in output_column_names]
|
1076
|
-
self._model_signature_dict[prob_func] = ModelSignature(
|
1077
|
-
|
1078
|
-
|
1179
|
+
self._model_signature_dict[prob_func] = ModelSignature(
|
1180
|
+
inputs, ([] if self._drop_input_cols else inputs) + outputs
|
1181
|
+
)
|
1079
1182
|
|
1080
1183
|
# Output signature names may still need to be renamed, since they were not created with `_infer_signature`.
|
1081
1184
|
items = list(self._model_signature_dict.items())
|
@@ -1088,10 +1191,10 @@ class ExtraTreeClassifier(BaseTransformer):
|
|
1088
1191
|
"""Returns model signature of current class.
|
1089
1192
|
|
1090
1193
|
Raises:
|
1091
|
-
|
1194
|
+
SnowflakeMLException: If estimator is not fitted, then model signature cannot be inferred
|
1092
1195
|
|
1093
1196
|
Returns:
|
1094
|
-
Dict
|
1197
|
+
Dict with each method and its input output signature
|
1095
1198
|
"""
|
1096
1199
|
if self._model_signature_dict is None:
|
1097
1200
|
raise exceptions.SnowflakeMLException(
|
@@ -1099,35 +1202,3 @@ class ExtraTreeClassifier(BaseTransformer):
|
|
1099
1202
|
original_exception=RuntimeError("Estimator not fitted before accessing property model_signatures!"),
|
1100
1203
|
)
|
1101
1204
|
return self._model_signature_dict
|
1102
|
-
|
1103
|
-
def to_sklearn(self) -> Any:
|
1104
|
-
"""Get sklearn.tree.ExtraTreeClassifier object.
|
1105
|
-
"""
|
1106
|
-
if self._sklearn_object is None:
|
1107
|
-
self._sklearn_object = self._create_sklearn_object()
|
1108
|
-
return self._sklearn_object
|
1109
|
-
|
1110
|
-
def to_xgboost(self) -> Any:
|
1111
|
-
raise exceptions.SnowflakeMLException(
|
1112
|
-
error_code=error_codes.METHOD_NOT_ALLOWED,
|
1113
|
-
original_exception=AttributeError(
|
1114
|
-
modeling_error_messages.UNSUPPORTED_MODEL_CONVERSION.format(
|
1115
|
-
"to_xgboost()",
|
1116
|
-
"to_sklearn()"
|
1117
|
-
)
|
1118
|
-
),
|
1119
|
-
)
|
1120
|
-
|
1121
|
-
def to_lightgbm(self) -> Any:
|
1122
|
-
raise exceptions.SnowflakeMLException(
|
1123
|
-
error_code=error_codes.METHOD_NOT_ALLOWED,
|
1124
|
-
original_exception=AttributeError(
|
1125
|
-
modeling_error_messages.UNSUPPORTED_MODEL_CONVERSION.format(
|
1126
|
-
"to_lightgbm()",
|
1127
|
-
"to_sklearn()"
|
1128
|
-
)
|
1129
|
-
),
|
1130
|
-
)
|
1131
|
-
|
1132
|
-
def _get_dependencies(self) -> List[str]:
|
1133
|
-
return self._deps
|