機械翻訳について

Embedded Python Executionについて

Embedded Python Executionは、Python用のOracle Machine Learning (OML4Py)の機能で、ユーザーはユーザー定義Python関数をOracleデータベース・インスタンスで直接起動できます。

詳細は、「Oracle Machine Learning for Pythonユーザーズ・ガイド」Embedded Python Executionを参照してください。

次の例では、埋込み実行の使用方法を示すために、空間回帰モデルを準備します。 このモデルは、埋込み実行を使用してPython関数を起動する方法を説明するこの章の後続のトピックで使用します。これには、そのモデルを使用して予測を行う関数を作成した後、その関数を使用してPython、SQLおよびRESTからの埋込み実行を実行する方法が含まれます。

ステップの例は次のとおりです:

  1. block_groups SpatialDataFrameおよびSpatialErrorRegressorを使用して、リプレッサ・モデルを定義します。
  2. 前処理ステップを使用して空間パイプラインを作成し、データを標準化し、後処理ステップとしてリプレッサを作成します。
  3. MEDIAN_INCOMEをターゲット変数として使用してモデルをトレーニングします。
from oraclesai.preprocessing import spatial_train_test_split
from oraclesai.weights import KNNWeightsDefinition
from oraclesai.regression import SpatialErrorRegressor
from oraclesai.pipeline import SpatialPipeline
from sklearn.preprocessing import StandardScaler
 
# Define variables
X = block_groups[["MEDIAN_INCOME", "MEAN_AGE", "HOUSE_VALUE", "geometry"]]
 
# Define training and test sets
X_train, X_test, _, _, _, _ = spatial_train_test_split(X, y="MEDIAN_INCOME", test_size=0.2, random_state=32)
 
# Create instance of SpatialErrorRegressor
spatial_error_model = SpatialErrorRegressor(spatial_weights_definition=KNNWeightsDefinition(k=5))
 
# Add the model into a Spatial Pipeline along with a pre-processing step
spatial_error_pipeline = SpatialPipeline([("scaler", StandardScaler()), ("spatial_error", spatial_error_model)])
 
# Train the model with MEDIAN_INCOME as the target variable
spatial_error_pipeline.fit(X_train, "MEDIAN_INCOME")

モデルがトレーニングされたら、モデルをOML4Pyデータストアに保存します。

oml.ds.save({'spatial_error': spatial_error_pipeline}, 
    'spatial_error_ds', description='some description', 
    overwrite=True)