MaxFrame; oturumları yönetmek, MaxCompute tablolarını okuyup yazmak, dağıtık hesaplamayı tetiklemek ve sonuçları yerel olarak almak için standart pandas arayüzünün ötesinde bir dizi API sunar.
Oturum
new_session
Kaynak kodu: new_session
new_session(
session_id: str = None,
default: bool = True,
new: bool = True,
odps_entry: Optional[ODPS] = None
)
Bir MaxFrame oturumu oluşturur ve MaxCompute ile bağlantı kurar.
Parametreler
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Döndürülenler: Oturum nesnesi.
Örnek
import os
from maxframe import new_session
from odps import ODPS
# Initialize the MaxCompute entry object.
# Store credentials in environment variables — do not hardcode them.
o = ODPS(
os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID'),
os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET'),
project='your-default-project',
endpoint='your-endpoint',
)
# Create the MaxFrame session.
session = new_session(odps_entry=o)
Giriş/Çıkış
Aşağıdaki işlevler MaxCompute'dan veri okur ve MaxCompute'a veri yazar.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
read_odps_table ve read_odps_query arasında seçim yapma: Belirli bir tablodan (isteğe bağlı bölüm ve sütun filtreleriyle) okuma yaparken read_odps_table kullanın. SQL düzeyinde filtreleme veya birden çok tablo arasında birleştirme (join) işlemi gerektiğinde read_odps_query kullanın.
read_odps_table
Kaynak kodu: read_odps_table
read_odps_table(
table_name: Union[str, Table],
partitions: Union[None, str, List[str]] = None,
columns: Optional[List[str]] = None,
index_col: Union[None, str, List[str]] = None,
odps_entry: ODPS = None,
string_as_binary: bool = None,
append_partitions: bool = False
)
Verileri bir MaxCompute tablosundan okur ve DataFrame olarak döndürür. Dizin sütunları belirtilmezse bir RangeIndex oluşturulur.
Parametreler
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Döndürülenler: Bir DataFrame nesnesi.
Örnek
import maxframe.dataframe as md
df = md.read_odps_table(
'BIGDATA_PUBLIC_DATASET.data_science.maxframe_ml_100k_users',
index_col='user_id',
columns=['age', 'sex']
)
print(df.execute().fetch())
# Output:
# age sex
# user_id
# 1 24 M
# 2 53 F
# 3 23 M
# 4 24 M
# 5 33 F
# ... ... ..
# 939 26 F
# 940 32 M
# 941 20 M
# 942 48 F
# 943 22 M
#
# [943 rows x 2 columns]
read_odps_query
Kaynak kodu: read_odps_query
read_odps_query(
query: str,
odps_entry: ODPS = None,
index_col: Union[None, str, List[str]] = None,
string_as_binary: bool = None
)
Bir MaxCompute SQL sorgusu çalıştırır ve sonuçları DataFrame olarak döndürür. Dizin sütunları belirtilmezse bir RangeIndex oluşturulur.
Parametreler
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Döndürülenler: Bir DataFrame nesnesi.
Örnek
import maxframe.dataframe as md
df = md.read_odps_query(
'SELECT user_id, age, sex FROM `BIGDATA_PUBLIC_DATASET.data_science.maxframe_ml_100k_users`'
)
to_odps_table
Kaynak kodu: to_odps_table
to_odps_table(
table: Union[Table, str],
partition: Optional[str] = None,
partition_col: Union[None, str, List[str]] = None,
overwrite: bool = False,
unknown_as_string: Optional[bool] = None,
index: bool = True,
index_label: Union[None, str, List[str]] = None,
lifecycle: Optional[int] = None
)
Bir DataFrame'i MaxCompute tablosuna yazar. Tablo yoksa MaxFrame otomatik olarak oluşturur.
Parametreler
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Döndürülenler: Bir DataFrame nesnesi.
Örnek
import maxframe.dataframe as md
df = md.read_odps_query(
'SELECT user_id, age, sex FROM `BIGDATA_PUBLIC_DATASET.data_science.maxframe_ml_100k_users`',
index_col='user_id'
)
df.to_odps_table('output_table', lifecycle=7)
to_odps_model
to_odps_model(
model_name: str,
model_version: str = None,
schema: str = None,
project: str = None,
description: Optional[str] = None,
version_description: Optional[str] = None,
create_model: bool = True,
set_default_version: bool = False
)
Bir MaxFrame işinde eğitilen XGBoost modelini MaxCompute model nesnesi olarak kaydeder. Kaydetme işlemini tetiklemek için döndürülen Scalar üzerinde .execute() çağrısı yapın.
Parametreler
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Döndürülenler: Bir Scalar nesnesi. Model kaydetme işlemini tetiklemek için .execute() çağrısı yapın.
Örnek
from maxframe.learn.contrib.xgboost import XGBClassifier
import maxframe.dataframe as md
# Train an XGBoost model.
X_df = md.DataFrame(X, columns=cols)
clf = XGBClassifier(n_estimators=10)
clf.fit(X_df, y)
# Save the model to MaxCompute.
clf.to_odps_model(
model_name='my_model',
# If project and schema are not specified separately,
# use the format: model_name='project.schema.my_model'
model_version='version1'
).execute()
Çalıştırma
execute
Kaynak kodu: execute
execute(
session: SessionType = None
)
Veri işleme görevini yürütülmek üzere MaxCompute'a gönderir. MaxFrame tembel yürütme (lazy execution) kullandığından DataFrame üzerindeki işlemler execute() çağrılana kadar hesaplanmaz.
Parametreler
|
|
|
|
|
|
|
|
|
|
|
|
Döndürülenler: Yok.
Örnek
import maxframe.dataframe as md
df = md.read_odps_query(
'SELECT user_id, age, sex FROM BIGDATA_PUBLIC_DATASET.data_science.maxframe_ml_100k_users',
index_col='user_id'
)
df.execute()
Getirme
fetch
Kaynak kodu: fetch
fetch(
session: SessionType = None
)
Hesaplama sonucunu MaxCompute'tan alır ve yerel ortamınızda pandas DataFrame veya Series olarak döndürür. Her zaman execute() yöntemini fetch() yönteminden önce çağırın.
Parametreler
|
|
|
|
|
|
|
|
|
|
|
|
Döndürülenler: Bir pandas DataFrame veya Series.
Örnek
import maxframe.dataframe as md
df = md.read_odps_query(
'SELECT user_id, age, sex FROM `BIGDATA_PUBLIC_DATASET.data_science.maxframe_ml_100k_users`',
index_col='user_id'
)
result = df.execute().fetch()
print(result)
# Output:
# age sex
# user_id
# 1 24 M
# 2 53 F
# 3 23 M
# 4 24 M
# 5 33 F
# ... ... ..
# 939 26 F
# 940 32 M
# 941 20 M
# 942 48 F
# 943 22 M
#
# [943 rows x 2 columns]