如何将数据集链接到GCP中的模型



我第一次尝试在GCP中建模,但我找不到也不知道如何将数据链接到上的模型。在我的脚本中,我通常会从这个路径写入read_csv。

我知道我必须把它加载到谷歌云存储。这是一个csv,我正在运行xgb分类。问题是如何链接这些东西,以便脚本知道在上面运行它。。。

#read in the file
#ds
#model
import xgboost as xgb
from sklearn.model_selection import train_test_split
y=ds[["Label_Num","ShotPlus"]]
y["Player"]=shots2["Player"]
#adjust in i
X=ds.drop(["ShotPlus", "Label_Num",
#,"DSL_Available_Bandwidth","Band_2_DSL_rel","DSL_vals"
],axis=1)
X_train, X_test, y_train1,y_test1=train_test_split(X,y, test_size=0.3, random_state=785)
y_test = y_test1[["Label_Num"]]
y_train = y_train1[["Label_Num"]]
dtrain=xgb.DMatrix(X_train,label=y_train)
dtest=xgb.DMatrix(X_test,label=y_test)
params={
'max_depth':6,
'min_child_weight': 4,
'eta':0.1,
'subsample': 0.8,
'colsample_bytree': 0.8,
#     "scale_pos_weight" : 8, #change me
# Other parameters
#     'eval_metric' : "auc",
'objective':'multi:softprob',
"num_class":7,
'seed':123
}
num_boost_round = 999
mod_addK=xgb.train(params,
dtrain,
num_boost_round=num_boost_round,
evals=[(dtest, "Test")],
early_stopping_rounds=10)

我还没有找到作为CSV文件加载的示例。这在tf.dataset中读取,这告诉我它是如何在使用AutoML分类模型的过程中工作的。但是,对于我已经编写了自己的代码并想对其进行调整的自定义工作,它是如何工作的呢?

上面的代码将是建立我自己的源代码分发的任务元素,需要添加元素来编写它。这是我从GCS页面上获得的。

artifact_filename = 'ShotTypeModel.pkl'
# Save model artifact to local filesystem (doesn't persist)
local_path = artifact_filename
with open(local_path, 'wb') as model_file:
pickle.dump(mod_addK, model_file)
# Upload model artifact to Cloud Storage
model_directory = os.environ['AIP_MODEL_DIR']
storage_path = os.path.join(model_directory, artifact_filename)
blob = storage.blob.Blob.from_string(storage_path, client=storage.Client())
blob.upload_from_filename(local_path)

谷歌网站上有很多文档听起来应该会有所帮助,但不要告诉我具体情况。例如在自定义培训应用中使用托管数据集

答案是bucket提供了一个url,而这正是加载数据所需要的。

您还需要包含gcsfs包才能完成这项工作。

from google.cloud import storage
import os
import gcsfs
import pandas as pd
import pickle
#read in the file
print("Mod script starts")
ds = pd.read_csv("gs://shottypeids/ShotTypeModel_alldata.csv")

最新更新