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