Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 32 additions & 41 deletions ads/automl/provider.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
#!/usr/bin/env python
# -*- coding: utf-8; -*-

# Copyright (c) 2020, 2023 Oracle and/or its affiliates.
# Copyright (c) 2020, 2025 Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/

import logging
import time
import sys
import time
import warnings
from abc import ABC, abstractmethod, abstractproperty
import math
import pandas as pd
from abc import ABC, abstractmethod

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from sklearn import set_config
from sklearn.dummy import DummyClassifier, DummyRegressor

import matplotlib.pyplot as plt

import ads
from ads.common import logger, utils
from ads.common.decorator.deprecate import deprecated
from ads.common.decorator.runtime_dependency import (
OptionalDependency,
runtime_dependency,
)
from ads.common.utils import (
is_notebook,
ml_task_types,
wrap_lines,
is_documentation_mode,
is_notebook,
)
from ads.common.decorator.runtime_dependency import (
runtime_dependency,
OptionalDependency,
)
from ads.common.decorator.deprecate import deprecated
from ads.dataset.label_encoder import DataFrameLabelEncoder
from ads.dataset.helper import is_text_data

from ads.common import logger, utils


class AutoMLProvider(ABC):
Expand Down Expand Up @@ -141,7 +136,7 @@ def get_transformer_pipeline(self):
pass


class BaselineModel(object):
class BaselineModel:
"""
A BaselineModel object that supports fit/predict/predict_proba/transform
interface. Labels (y) are encoded using DataFrameLabelEncoder.
Expand All @@ -156,7 +151,6 @@ def __init__(self, est):
self.df_label_encoder = DataFrameLabelEncoder()

def predict(self, X):

"""
Runs the Baselines predict function and returns the result.

Expand All @@ -174,7 +168,6 @@ def predict(self, X):
return self.est.predict(X)

def predict_proba(self, X):

"""
Runs the Baselines predict_proba function and returns the result.

Expand All @@ -192,7 +185,6 @@ def predict_proba(self, X):
return self.est.predict_proba(X)

def fit(self, X, y):

"""
Fits the baseline estimator.

Expand All @@ -213,7 +205,6 @@ def fit(self, X, y):
return self

def transform(self, X):

"""
Runs the Baselines transform function and returns the result.

Expand Down Expand Up @@ -304,16 +295,15 @@ def decide_estimator(self, **kwargs):
"""
if self.est is not None:
return self.est
else:
if self.ml_task_type == ml_task_types.REGRESSION:
return BaselineModel(DummyRegressor())
elif self.ml_task_type in [
ml_task_types.BINARY_CLASSIFICATION,
ml_task_types.MULTI_CLASS_CLASSIFICATION,
ml_task_types.BINARY_TEXT_CLASSIFICATION,
ml_task_types.MULTI_CLASS_TEXT_CLASSIFICATION,
]:
return BaselineModel(DummyClassifier())
elif self.ml_task_type == ml_task_types.REGRESSION:
return BaselineModel(DummyRegressor())
elif self.ml_task_type in [
ml_task_types.BINARY_CLASSIFICATION,
ml_task_types.MULTI_CLASS_CLASSIFICATION,
ml_task_types.BINARY_TEXT_CLASSIFICATION,
ml_task_types.MULTI_CLASS_TEXT_CLASSIFICATION,
]:
return BaselineModel(DummyClassifier())


# An installation of oracle labs automl is required only for this class
Expand Down Expand Up @@ -483,8 +473,11 @@ def print_summary(
0, "Rank based on Performance", np.arange(2, len(sorted_summary_df) + 2)
)

from IPython.core.display import display, HTML
from IPython.display import HTML

from ads.common.utils import get_display

