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 ExtraTreeRegressor(BaseTransformer):
|
71
64
|
r"""An extremely randomized tree regressor
|
72
65
|
For more details on this class, see [sklearn.tree.ExtraTreeRegressor]
|
@@ -304,12 +297,7 @@ class ExtraTreeRegressor(BaseTransformer):
|
|
304
297
|
)
|
305
298
|
return selected_cols
|
306
299
|
|
307
|
-
|
308
|
-
project=_PROJECT,
|
309
|
-
subproject=_SUBPROJECT,
|
310
|
-
custom_tags=dict([("autogen", True)]),
|
311
|
-
)
|
312
|
-
def fit(self, dataset: Union[DataFrame, pd.DataFrame]) -> "ExtraTreeRegressor":
|
300
|
+
def _fit(self, dataset: Union[DataFrame, pd.DataFrame]) -> "ExtraTreeRegressor":
|
313
301
|
"""Build a decision tree regressor from the training set (X, y)
|
314
302
|
For more details on this function, see [sklearn.tree.ExtraTreeRegressor.fit]
|
315
303
|
(https://scikit-learn.org/stable/modules/generated/sklearn.tree.ExtraTreeRegressor.html#sklearn.tree.ExtraTreeRegressor.fit)
|
@@ -336,12 +324,14 @@ class ExtraTreeRegressor(BaseTransformer):
|
|
336
324
|
|
337
325
|
self._snowpark_cols = dataset.select(self.input_cols).columns
|
338
326
|
|
339
|
-
|
327
|
+
# If we are already in a stored procedure, no need to kick off another one.
|
340
328
|
if SNOWML_SPROC_ENV in os.environ:
|
341
329
|
statement_params = telemetry.get_function_usage_statement_params(
|
342
330
|
project=_PROJECT,
|
343
331
|
subproject=_SUBPROJECT,
|
344
|
-
function_name=telemetry.get_statement_params_full_func_name(
|
332
|
+
function_name=telemetry.get_statement_params_full_func_name(
|
333
|
+
inspect.currentframe(), ExtraTreeRegressor.__class__.__name__
|
334
|
+
),
|
345
335
|
api_calls=[Session.call],
|
346
336
|
custom_tags=dict([("autogen", True)]) if self._autogenerated else None,
|
347
337
|
)
|
@@ -362,27 +352,24 @@ class ExtraTreeRegressor(BaseTransformer):
|
|
362
352
|
)
|
363
353
|
self._sklearn_object = model_trainer.train()
|
364
354
|
self._is_fitted = True
|
365
|
-
self.
|
355
|
+
self._generate_model_signatures(dataset)
|
366
356
|
return self
|
367
357
|
|
368
358
|
def _batch_inference_validate_snowpark(
|
369
359
|
self,
|
370
360
|
dataset: DataFrame,
|
371
361
|
inference_method: str,
|
372
|
-
) ->
|
373
|
-
"""Util method to run validate that batch inference can be run on a snowpark dataframe
|
374
|
-
return the available package that exists in the snowflake anaconda channel
|
362
|
+
) -> None:
|
363
|
+
"""Util method to run validate that batch inference can be run on a snowpark dataframe.
|
375
364
|
|
376
365
|
Args:
|
377
366
|
dataset: snowpark dataframe
|
378
367
|
inference_method: the inference method such as predict, score...
|
379
|
-
|
368
|
+
|
380
369
|
Raises:
|
381
370
|
SnowflakeMLException: If the estimator is not fitted, raise error
|
382
371
|
SnowflakeMLException: If the session is None, raise error
|
383
372
|
|
384
|
-
Returns:
|
385
|
-
A list of available package that exists in the snowflake anaconda channel
|
386
373
|
"""
|
387
374
|
if not self._is_fitted:
|
388
375
|
raise exceptions.SnowflakeMLException(
|
@@ -400,9 +387,7 @@ class ExtraTreeRegressor(BaseTransformer):
|
|
400
387
|
"Session must not specified for snowpark dataset."
|
401
388
|
),
|
402
389
|
)
|
403
|
-
|
404
|
-
return pkg_version_utils.get_valid_pkg_versions_supported_in_snowflake_conda_channel(
|
405
|
-
pkg_versions=self._get_dependencies(), session=session, subproject=_SUBPROJECT)
|
390
|
+
|
406
391
|
|
407
392
|
@available_if(original_estimator_has_callable("predict")) # type: ignore[misc]
|
408
393
|
@telemetry.send_api_usage_telemetry(
|
@@ -438,7 +423,9 @@ class ExtraTreeRegressor(BaseTransformer):
|
|
438
423
|
# when it is classifier, infer the datatype from label columns
|
439
424
|
if expected_type_inferred == "" and 'predict' in self.model_signatures:
|
440
425
|
# Batch inference takes a single expected output column type. Use the first columns type for now.
|
441
|
-
label_cols_signatures = [
|
426
|
+
label_cols_signatures = [
|
427
|
+
row for row in self.model_signatures['predict'].outputs if row.name in self.output_cols
|
428
|
+
]
|
442
429
|
if len(label_cols_signatures) == 0:
|
443
430
|
error_str = f"Output columns {self.output_cols} do not match model signatures {self.model_signatures['predict'].outputs}."
|
444
431
|
raise exceptions.SnowflakeMLException(
|
@@ -446,25 +433,23 @@ class ExtraTreeRegressor(BaseTransformer):
|
|
446
433
|
original_exception=ValueError(error_str),
|
447
434
|
)
|
448
435
|
|
449
|
-
expected_type_inferred = convert_sp_to_sf_type(
|
450
|
-
label_cols_signatures[0].as_snowpark_type()
|
451
|
-
)
|
436
|
+
expected_type_inferred = convert_sp_to_sf_type(label_cols_signatures[0].as_snowpark_type())
|
452
437
|
|
453
|
-
self.
|
454
|
-
|
438
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
439
|
+
self._deps = self._get_dependencies()
|
440
|
+
assert isinstance(
|
441
|
+
dataset._session, Session
|
442
|
+
) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
455
443
|
|
456
444
|
transform_kwargs = dict(
|
457
|
-
session
|
458
|
-
dependencies
|
459
|
-
drop_input_cols
|
460
|
-
expected_output_cols_type
|
445
|
+
session=dataset._session,
|
446
|
+
dependencies=self._deps,
|
447
|
+
drop_input_cols=self._drop_input_cols,
|
448
|
+
expected_output_cols_type=expected_type_inferred,
|
461
449
|
)
|
462
450
|
|
463
451
|
elif isinstance(dataset, pd.DataFrame):
|
464
|
-
transform_kwargs = dict(
|
465
|
-
snowpark_input_cols = self._snowpark_cols,
|
466
|
-
drop_input_cols = self._drop_input_cols
|
467
|
-
)
|
452
|
+
transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
|
468
453
|
|
469
454
|
transform_handlers = ModelTransformerBuilder.build(
|
470
455
|
dataset=dataset,
|
@@ -504,7 +489,7 @@ class ExtraTreeRegressor(BaseTransformer):
|
|
504
489
|
Transformed dataset.
|
505
490
|
"""
|
506
491
|
super()._check_dataset_type(dataset)
|
507
|
-
inference_method="transform"
|
492
|
+
inference_method = "transform"
|
508
493
|
|
509
494
|
# This dictionary contains optional kwargs for batch inference. These kwargs
|
510
495
|
# are specific to the type of dataset used.
|
@@ -534,24 +519,19 @@ class ExtraTreeRegressor(BaseTransformer):
|
|
534
519
|
if all(x == output_types[0] for x in output_types) and len(output_types) == len(self.output_cols):
|
535
520
|
expected_dtype = convert_sp_to_sf_type(output_types[0])
|
536
521
|
|
537
|
-
self.
|
538
|
-
|
539
|
-
inference_method=inference_method,
|
540
|
-
)
|
522
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
523
|
+
self._deps = self._get_dependencies()
|
541
524
|
assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
542
525
|
|
543
526
|
transform_kwargs = dict(
|
544
|
-
session
|
545
|
-
dependencies
|
546
|
-
drop_input_cols
|
547
|
-
expected_output_cols_type
|
527
|
+
session=dataset._session,
|
528
|
+
dependencies=self._deps,
|
529
|
+
drop_input_cols=self._drop_input_cols,
|
530
|
+
expected_output_cols_type=expected_dtype,
|
548
531
|
)
|
549
532
|
|
550
533
|
elif isinstance(dataset, pd.DataFrame):
|
551
|
-
transform_kwargs = dict(
|
552
|
-
snowpark_input_cols = self._snowpark_cols,
|
553
|
-
drop_input_cols = self._drop_input_cols
|
554
|
-
)
|
534
|
+
transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
|
555
535
|
|
556
536
|
transform_handlers = ModelTransformerBuilder.build(
|
557
537
|
dataset=dataset,
|
@@ -570,7 +550,11 @@ class ExtraTreeRegressor(BaseTransformer):
|
|
570
550
|
return output_df
|
571
551
|
|
572
552
|
@available_if(original_estimator_has_callable("fit_predict")) # type: ignore[misc]
|
573
|
-
def fit_predict(
|
553
|
+
def fit_predict(
|
554
|
+
self,
|
555
|
+
dataset: Union[DataFrame, pd.DataFrame],
|
556
|
+
output_cols_prefix: str = "fit_predict_",
|
557
|
+
) -> Union[DataFrame, pd.DataFrame]:
|
574
558
|
""" Method not supported for this class.
|
575
559
|
|
576
560
|
|
@@ -595,22 +579,104 @@ class ExtraTreeRegressor(BaseTransformer):
|
|
595
579
|
)
|
596
580
|
output_result, fitted_estimator = model_trainer.train_fit_predict(
|
597
581
|
drop_input_cols=self._drop_input_cols,
|
598
|
-
expected_output_cols_list=
|
582
|
+
expected_output_cols_list=(
|
583
|
+
self.output_cols if self.output_cols else self._get_output_column_names(output_cols_prefix)
|
584
|
+
),
|
599
585
|
)
|
600
586
|
self._sklearn_object = fitted_estimator
|
601
587
|
self._is_fitted = True
|
602
588
|
return output_result
|
603
589
|
|
590
|
+
|
591
|
+
@available_if(original_estimator_has_callable("fit_transform")) # type: ignore[misc]
|
592
|
+
def fit_transform(self, dataset: Union[DataFrame, pd.DataFrame], output_cols_prefix: str = "fit_transform_",) -> Union[DataFrame, pd.DataFrame]:
|
593
|
+
""" Method not supported for this class.
|
594
|
+
|
604
595
|
|
605
|
-
|
606
|
-
|
607
|
-
|
596
|
+
Raises:
|
597
|
+
TypeError: Supported dataset types: snowpark.DataFrame, pandas.DataFrame.
|
598
|
+
|
599
|
+
Args:
|
600
|
+
dataset: Union[snowflake.snowpark.DataFrame, pandas.DataFrame]
|
601
|
+
Snowpark or Pandas DataFrame.
|
602
|
+
output_cols_prefix: Prefix for the response columns
|
608
603
|
Returns:
|
609
604
|
Transformed dataset.
|
610
605
|
"""
|
611
|
-
self.
|
612
|
-
|
613
|
-
|
606
|
+
self._infer_input_output_cols(dataset)
|
607
|
+
super()._check_dataset_type(dataset)
|
608
|
+
model_trainer = ModelTrainerBuilder.build_fit_transform(
|
609
|
+
estimator=self._sklearn_object,
|
610
|
+
dataset=dataset,
|
611
|
+
input_cols=self.input_cols,
|
612
|
+
label_cols=self.label_cols,
|
613
|
+
sample_weight_col=self.sample_weight_col,
|
614
|
+
autogenerated=self._autogenerated,
|
615
|
+
subproject=_SUBPROJECT,
|
616
|
+
)
|
617
|
+
output_result, fitted_estimator = model_trainer.train_fit_transform(
|
618
|
+
drop_input_cols=self._drop_input_cols,
|
619
|
+
expected_output_cols_list=self.output_cols,
|
620
|
+
)
|
621
|
+
self._sklearn_object = fitted_estimator
|
622
|
+
self._is_fitted = True
|
623
|
+
return output_result
|
624
|
+
|
625
|
+
|
626
|
+
def _get_output_column_names(self, output_cols_prefix: str, output_cols: Optional[List[str]] = None) -> List[str]:
|
627
|
+
""" Returns the list of output columns for predict_proba(), decision_function(), etc.. functions.
|
628
|
+
Returns a list with output_cols_prefix as the only element if the estimator is not a classifier.
|
629
|
+
"""
|
630
|
+
output_cols_prefix = identifier.resolve_identifier(output_cols_prefix)
|
631
|
+
# The following condition is introduced for kneighbors methods, and not used in other methods
|
632
|
+
if output_cols:
|
633
|
+
output_cols = [
|
634
|
+
identifier.concat_names([output_cols_prefix, identifier.resolve_identifier(c)])
|
635
|
+
for c in output_cols
|
636
|
+
]
|
637
|
+
elif getattr(self._sklearn_object, "classes_", None) is None:
|
638
|
+
output_cols = [output_cols_prefix]
|
639
|
+
elif self._sklearn_object is not None:
|
640
|
+
classes = self._sklearn_object.classes_
|
641
|
+
if isinstance(classes, numpy.ndarray):
|
642
|
+
output_cols = [f'{output_cols_prefix}{str(c)}' for c in classes.tolist()]
|
643
|
+
elif isinstance(classes, list) and len(classes) > 0 and isinstance(classes[0], numpy.ndarray):
|
644
|
+
# If the estimator is a multioutput estimator, classes_ will be a list of ndarrays.
|
645
|
+
output_cols = []
|
646
|
+
for i, cl in enumerate(classes):
|
647
|
+
# For binary classification, there is only one output column for each class
|
648
|
+
# ndarray as the two classes are complementary.
|
649
|
+
if len(cl) == 2:
|
650
|
+
output_cols.append(f'{output_cols_prefix}{i}_{cl[0]}')
|
651
|
+
else:
|
652
|
+
output_cols.extend([
|
653
|
+
f'{output_cols_prefix}{i}_{c}' for c in cl.tolist()
|
654
|
+
])
|
655
|
+
else:
|
656
|
+
output_cols = []
|
657
|
+
|
658
|
+
# Make sure column names are valid snowflake identifiers.
|
659
|
+
assert output_cols is not None # Make MyPy happy
|
660
|
+
rv = [identifier.rename_to_valid_snowflake_identifier(c) for c in output_cols]
|
661
|
+
|
662
|
+
return rv
|
663
|
+
|
664
|
+
def _align_expected_output_names(
|
665
|
+
self, method: str, dataset: DataFrame, expected_output_cols_list: List[str], output_cols_prefix: str
|
666
|
+
) -> List[str]:
|
667
|
+
# in case the inferred output column names dimension is different
|
668
|
+
# we use one line of snowpark dataframe and put it into sklearn estimator using pandas
|
669
|
+
output_df_pd = getattr(self, method)(dataset.limit(1).to_pandas(), output_cols_prefix)
|
670
|
+
output_df_columns = list(output_df_pd.columns)
|
671
|
+
output_df_columns_set: Set[str] = set(output_df_columns) - set(dataset.columns)
|
672
|
+
if self.sample_weight_col:
|
673
|
+
output_df_columns_set -= set(self.sample_weight_col)
|
674
|
+
# if the dimension of inferred output column names is correct; use it
|
675
|
+
if len(expected_output_cols_list) == len(output_df_columns_set):
|
676
|
+
return expected_output_cols_list
|
677
|
+
# otherwise, use the sklearn estimator's output
|
678
|
+
else:
|
679
|
+
return sorted(list(output_df_columns_set), key=lambda x: output_df_columns.index(x))
|
614
680
|
|
615
681
|
@available_if(original_estimator_has_callable("predict_proba")) # type: ignore[misc]
|
616
682
|
@telemetry.send_api_usage_telemetry(
|
@@ -642,24 +708,26 @@ class ExtraTreeRegressor(BaseTransformer):
|
|
642
708
|
# are specific to the type of dataset used.
|
643
709
|
transform_kwargs: BatchInferenceKwargsTypedDict = dict()
|
644
710
|
|
711
|
+
expected_output_cols = self._get_output_column_names(output_cols_prefix)
|
712
|
+
|
645
713
|
if isinstance(dataset, DataFrame):
|
646
|
-
self.
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
714
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
715
|
+
self._deps = self._get_dependencies()
|
716
|
+
assert isinstance(
|
717
|
+
dataset._session, Session
|
718
|
+
) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
651
719
|
transform_kwargs = dict(
|
652
720
|
session=dataset._session,
|
653
721
|
dependencies=self._deps,
|
654
|
-
drop_input_cols
|
722
|
+
drop_input_cols=self._drop_input_cols,
|
655
723
|
expected_output_cols_type="float",
|
656
724
|
)
|
725
|
+
expected_output_cols = self._align_expected_output_names(
|
726
|
+
inference_method, dataset, expected_output_cols, output_cols_prefix
|
727
|
+
)
|
657
728
|
|
658
729
|
elif isinstance(dataset, pd.DataFrame):
|
659
|
-
transform_kwargs = dict(
|
660
|
-
snowpark_input_cols = self._snowpark_cols,
|
661
|
-
drop_input_cols = self._drop_input_cols
|
662
|
-
)
|
730
|
+
transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
|
663
731
|
|
664
732
|
transform_handlers = ModelTransformerBuilder.build(
|
665
733
|
dataset=dataset,
|
@@ -671,7 +739,7 @@ class ExtraTreeRegressor(BaseTransformer):
|
|
671
739
|
output_df: DATAFRAME_TYPE = transform_handlers.batch_inference(
|
672
740
|
inference_method=inference_method,
|
673
741
|
input_cols=self.input_cols,
|
674
|
-
expected_output_cols=
|
742
|
+
expected_output_cols=expected_output_cols,
|
675
743
|
**transform_kwargs
|
676
744
|
)
|
677
745
|
return output_df
|
@@ -701,29 +769,30 @@ class ExtraTreeRegressor(BaseTransformer):
|
|
701
769
|
Output dataset with log probability of the sample for each class in the model.
|
702
770
|
"""
|
703
771
|
super()._check_dataset_type(dataset)
|
704
|
-
inference_method="predict_log_proba"
|
772
|
+
inference_method = "predict_log_proba"
|
773
|
+
expected_output_cols = self._get_output_column_names(output_cols_prefix)
|
705
774
|
|
706
775
|
# This dictionary contains optional kwargs for batch inference. These kwargs
|
707
776
|
# are specific to the type of dataset used.
|
708
777
|
transform_kwargs: BatchInferenceKwargsTypedDict = dict()
|
709
778
|
|
710
779
|
if isinstance(dataset, DataFrame):
|
711
|
-
self.
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
780
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
781
|
+
self._deps = self._get_dependencies()
|
782
|
+
assert isinstance(
|
783
|
+
dataset._session, Session
|
784
|
+
) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
716
785
|
transform_kwargs = dict(
|
717
786
|
session=dataset._session,
|
718
787
|
dependencies=self._deps,
|
719
|
-
drop_input_cols
|
788
|
+
drop_input_cols=self._drop_input_cols,
|
720
789
|
expected_output_cols_type="float",
|
721
790
|
)
|
791
|
+
expected_output_cols = self._align_expected_output_names(
|
792
|
+
inference_method, dataset, expected_output_cols, output_cols_prefix
|
793
|
+
)
|
722
794
|
elif isinstance(dataset, pd.DataFrame):
|
723
|
-
transform_kwargs = dict(
|
724
|
-
snowpark_input_cols = self._snowpark_cols,
|
725
|
-
drop_input_cols = self._drop_input_cols
|
726
|
-
)
|
795
|
+
transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
|
727
796
|
|
728
797
|
transform_handlers = ModelTransformerBuilder.build(
|
729
798
|
dataset=dataset,
|
@@ -736,7 +805,7 @@ class ExtraTreeRegressor(BaseTransformer):
|
|
736
805
|
output_df: DATAFRAME_TYPE = transform_handlers.batch_inference(
|
737
806
|
inference_method=inference_method,
|
738
807
|
input_cols=self.input_cols,
|
739
|
-
expected_output_cols=
|
808
|
+
expected_output_cols=expected_output_cols,
|
740
809
|
**transform_kwargs
|
741
810
|
)
|
742
811
|
return output_df
|
@@ -762,30 +831,32 @@ class ExtraTreeRegressor(BaseTransformer):
|
|
762
831
|
Output dataset with results of the decision function for the samples in input dataset.
|
763
832
|
"""
|
764
833
|
super()._check_dataset_type(dataset)
|
765
|
-
inference_method="decision_function"
|
834
|
+
inference_method = "decision_function"
|
766
835
|
|
767
836
|
# This dictionary contains optional kwargs for batch inference. These kwargs
|
768
837
|
# are specific to the type of dataset used.
|
769
838
|
transform_kwargs: BatchInferenceKwargsTypedDict = dict()
|
770
839
|
|
840
|
+
expected_output_cols = self._get_output_column_names(output_cols_prefix)
|
841
|
+
|
771
842
|
if isinstance(dataset, DataFrame):
|
772
|
-
self.
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
843
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
844
|
+
self._deps = self._get_dependencies()
|
845
|
+
assert isinstance(
|
846
|
+
dataset._session, Session
|
847
|
+
) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
777
848
|
transform_kwargs = dict(
|
778
849
|
session=dataset._session,
|
779
850
|
dependencies=self._deps,
|
780
|
-
drop_input_cols
|
851
|
+
drop_input_cols=self._drop_input_cols,
|
781
852
|
expected_output_cols_type="float",
|
782
853
|
)
|
854
|
+
expected_output_cols = self._align_expected_output_names(
|
855
|
+
inference_method, dataset, expected_output_cols, output_cols_prefix
|
856
|
+
)
|
783
857
|
|
784
858
|
elif isinstance(dataset, pd.DataFrame):
|
785
|
-
transform_kwargs = dict(
|
786
|
-
snowpark_input_cols = self._snowpark_cols,
|
787
|
-
drop_input_cols = self._drop_input_cols
|
788
|
-
)
|
859
|
+
transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
|
789
860
|
|
790
861
|
transform_handlers = ModelTransformerBuilder.build(
|
791
862
|
dataset=dataset,
|
@@ -798,7 +869,7 @@ class ExtraTreeRegressor(BaseTransformer):
|
|
798
869
|
output_df: DATAFRAME_TYPE = transform_handlers.batch_inference(
|
799
870
|
inference_method=inference_method,
|
800
871
|
input_cols=self.input_cols,
|
801
|
-
expected_output_cols=
|
872
|
+
expected_output_cols=expected_output_cols,
|
802
873
|
**transform_kwargs
|
803
874
|
)
|
804
875
|
return output_df
|
@@ -827,17 +898,17 @@ class ExtraTreeRegressor(BaseTransformer):
|
|
827
898
|
Output dataset with probability of the sample for each class in the model.
|
828
899
|
"""
|
829
900
|
super()._check_dataset_type(dataset)
|
830
|
-
inference_method="score_samples"
|
901
|
+
inference_method = "score_samples"
|
831
902
|
|
832
903
|
# This dictionary contains optional kwargs for batch inference. These kwargs
|
833
904
|
# are specific to the type of dataset used.
|
834
905
|
transform_kwargs: BatchInferenceKwargsTypedDict = dict()
|
835
906
|
|
907
|
+
expected_output_cols = self._get_output_column_names(output_cols_prefix)
|
908
|
+
|
836
909
|
if isinstance(dataset, DataFrame):
|
837
|
-
self.
|
838
|
-
|
839
|
-
inference_method=inference_method,
|
840
|
-
)
|
910
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
911
|
+
self._deps = self._get_dependencies()
|
841
912
|
assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
842
913
|
transform_kwargs = dict(
|
843
914
|
session=dataset._session,
|
@@ -845,6 +916,9 @@ class ExtraTreeRegressor(BaseTransformer):
|
|
845
916
|
drop_input_cols = self._drop_input_cols,
|
846
917
|
expected_output_cols_type="float",
|
847
918
|
)
|
919
|
+
expected_output_cols = self._align_expected_output_names(
|
920
|
+
inference_method, dataset, expected_output_cols, output_cols_prefix
|
921
|
+
)
|
848
922
|
|
849
923
|
elif isinstance(dataset, pd.DataFrame):
|
850
924
|
transform_kwargs = dict(
|
@@ -863,7 +937,7 @@ class ExtraTreeRegressor(BaseTransformer):
|
|
863
937
|
output_df: DATAFRAME_TYPE = transform_handlers.batch_inference(
|
864
938
|
inference_method=inference_method,
|
865
939
|
input_cols=self.input_cols,
|
866
|
-
expected_output_cols=
|
940
|
+
expected_output_cols=expected_output_cols,
|
867
941
|
**transform_kwargs
|
868
942
|
)
|
869
943
|
return output_df
|
@@ -898,17 +972,15 @@ class ExtraTreeRegressor(BaseTransformer):
|
|
898
972
|
transform_kwargs: ScoreKwargsTypedDict = dict()
|
899
973
|
|
900
974
|
if isinstance(dataset, DataFrame):
|
901
|
-
self.
|
902
|
-
|
903
|
-
inference_method="score",
|
904
|
-
)
|
975
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method="score")
|
976
|
+
self._deps = self._get_dependencies()
|
905
977
|
selected_cols = self._get_active_columns()
|
906
978
|
if len(selected_cols) > 0:
|
907
979
|
dataset = dataset.select(selected_cols)
|
908
980
|
assert isinstance(dataset._session, Session) # keep mypy happy
|
909
981
|
transform_kwargs = dict(
|
910
982
|
session=dataset._session,
|
911
|
-
dependencies=
|
983
|
+
dependencies=self._deps,
|
912
984
|
score_sproc_imports=['sklearn'],
|
913
985
|
)
|
914
986
|
elif isinstance(dataset, pd.DataFrame):
|
@@ -973,11 +1045,8 @@ class ExtraTreeRegressor(BaseTransformer):
|
|
973
1045
|
|
974
1046
|
if isinstance(dataset, DataFrame):
|
975
1047
|
|
976
|
-
self.
|
977
|
-
|
978
|
-
inference_method=inference_method,
|
979
|
-
|
980
|
-
)
|
1048
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
1049
|
+
self._deps = self._get_dependencies()
|
981
1050
|
assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
982
1051
|
transform_kwargs = dict(
|
983
1052
|
session = dataset._session,
|
@@ -1010,50 +1079,84 @@ class ExtraTreeRegressor(BaseTransformer):
|
|
1010
1079
|
)
|
1011
1080
|
return output_df
|
1012
1081
|
|
1082
|
+
|
1083
|
+
|
1084
|
+
def to_sklearn(self) -> Any:
|
1085
|
+
"""Get sklearn.tree.ExtraTreeRegressor object.
|
1086
|
+
"""
|
1087
|
+
if self._sklearn_object is None:
|
1088
|
+
self._sklearn_object = self._create_sklearn_object()
|
1089
|
+
return self._sklearn_object
|
1090
|
+
|
1091
|
+
def to_xgboost(self) -> Any:
|
1092
|
+
raise exceptions.SnowflakeMLException(
|
1093
|
+
error_code=error_codes.METHOD_NOT_ALLOWED,
|
1094
|
+
original_exception=AttributeError(
|
1095
|
+
modeling_error_messages.UNSUPPORTED_MODEL_CONVERSION.format(
|
1096
|
+
"to_xgboost()",
|
1097
|
+
"to_sklearn()"
|
1098
|
+
)
|
1099
|
+
),
|
1100
|
+
)
|
1101
|
+
|
1102
|
+
def to_lightgbm(self) -> Any:
|
1103
|
+
raise exceptions.SnowflakeMLException(
|
1104
|
+
error_code=error_codes.METHOD_NOT_ALLOWED,
|
1105
|
+
original_exception=AttributeError(
|
1106
|
+
modeling_error_messages.UNSUPPORTED_MODEL_CONVERSION.format(
|
1107
|
+
"to_lightgbm()",
|
1108
|
+
"to_sklearn()"
|
1109
|
+
)
|
1110
|
+
),
|
1111
|
+
)
|
1112
|
+
|
1113
|
+
def _get_dependencies(self) -> List[str]:
|
1114
|
+
return self._deps
|
1115
|
+
|
1013
1116
|
|
1014
|
-
def
|
1117
|
+
def _generate_model_signatures(self, dataset: Union[DataFrame, pd.DataFrame]) -> None:
|
1015
1118
|
self._model_signature_dict = dict()
|
1016
1119
|
|
1017
1120
|
PROB_FUNCTIONS = ["predict_log_proba", "predict_proba", "decision_function"]
|
1018
1121
|
|
1019
|
-
inputs = list(_infer_signature(dataset[self.input_cols], "input"))
|
1122
|
+
inputs = list(_infer_signature(dataset[self.input_cols], "input", use_snowflake_identifiers=True))
|
1020
1123
|
outputs: List[BaseFeatureSpec] = []
|
1021
1124
|
if hasattr(self, "predict"):
|
1022
1125
|
# keep mypy happy
|
1023
|
-
assert self._sklearn_object is not None and hasattr(self._sklearn_object, "_estimator_type")
|
1126
|
+
assert self._sklearn_object is not None and hasattr(self._sklearn_object, "_estimator_type")
|
1024
1127
|
# For classifier, the type of predict is the same as the type of label
|
1025
|
-
if self._sklearn_object._estimator_type ==
|
1026
|
-
|
1128
|
+
if self._sklearn_object._estimator_type == "classifier":
|
1129
|
+
# label columns is the desired type for output
|
1027
1130
|
outputs = list(_infer_signature(dataset[self.label_cols], "output", use_snowflake_identifiers=True))
|
1028
1131
|
# rename the output columns
|
1029
1132
|
outputs = list(model_signature_utils.rename_features(outputs, self.output_cols))
|
1030
|
-
self._model_signature_dict["predict"] = ModelSignature(
|
1031
|
-
|
1032
|
-
|
1133
|
+
self._model_signature_dict["predict"] = ModelSignature(
|
1134
|
+
inputs, ([] if self._drop_input_cols else inputs) + outputs
|
1135
|
+
)
|
1033
1136
|
# For mixture models that use the density mixin, `predict` returns the argmax of the log prob.
|
1034
1137
|
# For outlier models, returns -1 for outliers and 1 for inliers.
|
1035
|
-
# Clusterer returns int64 cluster labels.
|
1138
|
+
# Clusterer returns int64 cluster labels.
|
1036
1139
|
elif self._sklearn_object._estimator_type in ["DensityEstimator", "clusterer", "outlier_detector"]:
|
1037
1140
|
outputs = [FeatureSpec(dtype=DataType.INT64, name=c) for c in self.output_cols]
|
1038
|
-
self._model_signature_dict["predict"] = ModelSignature(
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1141
|
+
self._model_signature_dict["predict"] = ModelSignature(
|
1142
|
+
inputs, ([] if self._drop_input_cols else inputs) + outputs
|
1143
|
+
)
|
1144
|
+
|
1042
1145
|
# For regressor, the type of predict is float64
|
1043
|
-
elif self._sklearn_object._estimator_type ==
|
1146
|
+
elif self._sklearn_object._estimator_type == "regressor":
|
1044
1147
|
outputs = [FeatureSpec(dtype=DataType.DOUBLE, name=c) for c in self.output_cols]
|
1045
|
-
self._model_signature_dict["predict"] = ModelSignature(
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1148
|
+
self._model_signature_dict["predict"] = ModelSignature(
|
1149
|
+
inputs, ([] if self._drop_input_cols else inputs) + outputs
|
1150
|
+
)
|
1151
|
+
|
1049
1152
|
for prob_func in PROB_FUNCTIONS:
|
1050
1153
|
if hasattr(self, prob_func):
|
1051
1154
|
output_cols_prefix: str = f"{prob_func}_"
|
1052
1155
|
output_column_names = self._get_output_column_names(output_cols_prefix)
|
1053
1156
|
outputs = [FeatureSpec(dtype=DataType.DOUBLE, name=c) for c in output_column_names]
|
1054
|
-
self._model_signature_dict[prob_func] = ModelSignature(
|
1055
|
-
|
1056
|
-
|
1157
|
+
self._model_signature_dict[prob_func] = ModelSignature(
|
1158
|
+
inputs, ([] if self._drop_input_cols else inputs) + outputs
|
1159
|
+
)
|
1057
1160
|
|
1058
1161
|
# Output signature names may still need to be renamed, since they were not created with `_infer_signature`.
|
1059
1162
|
items = list(self._model_signature_dict.items())
|
@@ -1066,10 +1169,10 @@ class ExtraTreeRegressor(BaseTransformer):
|
|
1066
1169
|
"""Returns model signature of current class.
|
1067
1170
|
|
1068
1171
|
Raises:
|
1069
|
-
|
1172
|
+
SnowflakeMLException: If estimator is not fitted, then model signature cannot be inferred
|
1070
1173
|
|
1071
1174
|
Returns:
|
1072
|
-
Dict
|
1175
|
+
Dict with each method and its input output signature
|
1073
1176
|
"""
|
1074
1177
|
if self._model_signature_dict is None:
|
1075
1178
|
raise exceptions.SnowflakeMLException(
|
@@ -1077,35 +1180,3 @@ class ExtraTreeRegressor(BaseTransformer):
|
|
1077
1180
|
original_exception=RuntimeError("Estimator not fitted before accessing property model_signatures!"),
|
1078
1181
|
)
|
1079
1182
|
return self._model_signature_dict
|
1080
|
-
|
1081
|
-
def to_sklearn(self) -> Any:
|
1082
|
-
"""Get sklearn.tree.ExtraTreeRegressor object.
|
1083
|
-
"""
|
1084
|
-
if self._sklearn_object is None:
|
1085
|
-
self._sklearn_object = self._create_sklearn_object()
|
1086
|
-
return self._sklearn_object
|
1087
|
-
|
1088
|
-
def to_xgboost(self) -> Any:
|
1089
|
-
raise exceptions.SnowflakeMLException(
|
1090
|
-
error_code=error_codes.METHOD_NOT_ALLOWED,
|
1091
|
-
original_exception=AttributeError(
|
1092
|
-
modeling_error_messages.UNSUPPORTED_MODEL_CONVERSION.format(
|
1093
|
-
"to_xgboost()",
|
1094
|
-
"to_sklearn()"
|
1095
|
-
)
|
1096
|
-
),
|
1097
|
-
)
|
1098
|
-
|
1099
|
-
def to_lightgbm(self) -> Any:
|
1100
|
-
raise exceptions.SnowflakeMLException(
|
1101
|
-
error_code=error_codes.METHOD_NOT_ALLOWED,
|
1102
|
-
original_exception=AttributeError(
|
1103
|
-
modeling_error_messages.UNSUPPORTED_MODEL_CONVERSION.format(
|
1104
|
-
"to_lightgbm()",
|
1105
|
-
"to_sklearn()"
|
1106
|
-
)
|
1107
|
-
),
|
1108
|
-
)
|
1109
|
-
|
1110
|
-
def _get_dependencies(self) -> List[str]:
|
1111
|
-
return self._deps
|