【发布时间】:2021-07-01 10:39:02
【问题描述】:
我有一个用于开发目的的脚本,我想在本地运行和调试。但是,我不想将实验所需的数据存储在本地机器上。
我在 Azure 机器学习工作室中使用 azureml 库。请参阅下面的代码
# General
import os
import argparse
# Data analysis and wrangling
import pandas as pd
# Machine learning
from sklearn.model_selection import GridSearchCV
from sklearn.svm import SVC
from azureml.core import Run
# Get the environment of this run
run = Run.get_context()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
'--data_path',
type=str,
help='Path to the training data',
# The default path is on my local machine, however I would like to reference a remote datastore on Azure as a parameter to this script
default=os.path.join(os.getcwd(), 'data')
)
args = parser.parse_args()
# Obtain the data from the datastore
train_df = pd.read_csv(os.path.join(args.data_path, os.listdir(args.data_path)[0]))
# Drop unnecessary columns
train_df = train_df.drop(['Name', 'PassengerId', 'Ticket', 'Cabin'], axis=1)
# Encode non-numeric features as dummies
train_df = pd.get_dummies(train_df)
# Drop NA's
train_df.dropna(inplace=True)
# Use gridsearch CV to find the best parameters for the model
parameters = {'kernel': ('linear', 'rbf'),
'C': [1, 10]}
# Initialize the grid search
search = GridSearchCV(SVC(), param_grid=parameters, cv=8)
# Train the model
search.fit(train_df.drop("Survived", axis=1), train_df["Survived"])
现在,脚本使用本地文件夹“数据”。但是,我想为此脚本提供一个参数,表明我想在 Azure 机器学习工作室中使用远程数据存储。我怎样才能做到这一点?
【问题讨论】:
标签: python azure-machine-learning-studio azureml