display = get_display()
with pd.option_context(
"display.max_colwidth",
1000,
Expand Down Expand Up @@ -595,9 +588,7 @@ def _decide_estimator(self, **kwargs):
if (
self.ml_task_type == ml_task_types.BINARY_CLASSIFICATION
or self.ml_task_type == ml_task_types.BINARY_TEXT_CLASSIFICATION
):
test_model_list = ["LogisticRegression"]
elif (
) or (
self.ml_task_type == ml_task_types.MULTI_CLASS_CLASSIFICATION
or self.ml_task_type == ml_task_types.MULTI_CLASS_TEXT_CLASSIFICATION
):
Expand Down Expand Up @@ -712,7 +703,7 @@ def visualize_algorithm_selection_trials(self, ylabel=None):
for f in mean_scores_ser.keys():
se = scipy.stats.sem(scores_ser[f], ddof=1)
y_error.append(se)
if f == "{}_AS".format(self.est.selected_model_):
if f == f"{self.est.selected_model_}_AS":
colors.append("orange")
elif mean_scores_ser[f] >= mean_scores_ser.mean():
colors.append("teal")
Expand Down Expand Up @@ -741,7 +732,7 @@ def visualize_adaptive_sampling_trials(self):
_log_visualize_no_trials("adaptive sampling")
return
fig, ax = plt.subplots(1, figsize=(6, 3))
ax.set_title("Adaptive Sampling ({})".format(trials[0][0]))
ax.set_title(f"Adaptive Sampling ({trials[0][0]})")
ax.set_xlabel("Dataset sample size")
ax.set_ylabel(r"Predicted model score")
scores = [
Expand Down Expand Up @@ -882,7 +873,7 @@ def visualize_tuning_trials(self, ylabel=None):
plt.show()


class AutoMLPreprocessingTransformer(object): # pragma: no cover
class AutoMLPreprocessingTransformer: # pragma: no cover
@deprecated(
details="Working with AutoML has moved from within ADS to working directly with the AutoMLx library. AutoMLx are preinstalled in conda pack automlx_p38_cpu_v2 and later, and can now be updated independently of ADS. AutoMLx documentation may be found at https://docs.oracle.com/en-us/iaas/tools/automlx/latest/html/multiversion/v23.1.1/index.html. Notebook examples are in Oracle's samples repository: https://github.com/oracle-samples/oci-data-science-ai-samples/tree/master/notebook_examples and a migration tutorial can be found at https://accelerated-data-science.readthedocs.io/en/latest/user_guide/model_training/automl/quick_start.html .",
raise_error=True,
Expand Down Expand Up @@ -931,7 +922,7 @@ def __repr__(self):
return self.msg


class AutoMLFeatureSelection(object): # pragma: no cover
class AutoMLFeatureSelection: # pragma: no cover
@deprecated(
details="Working with AutoML has moved from within ADS to working directly with the AutoMLx library. AutoMLx are preinstalled in conda pack automlx_p38_cpu_v2 and later, and can now be updated independently of ADS. AutoMLx documentation may be found at https://docs.oracle.com/en-us/iaas/tools/automlx/latest/html/multiversion/v23.1.1/index.html. Notebook examples are in Oracle's samples repository: https://github.com/oracle-samples/oci-data-science-ai-samples/tree/master/notebook_examples and a migration tutorial can be found at https://accelerated-data-science.readthedocs.io/en/latest/user_guide/model_training/automl/quick_start.html .",
raise_error=True,
Expand Down
64 changes: 33 additions & 31 deletions ads/catalog/model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8; -*-

# Copyright (c) 2020, 2024 Oracle and/or its affiliates.
# Copyright (c) 2020, 2025 Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/

import warnings
Expand All @@ -27,20 +26,30 @@

import pandas as pd
import yaml
from oci.data_science.data_science_client import DataScienceClient
from oci.data_science.models import (
ArtifactExportDetailsObjectStorage,
ArtifactImportDetailsObjectStorage,
CreateModelDetails,
ExportModelArtifactDetails,
ImportModelArtifactDetails,
ModelSummary,
WorkRequest,
)
from oci.data_science.models import Model as OCIModel
from oci.data_science.models.model_provenance import ModelProvenance
from oci.data_science.models.update_model_details import UpdateModelDetails
from oci.exceptions import ServiceError
from oci.identity import IdentityClient

from ads.catalog.summary import SummaryList
from ads.common import auth, logger, oci_client, utils
from ads.common.decorator.deprecate import deprecated
from ads.common.decorator.runtime_dependency import (
runtime_dependency,
OptionalDependency,
runtime_dependency,
)
from ads.common.model_artifact import ConflictStrategy, ModelArtifact
from ads.model.model_metadata import (
METADATA_SIZE_LIMIT,
MetadataSizeTooLarge,
ModelCustomMetadata,
ModelTaxonomyMetadata,
)
from ads.common.object_storage_details import ObjectStorageDetails
from ads.common.oci_resource import SEARCH_TYPE, OCIResource
from ads.config import (
Expand All @@ -51,22 +60,14 @@
)
from ads.dataset.progress import TqdmProgressBar
from ads.feature_engineering.schema import Schema
from ads.model.model_version_set import ModelVersionSet, _extract_model_version_set_id
from ads.model.deployment.model_deployer import ModelDeployer
from oci.data_science.data_science_client import DataScienceClient
from oci.data_science.models import (
ArtifactExportDetailsObjectStorage,
ArtifactImportDetailsObjectStorage,
CreateModelDetails,
ExportModelArtifactDetails,
ImportModelArtifactDetails,
from ads.model.model_metadata import (
METADATA_SIZE_LIMIT,
MetadataSizeTooLarge,
ModelCustomMetadata,
ModelTaxonomyMetadata,
)
from oci.data_science.models import Model as OCIModel
from oci.data_science.models import ModelSummary, WorkRequest
from oci.data_science.models.model_provenance import ModelProvenance
from oci.data_science.models.update_model_details import UpdateModelDetails
from oci.exceptions import ServiceError
from oci.identity import IdentityClient
from ads.model.model_version_set import ModelVersionSet, _extract_model_version_set_id

_UPDATE_MODEL_DETAILS_ATTRIBUTES = [
"display_name",
Expand Down Expand Up @@ -391,8 +392,9 @@ def show_in_notebook(self, display_format: str = "dataframe") -> None:
Nothing.
"""
if display_format == "dataframe":
from IPython.core.display import display
from ads.common.utils import get_display

display = get_display()
display(self.to_dataframe())
elif display_format == "yaml":
print(self._to_yaml())
Expand Down Expand Up @@ -454,9 +456,9 @@ def commit(self, force: bool = True) -> None:
if hasattr(self, "metadata_custom"):
attributes["custom_metadata_list"] = self.metadata_custom._to_oci_metadata()
if hasattr(self, "metadata_taxonomy"):
attributes[
"defined_metadata_list"
] = self.metadata_taxonomy._to_oci_metadata()
attributes["defined_metadata_list"] = (
self.metadata_taxonomy._to_oci_metadata()
)

update_model_details = UpdateModelDetails(**attributes)
# freeform_tags=self._model.freeform_tags, defined_tags=self._model.defined_tags)
Expand Down Expand Up @@ -558,7 +560,7 @@ def load_model(

try:
provenance_response = cls._get_provenance_metadata(ds_client, model_id)
except Exception as e:
except Exception:
raise ValueError(
f"Unable to fetch model provenance metadata for model {model_id}"
)
Expand Down Expand Up @@ -1071,7 +1073,7 @@ def _download_large_artifact(
None
Nothing.
"""
progress.update(f"Importing model artifacts from model catalog")
progress.update("Importing model artifacts from model catalog")
self._import_model_artifact(model_id=model_id, bucket_uri=bucket_uri)

progress.update("Copying model artifacts to the artifact directory")
Expand Down Expand Up @@ -1360,7 +1362,7 @@ def upload_model(
raise ValueError("project_id needs to be specified.")
schema_file = os.path.join(model_artifact.artifact_dir, "schema.json")
if os.path.exists(schema_file):
with open(schema_file, "r") as schema:
with open(schema_file) as schema:
metadata = json.load(schema)
freeform_tags = {"problem_type": metadata["problem_type"]}

Expand Down Expand Up @@ -1475,7 +1477,7 @@ def _export_model_artifact(
3. Exports artifact from the user's object storage bucket to the system one.
"""
artifact_zip_path = self._prepare_model_artifact(model_artifact, progress)
progress.update(f"Copying model artifact to the Object Storage bucket")
progress.update("Copying model artifact to the Object Storage bucket")

try:
bucket_uri_file_name = os.path.basename(bucket_uri)
Expand Down
26 changes: 13 additions & 13 deletions ads/catalog/notebook.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8; -*-

# Copyright (c) 2020, 2024 Oracle and/or its affiliates.
# Copyright (c) 2020, 2025 Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/

import warnings
Expand All @@ -14,31 +13,31 @@
stacklevel=2,
)

from pandas import DataFrame
import oci
from types import MethodType

from oci.data_science.models import (
NotebookSessionSummary,
UpdateNotebookSessionDetails,
CreateNotebookSessionDetails,
NotebookSession,
NotebookSessionConfigurationDetails,
NotebookSessionSummary,
UpdateNotebookSessionDetails,
)
from oci.exceptions import ServiceError
from types import MethodType
from pandas import DataFrame

from ads.catalog.summary import SummaryList
from ads.common import auth as authutil
from ads.common import oci_client as oc
from ads.common import utils
from ads.common.decorator.runtime_dependency import (
runtime_dependency,
OptionalDependency,
runtime_dependency,
)
from ads.common import auth as authutil
from ads.common import oci_client as oc
from ads.config import (
OCI_IDENTITY_SERVICE_ENDPOINT,
NB_SESSION_COMPARTMENT_OCID,
PROJECT_OCID,
OCI_IDENTITY_SERVICE_ENDPOINT,
OCI_ODSC_SERVICE_ENDPOINT,
PROJECT_OCID,
)

create_notebook_details_attributes = CreateNotebookSessionDetails().swagger_types.keys()
Expand Down Expand Up @@ -210,8 +209,9 @@ def show_in_notebook(notebook_self):
"""
Describe the project by showing it's properties
"""
from IPython.core.display import display
from ads.common.utils import get_display

display = get_display()
display(notebook_self)

def _repr_html_(notebook_self):
Expand Down
Loading
Loading