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 SGDClassifier(BaseTransformer):
|
71
64
|
r"""Linear classifiers (SVM, logistic regression, etc
|
72
65
|
For more details on this class, see [sklearn.linear_model.SGDClassifier]
|
@@ -388,12 +381,7 @@ class SGDClassifier(BaseTransformer):
|
|
388
381
|
)
|
389
382
|
return selected_cols
|
390
383
|
|
391
|
-
|
392
|
-
project=_PROJECT,
|
393
|
-
subproject=_SUBPROJECT,
|
394
|
-
custom_tags=dict([("autogen", True)]),
|
395
|
-
)
|
396
|
-
def fit(self, dataset: Union[DataFrame, pd.DataFrame]) -> "SGDClassifier":
|
384
|
+
def _fit(self, dataset: Union[DataFrame, pd.DataFrame]) -> "SGDClassifier":
|
397
385
|
"""Fit linear model with Stochastic Gradient Descent
|
398
386
|
For more details on this function, see [sklearn.linear_model.SGDClassifier.fit]
|
399
387
|
(https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.SGDClassifier.html#sklearn.linear_model.SGDClassifier.fit)
|
@@ -420,12 +408,14 @@ class SGDClassifier(BaseTransformer):
|
|
420
408
|
|
421
409
|
self._snowpark_cols = dataset.select(self.input_cols).columns
|
422
410
|
|
423
|
-
|
411
|
+
# If we are already in a stored procedure, no need to kick off another one.
|
424
412
|
if SNOWML_SPROC_ENV in os.environ:
|
425
413
|
statement_params = telemetry.get_function_usage_statement_params(
|
426
414
|
project=_PROJECT,
|
427
415
|
subproject=_SUBPROJECT,
|
428
|
-
function_name=telemetry.get_statement_params_full_func_name(
|
416
|
+
function_name=telemetry.get_statement_params_full_func_name(
|
417
|
+
inspect.currentframe(), SGDClassifier.__class__.__name__
|
418
|
+
),
|
429
419
|
api_calls=[Session.call],
|
430
420
|
custom_tags=dict([("autogen", True)]) if self._autogenerated else None,
|
431
421
|
)
|
@@ -446,27 +436,24 @@ class SGDClassifier(BaseTransformer):
|
|
446
436
|
)
|
447
437
|
self._sklearn_object = model_trainer.train()
|
448
438
|
self._is_fitted = True
|
449
|
-
self.
|
439
|
+
self._generate_model_signatures(dataset)
|
450
440
|
return self
|
451
441
|
|
452
442
|
def _batch_inference_validate_snowpark(
|
453
443
|
self,
|
454
444
|
dataset: DataFrame,
|
455
445
|
inference_method: str,
|
456
|
-
) ->
|
457
|
-
"""Util method to run validate that batch inference can be run on a snowpark dataframe
|
458
|
-
return the available package that exists in the snowflake anaconda channel
|
446
|
+
) -> None:
|
447
|
+
"""Util method to run validate that batch inference can be run on a snowpark dataframe.
|
459
448
|
|
460
449
|
Args:
|
461
450
|
dataset: snowpark dataframe
|
462
451
|
inference_method: the inference method such as predict, score...
|
463
|
-
|
452
|
+
|
464
453
|
Raises:
|
465
454
|
SnowflakeMLException: If the estimator is not fitted, raise error
|
466
455
|
SnowflakeMLException: If the session is None, raise error
|
467
456
|
|
468
|
-
Returns:
|
469
|
-
A list of available package that exists in the snowflake anaconda channel
|
470
457
|
"""
|
471
458
|
if not self._is_fitted:
|
472
459
|
raise exceptions.SnowflakeMLException(
|
@@ -484,9 +471,7 @@ class SGDClassifier(BaseTransformer):
|
|
484
471
|
"Session must not specified for snowpark dataset."
|
485
472
|
),
|
486
473
|
)
|
487
|
-
|
488
|
-
return pkg_version_utils.get_valid_pkg_versions_supported_in_snowflake_conda_channel(
|
489
|
-
pkg_versions=self._get_dependencies(), session=session, subproject=_SUBPROJECT)
|
474
|
+
|
490
475
|
|
491
476
|
@available_if(original_estimator_has_callable("predict")) # type: ignore[misc]
|
492
477
|
@telemetry.send_api_usage_telemetry(
|
@@ -522,7 +507,9 @@ class SGDClassifier(BaseTransformer):
|
|
522
507
|
# when it is classifier, infer the datatype from label columns
|
523
508
|
if expected_type_inferred == "" and 'predict' in self.model_signatures:
|
524
509
|
# Batch inference takes a single expected output column type. Use the first columns type for now.
|
525
|
-
label_cols_signatures = [
|
510
|
+
label_cols_signatures = [
|
511
|
+
row for row in self.model_signatures['predict'].outputs if row.name in self.output_cols
|
512
|
+
]
|
526
513
|
if len(label_cols_signatures) == 0:
|
527
514
|
error_str = f"Output columns {self.output_cols} do not match model signatures {self.model_signatures['predict'].outputs}."
|
528
515
|
raise exceptions.SnowflakeMLException(
|
@@ -530,25 +517,23 @@ class SGDClassifier(BaseTransformer):
|
|
530
517
|
original_exception=ValueError(error_str),
|
531
518
|
)
|
532
519
|
|
533
|
-
expected_type_inferred = convert_sp_to_sf_type(
|
534
|
-
label_cols_signatures[0].as_snowpark_type()
|
535
|
-
)
|
520
|
+
expected_type_inferred = convert_sp_to_sf_type(label_cols_signatures[0].as_snowpark_type())
|
536
521
|
|
537
|
-
self.
|
538
|
-
|
522
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
523
|
+
self._deps = self._get_dependencies()
|
524
|
+
assert isinstance(
|
525
|
+
dataset._session, Session
|
526
|
+
) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
539
527
|
|
540
528
|
transform_kwargs = dict(
|
541
|
-
session
|
542
|
-
dependencies
|
543
|
-
drop_input_cols
|
544
|
-
expected_output_cols_type
|
529
|
+
session=dataset._session,
|
530
|
+
dependencies=self._deps,
|
531
|
+
drop_input_cols=self._drop_input_cols,
|
532
|
+
expected_output_cols_type=expected_type_inferred,
|
545
533
|
)
|
546
534
|
|
547
535
|
elif isinstance(dataset, pd.DataFrame):
|
548
|
-
transform_kwargs = dict(
|
549
|
-
snowpark_input_cols = self._snowpark_cols,
|
550
|
-
drop_input_cols = self._drop_input_cols
|
551
|
-
)
|
536
|
+
transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
|
552
537
|
|
553
538
|
transform_handlers = ModelTransformerBuilder.build(
|
554
539
|
dataset=dataset,
|
@@ -588,7 +573,7 @@ class SGDClassifier(BaseTransformer):
|
|
588
573
|
Transformed dataset.
|
589
574
|
"""
|
590
575
|
super()._check_dataset_type(dataset)
|
591
|
-
inference_method="transform"
|
576
|
+
inference_method = "transform"
|
592
577
|
|
593
578
|
# This dictionary contains optional kwargs for batch inference. These kwargs
|
594
579
|
# are specific to the type of dataset used.
|
@@ -618,24 +603,19 @@ class SGDClassifier(BaseTransformer):
|
|
618
603
|
if all(x == output_types[0] for x in output_types) and len(output_types) == len(self.output_cols):
|
619
604
|
expected_dtype = convert_sp_to_sf_type(output_types[0])
|
620
605
|
|
621
|
-
self.
|
622
|
-
|
623
|
-
inference_method=inference_method,
|
624
|
-
)
|
606
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
607
|
+
self._deps = self._get_dependencies()
|
625
608
|
assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
626
609
|
|
627
610
|
transform_kwargs = dict(
|
628
|
-
session
|
629
|
-
dependencies
|
630
|
-
drop_input_cols
|
631
|
-
expected_output_cols_type
|
611
|
+
session=dataset._session,
|
612
|
+
dependencies=self._deps,
|
613
|
+
drop_input_cols=self._drop_input_cols,
|
614
|
+
expected_output_cols_type=expected_dtype,
|
632
615
|
)
|
633
616
|
|
634
617
|
elif isinstance(dataset, pd.DataFrame):
|
635
|
-
transform_kwargs = dict(
|
636
|
-
snowpark_input_cols = self._snowpark_cols,
|
637
|
-
drop_input_cols = self._drop_input_cols
|
638
|
-
)
|
618
|
+
transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
|
639
619
|
|
640
620
|
transform_handlers = ModelTransformerBuilder.build(
|
641
621
|
dataset=dataset,
|
@@ -654,7 +634,11 @@ class SGDClassifier(BaseTransformer):
|
|
654
634
|
return output_df
|
655
635
|
|
656
636
|
@available_if(original_estimator_has_callable("fit_predict")) # type: ignore[misc]
|
657
|
-
def fit_predict(
|
637
|
+
def fit_predict(
|
638
|
+
self,
|
639
|
+
dataset: Union[DataFrame, pd.DataFrame],
|
640
|
+
output_cols_prefix: str = "fit_predict_",
|
641
|
+
) -> Union[DataFrame, pd.DataFrame]:
|
658
642
|
""" Method not supported for this class.
|
659
643
|
|
660
644
|
|
@@ -679,22 +663,104 @@ class SGDClassifier(BaseTransformer):
|
|
679
663
|
)
|
680
664
|
output_result, fitted_estimator = model_trainer.train_fit_predict(
|
681
665
|
drop_input_cols=self._drop_input_cols,
|
682
|
-
expected_output_cols_list=
|
666
|
+
expected_output_cols_list=(
|
667
|
+
self.output_cols if self.output_cols else self._get_output_column_names(output_cols_prefix)
|
668
|
+
),
|
683
669
|
)
|
684
670
|
self._sklearn_object = fitted_estimator
|
685
671
|
self._is_fitted = True
|
686
672
|
return output_result
|
687
673
|
|
674
|
+
|
675
|
+
@available_if(original_estimator_has_callable("fit_transform")) # type: ignore[misc]
|
676
|
+
def fit_transform(self, dataset: Union[DataFrame, pd.DataFrame], output_cols_prefix: str = "fit_transform_",) -> Union[DataFrame, pd.DataFrame]:
|
677
|
+
""" Method not supported for this class.
|
678
|
+
|
688
679
|
|
689
|
-
|
690
|
-
|
691
|
-
|
680
|
+
Raises:
|
681
|
+
TypeError: Supported dataset types: snowpark.DataFrame, pandas.DataFrame.
|
682
|
+
|
683
|
+
Args:
|
684
|
+
dataset: Union[snowflake.snowpark.DataFrame, pandas.DataFrame]
|
685
|
+
Snowpark or Pandas DataFrame.
|
686
|
+
output_cols_prefix: Prefix for the response columns
|
692
687
|
Returns:
|
693
688
|
Transformed dataset.
|
694
689
|
"""
|
695
|
-
self.
|
696
|
-
|
697
|
-
|
690
|
+
self._infer_input_output_cols(dataset)
|
691
|
+
super()._check_dataset_type(dataset)
|
692
|
+
model_trainer = ModelTrainerBuilder.build_fit_transform(
|
693
|
+
estimator=self._sklearn_object,
|
694
|
+
dataset=dataset,
|
695
|
+
input_cols=self.input_cols,
|
696
|
+
label_cols=self.label_cols,
|
697
|
+
sample_weight_col=self.sample_weight_col,
|
698
|
+
autogenerated=self._autogenerated,
|
699
|
+
subproject=_SUBPROJECT,
|
700
|
+
)
|
701
|
+
output_result, fitted_estimator = model_trainer.train_fit_transform(
|
702
|
+
drop_input_cols=self._drop_input_cols,
|
703
|
+
expected_output_cols_list=self.output_cols,
|
704
|
+
)
|
705
|
+
self._sklearn_object = fitted_estimator
|
706
|
+
self._is_fitted = True
|
707
|
+
return output_result
|
708
|
+
|
709
|
+
|
710
|
+
def _get_output_column_names(self, output_cols_prefix: str, output_cols: Optional[List[str]] = None) -> List[str]:
|
711
|
+
""" Returns the list of output columns for predict_proba(), decision_function(), etc.. functions.
|
712
|
+
Returns a list with output_cols_prefix as the only element if the estimator is not a classifier.
|
713
|
+
"""
|
714
|
+
output_cols_prefix = identifier.resolve_identifier(output_cols_prefix)
|
715
|
+
# The following condition is introduced for kneighbors methods, and not used in other methods
|
716
|
+
if output_cols:
|
717
|
+
output_cols = [
|
718
|
+
identifier.concat_names([output_cols_prefix, identifier.resolve_identifier(c)])
|
719
|
+
for c in output_cols
|
720
|
+
]
|
721
|
+
elif getattr(self._sklearn_object, "classes_", None) is None:
|
722
|
+
output_cols = [output_cols_prefix]
|
723
|
+
elif self._sklearn_object is not None:
|
724
|
+
classes = self._sklearn_object.classes_
|
725
|
+
if isinstance(classes, numpy.ndarray):
|
726
|
+
output_cols = [f'{output_cols_prefix}{str(c)}' for c in classes.tolist()]
|
727
|
+
elif isinstance(classes, list) and len(classes) > 0 and isinstance(classes[0], numpy.ndarray):
|
728
|
+
# If the estimator is a multioutput estimator, classes_ will be a list of ndarrays.
|
729
|
+
output_cols = []
|
730
|
+
for i, cl in enumerate(classes):
|
731
|
+
# For binary classification, there is only one output column for each class
|
732
|
+
# ndarray as the two classes are complementary.
|
733
|
+
if len(cl) == 2:
|
734
|
+
output_cols.append(f'{output_cols_prefix}{i}_{cl[0]}')
|
735
|
+
else:
|
736
|
+
output_cols.extend([
|
737
|
+
f'{output_cols_prefix}{i}_{c}' for c in cl.tolist()
|
738
|
+
])
|
739
|
+
else:
|
740
|
+
output_cols = []
|
741
|
+
|
742
|
+
# Make sure column names are valid snowflake identifiers.
|
743
|
+
assert output_cols is not None # Make MyPy happy
|
744
|
+
rv = [identifier.rename_to_valid_snowflake_identifier(c) for c in output_cols]
|
745
|
+
|
746
|
+
return rv
|
747
|
+
|
748
|
+
def _align_expected_output_names(
|
749
|
+
self, method: str, dataset: DataFrame, expected_output_cols_list: List[str], output_cols_prefix: str
|
750
|
+
) -> List[str]:
|
751
|
+
# in case the inferred output column names dimension is different
|
752
|
+
# we use one line of snowpark dataframe and put it into sklearn estimator using pandas
|
753
|
+
output_df_pd = getattr(self, method)(dataset.limit(1).to_pandas(), output_cols_prefix)
|
754
|
+
output_df_columns = list(output_df_pd.columns)
|
755
|
+
output_df_columns_set: Set[str] = set(output_df_columns) - set(dataset.columns)
|
756
|
+
if self.sample_weight_col:
|
757
|
+
output_df_columns_set -= set(self.sample_weight_col)
|
758
|
+
# if the dimension of inferred output column names is correct; use it
|
759
|
+
if len(expected_output_cols_list) == len(output_df_columns_set):
|
760
|
+
return expected_output_cols_list
|
761
|
+
# otherwise, use the sklearn estimator's output
|
762
|
+
else:
|
763
|
+
return sorted(list(output_df_columns_set), key=lambda x: output_df_columns.index(x))
|
698
764
|
|
699
765
|
@available_if(original_estimator_has_callable("predict_proba")) # type: ignore[misc]
|
700
766
|
@telemetry.send_api_usage_telemetry(
|
@@ -728,24 +794,26 @@ class SGDClassifier(BaseTransformer):
|
|
728
794
|
# are specific to the type of dataset used.
|
729
795
|
transform_kwargs: BatchInferenceKwargsTypedDict = dict()
|
730
796
|
|
797
|
+
expected_output_cols = self._get_output_column_names(output_cols_prefix)
|
798
|
+
|
731
799
|
if isinstance(dataset, DataFrame):
|
732
|
-
self.
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
800
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
801
|
+
self._deps = self._get_dependencies()
|
802
|
+
assert isinstance(
|
803
|
+
dataset._session, Session
|
804
|
+
) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
737
805
|
transform_kwargs = dict(
|
738
806
|
session=dataset._session,
|
739
807
|
dependencies=self._deps,
|
740
|
-
drop_input_cols
|
808
|
+
drop_input_cols=self._drop_input_cols,
|
741
809
|
expected_output_cols_type="float",
|
742
810
|
)
|
811
|
+
expected_output_cols = self._align_expected_output_names(
|
812
|
+
inference_method, dataset, expected_output_cols, output_cols_prefix
|
813
|
+
)
|
743
814
|
|
744
815
|
elif isinstance(dataset, pd.DataFrame):
|
745
|
-
transform_kwargs = dict(
|
746
|
-
snowpark_input_cols = self._snowpark_cols,
|
747
|
-
drop_input_cols = self._drop_input_cols
|
748
|
-
)
|
816
|
+
transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
|
749
817
|
|
750
818
|
transform_handlers = ModelTransformerBuilder.build(
|
751
819
|
dataset=dataset,
|
@@ -757,7 +825,7 @@ class SGDClassifier(BaseTransformer):
|
|
757
825
|
output_df: DATAFRAME_TYPE = transform_handlers.batch_inference(
|
758
826
|
inference_method=inference_method,
|
759
827
|
input_cols=self.input_cols,
|
760
|
-
expected_output_cols=
|
828
|
+
expected_output_cols=expected_output_cols,
|
761
829
|
**transform_kwargs
|
762
830
|
)
|
763
831
|
return output_df
|
@@ -789,29 +857,30 @@ class SGDClassifier(BaseTransformer):
|
|
789
857
|
Output dataset with log probability of the sample for each class in the model.
|
790
858
|
"""
|
791
859
|
super()._check_dataset_type(dataset)
|
792
|
-
inference_method="predict_log_proba"
|
860
|
+
inference_method = "predict_log_proba"
|
861
|
+
expected_output_cols = self._get_output_column_names(output_cols_prefix)
|
793
862
|
|
794
863
|
# This dictionary contains optional kwargs for batch inference. These kwargs
|
795
864
|
# are specific to the type of dataset used.
|
796
865
|
transform_kwargs: BatchInferenceKwargsTypedDict = dict()
|
797
866
|
|
798
867
|
if isinstance(dataset, DataFrame):
|
799
|
-
self.
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
868
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
869
|
+
self._deps = self._get_dependencies()
|
870
|
+
assert isinstance(
|
871
|
+
dataset._session, Session
|
872
|
+
) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
804
873
|
transform_kwargs = dict(
|
805
874
|
session=dataset._session,
|
806
875
|
dependencies=self._deps,
|
807
|
-
drop_input_cols
|
876
|
+
drop_input_cols=self._drop_input_cols,
|
808
877
|
expected_output_cols_type="float",
|
809
878
|
)
|
879
|
+
expected_output_cols = self._align_expected_output_names(
|
880
|
+
inference_method, dataset, expected_output_cols, output_cols_prefix
|
881
|
+
)
|
810
882
|
elif isinstance(dataset, pd.DataFrame):
|
811
|
-
transform_kwargs = dict(
|
812
|
-
snowpark_input_cols = self._snowpark_cols,
|
813
|
-
drop_input_cols = self._drop_input_cols
|
814
|
-
)
|
883
|
+
transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
|
815
884
|
|
816
885
|
transform_handlers = ModelTransformerBuilder.build(
|
817
886
|
dataset=dataset,
|
@@ -824,7 +893,7 @@ class SGDClassifier(BaseTransformer):
|
|
824
893
|
output_df: DATAFRAME_TYPE = transform_handlers.batch_inference(
|
825
894
|
inference_method=inference_method,
|
826
895
|
input_cols=self.input_cols,
|
827
|
-
expected_output_cols=
|
896
|
+
expected_output_cols=expected_output_cols,
|
828
897
|
**transform_kwargs
|
829
898
|
)
|
830
899
|
return output_df
|
@@ -852,30 +921,32 @@ class SGDClassifier(BaseTransformer):
|
|
852
921
|
Output dataset with results of the decision function for the samples in input dataset.
|
853
922
|
"""
|
854
923
|
super()._check_dataset_type(dataset)
|
855
|
-
inference_method="decision_function"
|
924
|
+
inference_method = "decision_function"
|
856
925
|
|
857
926
|
# This dictionary contains optional kwargs for batch inference. These kwargs
|
858
927
|
# are specific to the type of dataset used.
|
859
928
|
transform_kwargs: BatchInferenceKwargsTypedDict = dict()
|
860
929
|
|
930
|
+
expected_output_cols = self._get_output_column_names(output_cols_prefix)
|
931
|
+
|
861
932
|
if isinstance(dataset, DataFrame):
|
862
|
-
self.
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
933
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
934
|
+
self._deps = self._get_dependencies()
|
935
|
+
assert isinstance(
|
936
|
+
dataset._session, Session
|
937
|
+
) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
867
938
|
transform_kwargs = dict(
|
868
939
|
session=dataset._session,
|
869
940
|
dependencies=self._deps,
|
870
|
-
drop_input_cols
|
941
|
+
drop_input_cols=self._drop_input_cols,
|
871
942
|
expected_output_cols_type="float",
|
872
943
|
)
|
944
|
+
expected_output_cols = self._align_expected_output_names(
|
945
|
+
inference_method, dataset, expected_output_cols, output_cols_prefix
|
946
|
+
)
|
873
947
|
|
874
948
|
elif isinstance(dataset, pd.DataFrame):
|
875
|
-
transform_kwargs = dict(
|
876
|
-
snowpark_input_cols = self._snowpark_cols,
|
877
|
-
drop_input_cols = self._drop_input_cols
|
878
|
-
)
|
949
|
+
transform_kwargs = dict(snowpark_input_cols=self._snowpark_cols, drop_input_cols=self._drop_input_cols)
|
879
950
|
|
880
951
|
transform_handlers = ModelTransformerBuilder.build(
|
881
952
|
dataset=dataset,
|
@@ -888,7 +959,7 @@ class SGDClassifier(BaseTransformer):
|
|
888
959
|
output_df: DATAFRAME_TYPE = transform_handlers.batch_inference(
|
889
960
|
inference_method=inference_method,
|
890
961
|
input_cols=self.input_cols,
|
891
|
-
expected_output_cols=
|
962
|
+
expected_output_cols=expected_output_cols,
|
892
963
|
**transform_kwargs
|
893
964
|
)
|
894
965
|
return output_df
|
@@ -917,17 +988,17 @@ class SGDClassifier(BaseTransformer):
|
|
917
988
|
Output dataset with probability of the sample for each class in the model.
|
918
989
|
"""
|
919
990
|
super()._check_dataset_type(dataset)
|
920
|
-
inference_method="score_samples"
|
991
|
+
inference_method = "score_samples"
|
921
992
|
|
922
993
|
# This dictionary contains optional kwargs for batch inference. These kwargs
|
923
994
|
# are specific to the type of dataset used.
|
924
995
|
transform_kwargs: BatchInferenceKwargsTypedDict = dict()
|
925
996
|
|
997
|
+
expected_output_cols = self._get_output_column_names(output_cols_prefix)
|
998
|
+
|
926
999
|
if isinstance(dataset, DataFrame):
|
927
|
-
self.
|
928
|
-
|
929
|
-
inference_method=inference_method,
|
930
|
-
)
|
1000
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
1001
|
+
self._deps = self._get_dependencies()
|
931
1002
|
assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
932
1003
|
transform_kwargs = dict(
|
933
1004
|
session=dataset._session,
|
@@ -935,6 +1006,9 @@ class SGDClassifier(BaseTransformer):
|
|
935
1006
|
drop_input_cols = self._drop_input_cols,
|
936
1007
|
expected_output_cols_type="float",
|
937
1008
|
)
|
1009
|
+
expected_output_cols = self._align_expected_output_names(
|
1010
|
+
inference_method, dataset, expected_output_cols, output_cols_prefix
|
1011
|
+
)
|
938
1012
|
|
939
1013
|
elif isinstance(dataset, pd.DataFrame):
|
940
1014
|
transform_kwargs = dict(
|
@@ -953,7 +1027,7 @@ class SGDClassifier(BaseTransformer):
|
|
953
1027
|
output_df: DATAFRAME_TYPE = transform_handlers.batch_inference(
|
954
1028
|
inference_method=inference_method,
|
955
1029
|
input_cols=self.input_cols,
|
956
|
-
expected_output_cols=
|
1030
|
+
expected_output_cols=expected_output_cols,
|
957
1031
|
**transform_kwargs
|
958
1032
|
)
|
959
1033
|
return output_df
|
@@ -988,17 +1062,15 @@ class SGDClassifier(BaseTransformer):
|
|
988
1062
|
transform_kwargs: ScoreKwargsTypedDict = dict()
|
989
1063
|
|
990
1064
|
if isinstance(dataset, DataFrame):
|
991
|
-
self.
|
992
|
-
|
993
|
-
inference_method="score",
|
994
|
-
)
|
1065
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method="score")
|
1066
|
+
self._deps = self._get_dependencies()
|
995
1067
|
selected_cols = self._get_active_columns()
|
996
1068
|
if len(selected_cols) > 0:
|
997
1069
|
dataset = dataset.select(selected_cols)
|
998
1070
|
assert isinstance(dataset._session, Session) # keep mypy happy
|
999
1071
|
transform_kwargs = dict(
|
1000
1072
|
session=dataset._session,
|
1001
|
-
dependencies=
|
1073
|
+
dependencies=self._deps,
|
1002
1074
|
score_sproc_imports=['sklearn'],
|
1003
1075
|
)
|
1004
1076
|
elif isinstance(dataset, pd.DataFrame):
|
@@ -1063,11 +1135,8 @@ class SGDClassifier(BaseTransformer):
|
|
1063
1135
|
|
1064
1136
|
if isinstance(dataset, DataFrame):
|
1065
1137
|
|
1066
|
-
self.
|
1067
|
-
|
1068
|
-
inference_method=inference_method,
|
1069
|
-
|
1070
|
-
)
|
1138
|
+
self._batch_inference_validate_snowpark(dataset=dataset, inference_method=inference_method)
|
1139
|
+
self._deps = self._get_dependencies()
|
1071
1140
|
assert isinstance(dataset._session, Session) # mypy does not recognize the check in _batch_inference_validate_snowpark()
|
1072
1141
|
transform_kwargs = dict(
|
1073
1142
|
session = dataset._session,
|
@@ -1100,50 +1169,84 @@ class SGDClassifier(BaseTransformer):
|
|
1100
1169
|
)
|
1101
1170
|
return output_df
|
1102
1171
|
|
1172
|
+
|
1173
|
+
|
1174
|
+
def to_sklearn(self) -> Any:
|
1175
|
+
"""Get sklearn.linear_model.SGDClassifier object.
|
1176
|
+
"""
|
1177
|
+
if self._sklearn_object is None:
|
1178
|
+
self._sklearn_object = self._create_sklearn_object()
|
1179
|
+
return self._sklearn_object
|
1180
|
+
|
1181
|
+
def to_xgboost(self) -> Any:
|
1182
|
+
raise exceptions.SnowflakeMLException(
|
1183
|
+
error_code=error_codes.METHOD_NOT_ALLOWED,
|
1184
|
+
original_exception=AttributeError(
|
1185
|
+
modeling_error_messages.UNSUPPORTED_MODEL_CONVERSION.format(
|
1186
|
+
"to_xgboost()",
|
1187
|
+
"to_sklearn()"
|
1188
|
+
)
|
1189
|
+
),
|
1190
|
+
)
|
1191
|
+
|
1192
|
+
def to_lightgbm(self) -> Any:
|
1193
|
+
raise exceptions.SnowflakeMLException(
|
1194
|
+
error_code=error_codes.METHOD_NOT_ALLOWED,
|
1195
|
+
original_exception=AttributeError(
|
1196
|
+
modeling_error_messages.UNSUPPORTED_MODEL_CONVERSION.format(
|
1197
|
+
"to_lightgbm()",
|
1198
|
+
"to_sklearn()"
|
1199
|
+
)
|
1200
|
+
),
|
1201
|
+
)
|
1202
|
+
|
1203
|
+
def _get_dependencies(self) -> List[str]:
|
1204
|
+
return self._deps
|
1205
|
+
|
1103
1206
|
|
1104
|
-
def
|
1207
|
+
def _generate_model_signatures(self, dataset: Union[DataFrame, pd.DataFrame]) -> None:
|
1105
1208
|
self._model_signature_dict = dict()
|
1106
1209
|
|
1107
1210
|
PROB_FUNCTIONS = ["predict_log_proba", "predict_proba", "decision_function"]
|
1108
1211
|
|
1109
|
-
inputs = list(_infer_signature(dataset[self.input_cols], "input"))
|
1212
|
+
inputs = list(_infer_signature(dataset[self.input_cols], "input", use_snowflake_identifiers=True))
|
1110
1213
|
outputs: List[BaseFeatureSpec] = []
|
1111
1214
|
if hasattr(self, "predict"):
|
1112
1215
|
# keep mypy happy
|
1113
|
-
assert self._sklearn_object is not None and hasattr(self._sklearn_object, "_estimator_type")
|
1216
|
+
assert self._sklearn_object is not None and hasattr(self._sklearn_object, "_estimator_type")
|
1114
1217
|
# For classifier, the type of predict is the same as the type of label
|
1115
|
-
if self._sklearn_object._estimator_type ==
|
1116
|
-
|
1218
|
+
if self._sklearn_object._estimator_type == "classifier":
|
1219
|
+
# label columns is the desired type for output
|
1117
1220
|
outputs = list(_infer_signature(dataset[self.label_cols], "output", use_snowflake_identifiers=True))
|
1118
1221
|
# rename the output columns
|
1119
1222
|
outputs = list(model_signature_utils.rename_features(outputs, self.output_cols))
|
1120
|
-
self._model_signature_dict["predict"] = ModelSignature(
|
1121
|
-
|
1122
|
-
|
1223
|
+
self._model_signature_dict["predict"] = ModelSignature(
|
1224
|
+
inputs, ([] if self._drop_input_cols else inputs) + outputs
|
1225
|
+
)
|
1123
1226
|
# For mixture models that use the density mixin, `predict` returns the argmax of the log prob.
|
1124
1227
|
# For outlier models, returns -1 for outliers and 1 for inliers.
|
1125
|
-
# Clusterer returns int64 cluster labels.
|
1228
|
+
# Clusterer returns int64 cluster labels.
|
1126
1229
|
elif self._sklearn_object._estimator_type in ["DensityEstimator", "clusterer", "outlier_detector"]:
|
1127
1230
|
outputs = [FeatureSpec(dtype=DataType.INT64, name=c) for c in self.output_cols]
|
1128
|
-
self._model_signature_dict["predict"] = ModelSignature(
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1231
|
+
self._model_signature_dict["predict"] = ModelSignature(
|
1232
|
+
inputs, ([] if self._drop_input_cols else inputs) + outputs
|
1233
|
+
)
|
1234
|
+
|
1132
1235
|
# For regressor, the type of predict is float64
|
1133
|
-
elif self._sklearn_object._estimator_type ==
|
1236
|
+
elif self._sklearn_object._estimator_type == "regressor":
|
1134
1237
|
outputs = [FeatureSpec(dtype=DataType.DOUBLE, name=c) for c in self.output_cols]
|
1135
|
-
self._model_signature_dict["predict"] = ModelSignature(
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1238
|
+
self._model_signature_dict["predict"] = ModelSignature(
|
1239
|
+
inputs, ([] if self._drop_input_cols else inputs) + outputs
|
1240
|
+
)
|
1241
|
+
|
1139
1242
|
for prob_func in PROB_FUNCTIONS:
|
1140
1243
|
if hasattr(self, prob_func):
|
1141
1244
|
output_cols_prefix: str = f"{prob_func}_"
|
1142
1245
|
output_column_names = self._get_output_column_names(output_cols_prefix)
|
1143
1246
|
outputs = [FeatureSpec(dtype=DataType.DOUBLE, name=c) for c in output_column_names]
|
1144
|
-
self._model_signature_dict[prob_func] = ModelSignature(
|
1145
|
-
|
1146
|
-
|
1247
|
+
self._model_signature_dict[prob_func] = ModelSignature(
|
1248
|
+
inputs, ([] if self._drop_input_cols else inputs) + outputs
|
1249
|
+
)
|
1147
1250
|
|
1148
1251
|
# Output signature names may still need to be renamed, since they were not created with `_infer_signature`.
|
1149
1252
|
items = list(self._model_signature_dict.items())
|
@@ -1156,10 +1259,10 @@ class SGDClassifier(BaseTransformer):
|
|
1156
1259
|
"""Returns model signature of current class.
|
1157
1260
|
|
1158
1261
|
Raises:
|
1159
|
-
|
1262
|
+
SnowflakeMLException: If estimator is not fitted, then model signature cannot be inferred
|
1160
1263
|
|
1161
1264
|
Returns:
|
1162
|
-
Dict
|
1265
|
+
Dict with each method and its input output signature
|
1163
1266
|
"""
|
1164
1267
|
if self._model_signature_dict is None:
|
1165
1268
|
raise exceptions.SnowflakeMLException(
|
@@ -1167,35 +1270,3 @@ class SGDClassifier(BaseTransformer):
|
|
1167
1270
|
original_exception=RuntimeError("Estimator not fitted before accessing property model_signatures!"),
|
1168
1271
|
)
|
1169
1272
|
return self._model_signature_dict
|
1170
|
-
|
1171
|
-
def to_sklearn(self) -> Any:
|
1172
|
-
"""Get sklearn.linear_model.SGDClassifier object.
|
1173
|
-
"""
|
1174
|
-
if self._sklearn_object is None:
|
1175
|
-
self._sklearn_object = self._create_sklearn_object()
|
1176
|
-
return self._sklearn_object
|
1177
|
-
|
1178
|
-
def to_xgboost(self) -> Any:
|
1179
|
-
raise exceptions.SnowflakeMLException(
|
1180
|
-
error_code=error_codes.METHOD_NOT_ALLOWED,
|
1181
|
-
original_exception=AttributeError(
|
1182
|
-
modeling_error_messages.UNSUPPORTED_MODEL_CONVERSION.format(
|
1183
|
-
"to_xgboost()",
|
1184
|
-
"to_sklearn()"
|
1185
|
-
)
|
1186
|
-
),
|
1187
|
-
)
|
1188
|
-
|
1189
|
-
def to_lightgbm(self) -> Any:
|
1190
|
-
raise exceptions.SnowflakeMLException(
|
1191
|
-
error_code=error_codes.METHOD_NOT_ALLOWED,
|
1192
|
-
original_exception=AttributeError(
|
1193
|
-
modeling_error_messages.UNSUPPORTED_MODEL_CONVERSION.format(
|
1194
|
-
"to_lightgbm()",
|
1195
|
-
"to_sklearn()"
|
1196
|
-
)
|
1197
|
-
),
|
1198
|
-
)
|
1199
|
-
|
1200
|
-
def _get_dependencies(self) -> List[str]:
|
1201
|
-
return self._deps
|