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.linear_model".replace("s
|
|
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 Lasso(BaseTransformer):
|
71
64
|
r"""Linear Model trained with L1 prior as regularizer (aka the Lasso)
|
72
65
|
For more details on this class, see [sklearn.linear_model.Lasso]
|
@@ -262,12 +255,7 @@ class Lasso(BaseTransformer):
|
|
262
255
|
)
|
263
256
|
return selected_cols
|
264
257
|
|
265
|
-
|
266
|
-
project=_PROJECT,
|
267
|
-
subproject=_SUBPROJECT,
|
268
|
-
custom_tags=dict([("autogen", True)]),
|
269
|
-
)
|
270
|
-
def fit(self, dataset: Union[DataFrame, pd.DataFrame]) -> "Lasso":
|
258
|
+
def _fit(self, dataset: Union[DataFrame, pd.DataFrame]) -> "Lasso":
|
271
259
|
"""Fit model with coordinate descent
|
272
260
|
For more details on this function, see [sklearn.linear_model.Lasso.fit]
|
273
261
|
(https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.Lasso.html#sklearn.linear_model.Lasso.fit)
|
@@ -294,12 +282,14 @@ class Lasso(BaseTransformer):
|
|
294
282
|
|
295
283
|
self._snowpark_cols = dataset.select(self.input_cols).columns
|
296
284
|
|
297
|
-
|
285
|
+
# If we are already in a stored procedure, no need to kick off another one.
|
298
286
|
if SNOWML_SPROC_ENV in os.environ:
|
299
287
|
statement_params = telemetry.get_function_usage_statement_params(
|
300
288
|
project=_PROJECT,
|
301
289
|
subproject=_SUBPROJECT,
|
302
|
-
function_name=telemetry.get_statement_params_full_func_name(
|
290
|
+
function_name=telemetry.get_statement_params_full_func_name(
|
291
|
+
inspect.currentframe(), Lasso.__class__.__name__
|
292
|
+
),
|
303
293
|
api_calls=[Session.call],
|
304
294
|
custom_tags=dict([("autogen", True)]) if self._autogenerated else None,
|
305
295
|
)
|
@@ -320,27 +310,24 @@ class Lasso(BaseTransformer):
|
|
320
310
|
)
|
321
311
|
self._sklearn_object = model_trainer.train()
|
322
312
|
self._is_fitted = True
|
323
|
-
self.
|
313
|
+
self._generate_model_signatures(dataset)
|
324
314
|
return self
|
325
315
|
|
326
316
|
def _batch_inference_validate_snowpark(
|
327
317
|
self,
|
328
318
|
dataset: DataFrame,
|
329
319
|
inference_method: str,
|
330
|
-
) ->
|
331
|
-
"""Util method to run validate that batch inference can be run on a snowpark dataframe
|
332
|
-
return the available package that exists in the snowflake anaconda channel
|
320
|
+
) -> None:
|
321
|
+
"""Util method to run validate that batch inference can be run on a snowpark dataframe.
|
333
322
|
|
334
323
|
Args:
|
335
324
|
dataset: snowpark dataframe
|
336
325
|
inference_method: the inference method such as predict, score...
|
337
|
-
|
326
|
+
|
338
327
|
Raises:
|
339
328
|
SnowflakeMLException: If the estimator is not fitted, raise error
|
340
329
|
SnowflakeMLException: If the session is None, raise error
|
341
330
|
|
342
|
-
Returns:
|
343
|
-
A list of available package that exists in the snowflake anaconda channel
|
344
331
|
"""
|
345
332
|
if not self._is_fitted:
|
346
333
|
raise exceptions.SnowflakeMLException(
|
@@ -358,9 +345,7 @@ class Lasso(BaseTransformer):
|
|
358
345
|
"Session must not specified for snowpark dataset."
|
359
346
|
),
|
360
347
|
)
|
361
|
-
|
362
|
-
return pkg_version_utils.get_valid_pkg_versions_supported_in_snowflake_conda_channel(
|
363
|
-
pkg_versions=self._get_dependencies(), session=session, subproject=_SUBPROJECT)
|
348
|
+
|
364
349
|
|
365
350
|
@available_if(original_estimator_has_callable("predict")) # type: ignore[misc]
|
366
351
|
@telemetry.send_api_usage_telemetry(
|
@@ -396,7 +381,9 @@ class Lasso(BaseTransformer):
|
|
396
381
|
# when it is classifier, infer the datatype from label columns
|
397
382
|
if expected_type_inferred == "" and 'predict' in self.model_signatures:
|
398
383
|
# Batch inference takes a single expected output column type. Use the first columns type for now.
|
399
|
-
label_cols_signatures = [
|
384
|
+
label_cols_signatures = [
|
385
|
+
row for row in self.model_signatures['predict'].outputs if row.name in self.output_cols
|
386
|
+
]
|
400
387
|
if len(label_cols_signatures) == 0:
|
401
388
|
error_str = f"Output columns {self.output_cols} do not match model signatures {self.model_signatures['predict'].outputs}."
|
402
389
|
raise exceptions.SnowflakeMLException(
|
@@ -404,25 +391,23 @@ class Lasso(BaseTransformer):
|
|
404
391
|
original_exception=ValueError(error_str),
|
405
392
|
)
|
406
393
|
|
407
|
-
expected_type_inferred = convert_sp_to_sf_type(
|
408
|
-
label_cols_signatures[0].as_snowpark_type()
|
409
|
-
)
|
394
|
+
expected_type_inferred = convert_sp_to_sf_type(label_cols_signatures[0].as_snowpark_type())
|
410
395
|
|
411
|
-
self.
|
412
|
-
|
396
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
397
|
+
self._deps = self._get_dependencies()
|
398
|
+
assert isinstance(
|
399
|
+
dataset._session, Session
|
400
|
+
) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
413
401
|
|
414
402
|
transform_kwargs = dict(
|
415
|
-
session
|
416
|
-
dependencies
|
417
|
-
drop_input_cols
|
418
|
-
expected_output_cols_type
|
403
|
+
session=dataset._session,
|
404
|
+
dependencies=self._deps,
|
405
|
+
drop_input_cols=self._drop_input_cols,
|
406
|
+
expected_output_cols_type=expected_type_inferred,
|
419
407
|
)
|
420
408
|
|
421
409
|
elif isinstance(dataset, pd.DataFrame):
|
422
|
-
transform_kwargs = dict(
|
423
|
-
snowpark_input_cols = self._snowpark_cols,
|
424
|
-
drop_input_cols = self._drop_input_cols
|
425
|
-
)
|
410
|
+
transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
|
426
411
|
|
427
412
|
transform_handlers = ModelTransformerBuilder.build(
|
428
413
|
dataset=dataset,
|
@@ -462,7 +447,7 @@ class Lasso(BaseTransformer):
|
|
462
447
|
Transformed dataset.
|
463
448
|
"""
|
464
449
|
super()._check_dataset_type(dataset)
|
465
|
-
inference_method="transform"
|
450
|
+
inference_method = "transform"
|
466
451
|
|
467
452
|
# This dictionary contains optional kwargs for batch inference. These kwargs
|
468
453
|
# are specific to the type of dataset used.
|
@@ -492,24 +477,19 @@ class Lasso(BaseTransformer):
|
|
492
477
|
if all(x == output_types[0] for x in output_types) and len(output_types) == len(self.output_cols):
|
493
478
|
expected_dtype = convert_sp_to_sf_type(output_types[0])
|
494
479
|
|
495
|
-
self.
|
496
|
-
|
497
|
-
inference_method=inference_method,
|
498
|
-
)
|
480
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
481
|
+
self._deps = self._get_dependencies()
|
499
482
|
assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
500
483
|
|
501
484
|
transform_kwargs = dict(
|
502
|
-
session
|
503
|
-
dependencies
|
504
|
-
drop_input_cols
|
505
|
-
expected_output_cols_type
|
485
|
+
session=dataset._session,
|
486
|
+
dependencies=self._deps,
|
487
|
+
drop_input_cols=self._drop_input_cols,
|
488
|
+
expected_output_cols_type=expected_dtype,
|
506
489
|
)
|
507
490
|
|
508
491
|
elif isinstance(dataset, pd.DataFrame):
|
509
|
-
transform_kwargs = dict(
|
510
|
-
snowpark_input_cols = self._snowpark_cols,
|
511
|
-
drop_input_cols = self._drop_input_cols
|
512
|
-
)
|
492
|
+
transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
|
513
493
|
|
514
494
|
transform_handlers = ModelTransformerBuilder.build(
|
515
495
|
dataset=dataset,
|
@@ -528,7 +508,11 @@ class Lasso(BaseTransformer):
|
|
528
508
|
return output_df
|
529
509
|
|
530
510
|
@available_if(original_estimator_has_callable("fit_predict")) # type: ignore[misc]
|
531
|
-
def fit_predict(
|
511
|
+
def fit_predict(
|
512
|
+
self,
|
513
|
+
dataset: Union[DataFrame, pd.DataFrame],
|
514
|
+
output_cols_prefix: str = "fit_predict_",
|
515
|
+
) -> Union[DataFrame, pd.DataFrame]:
|
532
516
|
""" Method not supported for this class.
|
533
517
|
|
534
518
|
|
@@ -553,22 +537,104 @@ class Lasso(BaseTransformer):
|
|
553
537
|
)
|
554
538
|
output_result, fitted_estimator = model_trainer.train_fit_predict(
|
555
539
|
drop_input_cols=self._drop_input_cols,
|
556
|
-
expected_output_cols_list=
|
540
|
+
expected_output_cols_list=(
|
541
|
+
self.output_cols if self.output_cols else self._get_output_column_names(output_cols_prefix)
|
542
|
+
),
|
557
543
|
)
|
558
544
|
self._sklearn_object = fitted_estimator
|
559
545
|
self._is_fitted = True
|
560
546
|
return output_result
|
561
547
|
|
548
|
+
|
549
|
+
@available_if(original_estimator_has_callable("fit_transform")) # type: ignore[misc]
|
550
|
+
def fit_transform(self, dataset: Union[DataFrame, pd.DataFrame], output_cols_prefix: str = "fit_transform_",) -> Union[DataFrame, pd.DataFrame]:
|
551
|
+
""" Method not supported for this class.
|
552
|
+
|
562
553
|
|
563
|
-
|
564
|
-
|
565
|
-
|
554
|
+
Raises:
|
555
|
+
TypeError: Supported dataset types: snowpark.DataFrame, pandas.DataFrame.
|
556
|
+
|
557
|
+
Args:
|
558
|
+
dataset: Union[snowflake.snowpark.DataFrame, pandas.DataFrame]
|
559
|
+
Snowpark or Pandas DataFrame.
|
560
|
+
output_cols_prefix: Prefix for the response columns
|
566
561
|
Returns:
|
567
562
|
Transformed dataset.
|
568
563
|
"""
|
569
|
-
self.
|
570
|
-
|
571
|
-
|
564
|
+
self._infer_input_output_cols(dataset)
|
565
|
+
super()._check_dataset_type(dataset)
|
566
|
+
model_trainer = ModelTrainerBuilder.build_fit_transform(
|
567
|
+
estimator=self._sklearn_object,
|
568
|
+
dataset=dataset,
|
569
|
+
input_cols=self.input_cols,
|
570
|
+
label_cols=self.label_cols,
|
571
|
+
sample_weight_col=self.sample_weight_col,
|
572
|
+
autogenerated=self._autogenerated,
|
573
|
+
subproject=_SUBPROJECT,
|
574
|
+
)
|
575
|
+
output_result, fitted_estimator = model_trainer.train_fit_transform(
|
576
|
+
drop_input_cols=self._drop_input_cols,
|
577
|
+
expected_output_cols_list=self.output_cols,
|
578
|
+
)
|
579
|
+
self._sklearn_object = fitted_estimator
|
580
|
+
self._is_fitted = True
|
581
|
+
return output_result
|
582
|
+
|
583
|
+
|
584
|
+
def _get_output_column_names(self, output_cols_prefix: str, output_cols: Optional[List[str]] = None) -> List[str]:
|
585
|
+
""" Returns the list of output columns for predict_proba(), decision_function(), etc.. functions.
|
586
|
+
Returns a list with output_cols_prefix as the only element if the estimator is not a classifier.
|
587
|
+
"""
|
588
|
+
output_cols_prefix = identifier.resolve_identifier(output_cols_prefix)
|
589
|
+
# The following condition is introduced for kneighbors methods, and not used in other methods
|
590
|
+
if output_cols:
|
591
|
+
output_cols = [
|
592
|
+
identifier.concat_names([output_cols_prefix, identifier.resolve_identifier(c)])
|
593
|
+
for c in output_cols
|
594
|
+
]
|
595
|
+
elif getattr(self._sklearn_object, "classes_", None) is None:
|
596
|
+
output_cols = [output_cols_prefix]
|
597
|
+
elif self._sklearn_object is not None:
|
598
|
+
classes = self._sklearn_object.classes_
|
599
|
+
if isinstance(classes, numpy.ndarray):
|
600
|
+
output_cols = [f'{output_cols_prefix}{str(c)}' for c in classes.tolist()]
|
601
|
+
elif isinstance(classes, list) and len(classes) > 0 and isinstance(classes[0], numpy.ndarray):
|
602
|
+
# If the estimator is a multioutput estimator, classes_ will be a list of ndarrays.
|
603
|
+
output_cols = []
|
604
|
+
for i, cl in enumerate(classes):
|
605
|
+
# For binary classification, there is only one output column for each class
|
606
|
+
# ndarray as the two classes are complementary.
|
607
|
+
if len(cl) == 2:
|
608
|
+
output_cols.append(f'{output_cols_prefix}{i}_{cl[0]}')
|
609
|
+
else:
|
610
|
+
output_cols.extend([
|
611
|
+
f'{output_cols_prefix}{i}_{c}' for c in cl.tolist()
|
612
|
+
])
|
613
|
+
else:
|
614
|
+
output_cols = []
|
615
|
+
|
616
|
+
# Make sure column names are valid snowflake identifiers.
|
617
|
+
assert output_cols is not None # Make MyPy happy
|
618
|
+
rv = [identifier.rename_to_valid_snowflake_identifier(c) for c in output_cols]
|
619
|
+
|
620
|
+
return rv
|
621
|
+
|
622
|
+
def _align_expected_output_names(
|
623
|
+
self, method: str, dataset: DataFrame, expected_output_cols_list: List[str], output_cols_prefix: str
|
624
|
+
) -> List[str]:
|
625
|
+
# in case the inferred output column names dimension is different
|
626
|
+
# we use one line of snowpark dataframe and put it into sklearn estimator using pandas
|
627
|
+
output_df_pd = getattr(self, method)(dataset.limit(1).to_pandas(), output_cols_prefix)
|
628
|
+
output_df_columns = list(output_df_pd.columns)
|
629
|
+
output_df_columns_set: Set[str] = set(output_df_columns) - set(dataset.columns)
|
630
|
+
if self.sample_weight_col:
|
631
|
+
output_df_columns_set -= set(self.sample_weight_col)
|
632
|
+
# if the dimension of inferred output column names is correct; use it
|
633
|
+
if len(expected_output_cols_list) == len(output_df_columns_set):
|
634
|
+
return expected_output_cols_list
|
635
|
+
# otherwise, use the sklearn estimator's output
|
636
|
+
else:
|
637
|
+
return sorted(list(output_df_columns_set), key=lambda x: output_df_columns.index(x))
|
572
638
|
|
573
639
|
@available_if(original_estimator_has_callable("predict_proba")) # type: ignore[misc]
|
574
640
|
@telemetry.send_api_usage_telemetry(
|
@@ -600,24 +666,26 @@ class Lasso(BaseTransformer):
|
|
600
666
|
# are specific to the type of dataset used.
|
601
667
|
transform_kwargs: BatchInferenceKwargsTypedDict = dict()
|
602
668
|
|
669
|
+
expected_output_cols = self._get_output_column_names(output_cols_prefix)
|
670
|
+
|
603
671
|
if isinstance(dataset, DataFrame):
|
604
|
-
self.
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
672
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
673
|
+
self._deps = self._get_dependencies()
|
674
|
+
assert isinstance(
|
675
|
+
dataset._session, Session
|
676
|
+
) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
609
677
|
transform_kwargs = dict(
|
610
678
|
session=dataset._session,
|
611
679
|
dependencies=self._deps,
|
612
|
-
drop_input_cols
|
680
|
+
drop_input_cols=self._drop_input_cols,
|
613
681
|
expected_output_cols_type="float",
|
614
682
|
)
|
683
|
+
expected_output_cols = self._align_expected_output_names(
|
684
|
+
inference_method, dataset, expected_output_cols, output_cols_prefix
|
685
|
+
)
|
615
686
|
|
616
687
|
elif isinstance(dataset, pd.DataFrame):
|
617
|
-
transform_kwargs = dict(
|
618
|
-
snowpark_input_cols = self._snowpark_cols,
|
619
|
-
drop_input_cols = self._drop_input_cols
|
620
|
-
)
|
688
|
+
transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
|
621
689
|
|
622
690
|
transform_handlers = ModelTransformerBuilder.build(
|
623
691
|
dataset=dataset,
|
@@ -629,7 +697,7 @@ class Lasso(BaseTransformer):
|
|
629
697
|
output_df: DATAFRAME_TYPE = transform_handlers.batch_inference(
|
630
698
|
inference_method=inference_method,
|
631
699
|
input_cols=self.input_cols,
|
632
|
-
expected_output_cols=
|
700
|
+
expected_output_cols=expected_output_cols,
|
633
701
|
**transform_kwargs
|
634
702
|
)
|
635
703
|
return output_df
|
@@ -659,29 +727,30 @@ class Lasso(BaseTransformer):
|
|
659
727
|
Output dataset with log probability of the sample for each class in the model.
|
660
728
|
"""
|
661
729
|
super()._check_dataset_type(dataset)
|
662
|
-
inference_method="predict_log_proba"
|
730
|
+
inference_method = "predict_log_proba"
|
731
|
+
expected_output_cols = self._get_output_column_names(output_cols_prefix)
|
663
732
|
|
664
733
|
# This dictionary contains optional kwargs for batch inference. These kwargs
|
665
734
|
# are specific to the type of dataset used.
|
666
735
|
transform_kwargs: BatchInferenceKwargsTypedDict = dict()
|
667
736
|
|
668
737
|
if isinstance(dataset, DataFrame):
|
669
|
-
self.
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
738
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
739
|
+
self._deps = self._get_dependencies()
|
740
|
+
assert isinstance(
|
741
|
+
dataset._session, Session
|
742
|
+
) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
674
743
|
transform_kwargs = dict(
|
675
744
|
session=dataset._session,
|
676
745
|
dependencies=self._deps,
|
677
|
-
drop_input_cols
|
746
|
+
drop_input_cols=self._drop_input_cols,
|
678
747
|
expected_output_cols_type="float",
|
679
748
|
)
|
749
|
+
expected_output_cols = self._align_expected_output_names(
|
750
|
+
inference_method, dataset, expected_output_cols, output_cols_prefix
|
751
|
+
)
|
680
752
|
elif isinstance(dataset, pd.DataFrame):
|
681
|
-
transform_kwargs = dict(
|
682
|
-
snowpark_input_cols = self._snowpark_cols,
|
683
|
-
drop_input_cols = self._drop_input_cols
|
684
|
-
)
|
753
|
+
transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
|
685
754
|
|
686
755
|
transform_handlers = ModelTransformerBuilder.build(
|
687
756
|
dataset=dataset,
|
@@ -694,7 +763,7 @@ class Lasso(BaseTransformer):
|
|
694
763
|
output_df: DATAFRAME_TYPE = transform_handlers.batch_inference(
|
695
764
|
inference_method=inference_method,
|
696
765
|
input_cols=self.input_cols,
|
697
|
-
expected_output_cols=
|
766
|
+
expected_output_cols=expected_output_cols,
|
698
767
|
**transform_kwargs
|
699
768
|
)
|
700
769
|
return output_df
|
@@ -720,30 +789,32 @@ class Lasso(BaseTransformer):
|
|
720
789
|
Output dataset with results of the decision function for the samples in input dataset.
|
721
790
|
"""
|
722
791
|
super()._check_dataset_type(dataset)
|
723
|
-
inference_method="decision_function"
|
792
|
+
inference_method = "decision_function"
|
724
793
|
|
725
794
|
# This dictionary contains optional kwargs for batch inference. These kwargs
|
726
795
|
# are specific to the type of dataset used.
|
727
796
|
transform_kwargs: BatchInferenceKwargsTypedDict = dict()
|
728
797
|
|
798
|
+
expected_output_cols = self._get_output_column_names(output_cols_prefix)
|
799
|
+
|
729
800
|
if isinstance(dataset, DataFrame):
|
730
|
-
self.
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
801
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
802
|
+
self._deps = self._get_dependencies()
|
803
|
+
assert isinstance(
|
804
|
+
dataset._session, Session
|
805
|
+
) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
735
806
|
transform_kwargs = dict(
|
736
807
|
session=dataset._session,
|
737
808
|
dependencies=self._deps,
|
738
|
-
drop_input_cols
|
809
|
+
drop_input_cols=self._drop_input_cols,
|
739
810
|
expected_output_cols_type="float",
|
740
811
|
)
|
812
|
+
expected_output_cols = self._align_expected_output_names(
|
813
|
+
inference_method, dataset, expected_output_cols, output_cols_prefix
|
814
|
+
)
|
741
815
|
|
742
816
|
elif isinstance(dataset, pd.DataFrame):
|
743
|
-
transform_kwargs = dict(
|
744
|
-
snowpark_input_cols = self._snowpark_cols,
|
745
|
-
drop_input_cols = self._drop_input_cols
|
746
|
-
)
|
817
|
+
transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
|
747
818
|
|
748
819
|
transform_handlers = ModelTransformerBuilder.build(
|
749
820
|
dataset=dataset,
|
@@ -756,7 +827,7 @@ class Lasso(BaseTransformer):
|
|
756
827
|
output_df: DATAFRAME_TYPE = transform_handlers.batch_inference(
|
757
828
|
inference_method=inference_method,
|
758
829
|
input_cols=self.input_cols,
|
759
|
-
expected_output_cols=
|
830
|
+
expected_output_cols=expected_output_cols,
|
760
831
|
**transform_kwargs
|
761
832
|
)
|
762
833
|
return output_df
|
@@ -785,17 +856,17 @@ class Lasso(BaseTransformer):
|
|
785
856
|
Output dataset with probability of the sample for each class in the model.
|
786
857
|
"""
|
787
858
|
super()._check_dataset_type(dataset)
|
788
|
-
inference_method="score_samples"
|
859
|
+
inference_method = "score_samples"
|
789
860
|
|
790
861
|
# This dictionary contains optional kwargs for batch inference. These kwargs
|
791
862
|
# are specific to the type of dataset used.
|
792
863
|
transform_kwargs: BatchInferenceKwargsTypedDict = dict()
|
793
864
|
|
865
|
+
expected_output_cols = self._get_output_column_names(output_cols_prefix)
|
866
|
+
|
794
867
|
if isinstance(dataset, DataFrame):
|
795
|
-
self.
|
796
|
-
|
797
|
-
inference_method=inference_method,
|
798
|
-
)
|
868
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
869
|
+
self._deps = self._get_dependencies()
|
799
870
|
assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
800
871
|
transform_kwargs = dict(
|
801
872
|
session=dataset._session,
|
@@ -803,6 +874,9 @@ class Lasso(BaseTransformer):
|
|
803
874
|
drop_input_cols = self._drop_input_cols,
|
804
875
|
expected_output_cols_type="float",
|
805
876
|
)
|
877
|
+
expected_output_cols = self._align_expected_output_names(
|
878
|
+
inference_method, dataset, expected_output_cols, output_cols_prefix
|
879
|
+
)
|
806
880
|
|
807
881
|
elif isinstance(dataset, pd.DataFrame):
|
808
882
|
transform_kwargs = dict(
|
@@ -821,7 +895,7 @@ class Lasso(BaseTransformer):
|
|
821
895
|
output_df: DATAFRAME_TYPE = transform_handlers.batch_inference(
|
822
896
|
inference_method=inference_method,
|
823
897
|
input_cols=self.input_cols,
|
824
|
-
expected_output_cols=
|
898
|
+
expected_output_cols=expected_output_cols,
|
825
899
|
**transform_kwargs
|
826
900
|
)
|
827
901
|
return output_df
|
@@ -856,17 +930,15 @@ class Lasso(BaseTransformer):
|
|
856
930
|
transform_kwargs: ScoreKwargsTypedDict = dict()
|
857
931
|
|
858
932
|
if isinstance(dataset, DataFrame):
|
859
|
-
self.
|
860
|
-
|
861
|
-
inference_method="score",
|
862
|
-
)
|
933
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method="score")
|
934
|
+
self._deps = self._get_dependencies()
|
863
935
|
selected_cols = self._get_active_columns()
|
864
936
|
if len(selected_cols) > 0:
|
865
937
|
dataset = dataset.select(selected_cols)
|
866
938
|
assert isinstance(dataset._session, Session) # keep mypy happy
|
867
939
|
transform_kwargs = dict(
|
868
940
|
session=dataset._session,
|
869
|
-
dependencies=
|
941
|
+
dependencies=self._deps,
|
870
942
|
score_sproc_imports=['sklearn'],
|
871
943
|
)
|
872
944
|
elif isinstance(dataset, pd.DataFrame):
|
@@ -931,11 +1003,8 @@ class Lasso(BaseTransformer):
|
|
931
1003
|
|
932
1004
|
if isinstance(dataset, DataFrame):
|
933
1005
|
|
934
|
-
self.
|
935
|
-
|
936
|
-
inference_method=inference_method,
|
937
|
-
|
938
|
-
)
|
1006
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
1007
|
+
self._deps = self._get_dependencies()
|
939
1008
|
assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
940
1009
|
transform_kwargs = dict(
|
941
1010
|
session = dataset._session,
|
@@ -968,50 +1037,84 @@ class Lasso(BaseTransformer):
|
|
968
1037
|
)
|
969
1038
|
return output_df
|
970
1039
|
|
1040
|
+
|
1041
|
+
|
1042
|
+
def to_sklearn(self) -> Any:
|
1043
|
+
"""Get sklearn.linear_model.Lasso object.
|
1044
|
+
"""
|
1045
|
+
if self._sklearn_object is None:
|
1046
|
+
self._sklearn_object = self._create_sklearn_object()
|
1047
|
+
return self._sklearn_object
|
1048
|
+
|
1049
|
+
def to_xgboost(self) -> Any:
|
1050
|
+
raise exceptions.SnowflakeMLException(
|
1051
|
+
error_code=error_codes.METHOD_NOT_ALLOWED,
|
1052
|
+
original_exception=AttributeError(
|
1053
|
+
modeling_error_messages.UNSUPPORTED_MODEL_CONVERSION.format(
|
1054
|
+
"to_xgboost()",
|
1055
|
+
"to_sklearn()"
|
1056
|
+
)
|
1057
|
+
),
|
1058
|
+
)
|
1059
|
+
|
1060
|
+
def to_lightgbm(self) -> Any:
|
1061
|
+
raise exceptions.SnowflakeMLException(
|
1062
|
+
error_code=error_codes.METHOD_NOT_ALLOWED,
|
1063
|
+
original_exception=AttributeError(
|
1064
|
+
modeling_error_messages.UNSUPPORTED_MODEL_CONVERSION.format(
|
1065
|
+
"to_lightgbm()",
|
1066
|
+
"to_sklearn()"
|
1067
|
+
)
|
1068
|
+
),
|
1069
|
+
)
|
1070
|
+
|
1071
|
+
def _get_dependencies(self) -> List[str]:
|
1072
|
+
return self._deps
|
1073
|
+
|
971
1074
|
|
972
|
-
def
|
1075
|
+
def _generate_model_signatures(self, dataset: Union[DataFrame, pd.DataFrame]) -> None:
|
973
1076
|
self._model_signature_dict = dict()
|
974
1077
|
|
975
1078
|
PROB_FUNCTIONS = ["predict_log_proba", "predict_proba", "decision_function"]
|
976
1079
|
|
977
|
-
inputs = list(_infer_signature(dataset[self.input_cols], "input"))
|
1080
|
+
inputs = list(_infer_signature(dataset[self.input_cols], "input", use_snowflake_identifiers=True))
|
978
1081
|
outputs: List[BaseFeatureSpec] = []
|
979
1082
|
if hasattr(self, "predict"):
|
980
1083
|
# keep mypy happy
|
981
|
-
assert self._sklearn_object is not None and hasattr(self._sklearn_object, "_estimator_type")
|
1084
|
+
assert self._sklearn_object is not None and hasattr(self._sklearn_object, "_estimator_type")
|
982
1085
|
# For classifier, the type of predict is the same as the type of label
|
983
|
-
if self._sklearn_object._estimator_type ==
|
984
|
-
|
1086
|
+
if self._sklearn_object._estimator_type == "classifier":
|
1087
|
+
# label columns is the desired type for output
|
985
1088
|
outputs = list(_infer_signature(dataset[self.label_cols], "output", use_snowflake_identifiers=True))
|
986
1089
|
# rename the output columns
|
987
1090
|
outputs = list(model_signature_utils.rename_features(outputs, self.output_cols))
|
988
|
-
self._model_signature_dict["predict"] = ModelSignature(
|
989
|
-
|
990
|
-
|
1091
|
+
self._model_signature_dict["predict"] = ModelSignature(
|
1092
|
+
inputs, ([] if self._drop_input_cols else inputs) + outputs
|
1093
|
+
)
|
991
1094
|
# For mixture models that use the density mixin, `predict` returns the argmax of the log prob.
|
992
1095
|
# For outlier models, returns -1 for outliers and 1 for inliers.
|
993
|
-
# Clusterer returns int64 cluster labels.
|
1096
|
+
# Clusterer returns int64 cluster labels.
|
994
1097
|
elif self._sklearn_object._estimator_type in ["DensityEstimator", "clusterer", "outlier_detector"]:
|
995
1098
|
outputs = [FeatureSpec(dtype=DataType.INT64, name=c) for c in self.output_cols]
|
996
|
-
self._model_signature_dict["predict"] = ModelSignature(
|
997
|
-
|
998
|
-
|
999
|
-
|
1099
|
+
self._model_signature_dict["predict"] = ModelSignature(
|
1100
|
+
inputs, ([] if self._drop_input_cols else inputs) + outputs
|
1101
|
+
)
|
1102
|
+
|
1000
1103
|
# For regressor, the type of predict is float64
|
1001
|
-
elif self._sklearn_object._estimator_type ==
|
1104
|
+
elif self._sklearn_object._estimator_type == "regressor":
|
1002
1105
|
outputs = [FeatureSpec(dtype=DataType.DOUBLE, name=c) for c in self.output_cols]
|
1003
|
-
self._model_signature_dict["predict"] = ModelSignature(
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1106
|
+
self._model_signature_dict["predict"] = ModelSignature(
|
1107
|
+
inputs, ([] if self._drop_input_cols else inputs) + outputs
|
1108
|
+
)
|
1109
|
+
|
1007
1110
|
for prob_func in PROB_FUNCTIONS:
|
1008
1111
|
if hasattr(self, prob_func):
|
1009
1112
|
output_cols_prefix: str = f"{prob_func}_"
|
1010
1113
|
output_column_names = self._get_output_column_names(output_cols_prefix)
|
1011
1114
|
outputs = [FeatureSpec(dtype=DataType.DOUBLE, name=c) for c in output_column_names]
|
1012
|
-
self._model_signature_dict[prob_func] = ModelSignature(
|
1013
|
-
|
1014
|
-
|
1115
|
+
self._model_signature_dict[prob_func] = ModelSignature(
|
1116
|
+
inputs, ([] if self._drop_input_cols else inputs) + outputs
|
1117
|
+
)
|
1015
1118
|
|
1016
1119
|
# Output signature names may still need to be renamed, since they were not created with `_infer_signature`.
|
1017
1120
|
items = list(self._model_signature_dict.items())
|
@@ -1024,10 +1127,10 @@ class Lasso(BaseTransformer):
|
|
1024
1127
|
"""Returns model signature of current class.
|
1025
1128
|
|
1026
1129
|
Raises:
|
1027
|
-
|
1130
|
+
SnowflakeMLException: If estimator is not fitted, then model signature cannot be inferred
|
1028
1131
|
|
1029
1132
|
Returns:
|
1030
|
-
Dict
|
1133
|
+
Dict with each method and its input output signature
|
1031
1134
|
"""
|
1032
1135
|
if self._model_signature_dict is None:
|
1033
1136
|
raise exceptions.SnowflakeMLException(
|
@@ -1035,35 +1138,3 @@ class Lasso(BaseTransformer):
|
|
1035
1138
|
original_exception=RuntimeError("Estimator not fitted before accessing property model_signatures!"),
|
1036
1139
|
)
|
1037
1140
|
return self._model_signature_dict
|
1038
|
-
|
1039
|
-
def to_sklearn(self) -> Any:
|
1040
|
-
"""Get sklearn.linear_model.Lasso object.
|
1041
|
-
"""
|
1042
|
-
if self._sklearn_object is None:
|
1043
|
-
self._sklearn_object = self._create_sklearn_object()
|
1044
|
-
return self._sklearn_object
|
1045
|
-
|
1046
|
-
def to_xgboost(self) -> Any:
|
1047
|
-
raise exceptions.SnowflakeMLException(
|
1048
|
-
error_code=error_codes.METHOD_NOT_ALLOWED,
|
1049
|
-
original_exception=AttributeError(
|
1050
|
-
modeling_error_messages.UNSUPPORTED_MODEL_CONVERSION.format(
|
1051
|
-
"to_xgboost()",
|
1052
|
-
"to_sklearn()"
|
1053
|
-
)
|
1054
|
-
),
|
1055
|
-
)
|
1056
|
-
|
1057
|
-
def to_lightgbm(self) -> Any:
|
1058
|
-
raise exceptions.SnowflakeMLException(
|
1059
|
-
error_code=error_codes.METHOD_NOT_ALLOWED,
|
1060
|
-
original_exception=AttributeError(
|
1061
|
-
modeling_error_messages.UNSUPPORTED_MODEL_CONVERSION.format(
|
1062
|
-
"to_lightgbm()",
|
1063
|
-
"to_sklearn()"
|
1064
|
-
)
|
1065
|
-
),
|
1066
|
-
)
|
1067
|
-
|
1068
|
-
def _get_dependencies(self) -> List[str]:
|
1069
|
-
return self._deps
|