Google Cloud Machine Learning

1. Create an Google Compute Engine Instance
2. Activate the Google Machine Learning API under this project
3. Create an Google Storage Bucket
4. Login to the Google Compute Engine, create a folder for the ML project, in my case I called it MLtest. Inside this folder, two basic configuration files are required.

a. config.yaml

It is important to set “runtimeVersion” to be the latest, otherwise, some functions may not be available.

  scaleTier: BASIC
  runtimeVersion: "1.7"
  pythonVersion: '3.5'


from setuptools import setup, find_packages

  description='example to run keras on gcloud ml-engine',
  author='Jianping Lai',
      'xgboost', ### put required packages here

5. The file inside the folder shows the structure blow.

├── config.yaml
├── input
│   ├── input.csv
│   └── test.pkl
├── output
│   └── test-output.pkl
├── run
└── train

to run a training module LOCALLY, such as, you type

python -m train.8-output

In order to submit the job to Google Cloud ML, the following command is required,

gcloud ml-engine jobs submit training tbjc_ml32 \
  	--package-path train \
        --module-name train.8-output \
        --region us-east1 \
        --config config.yaml \
	--staging-bucket gs://tbjc1magic-deeplearning/ \
        -- \   ### after this line everything will be cmd line args
        --input_dir gs://tbjc1magic-deeplearning/ 
        ###  ['--input_dir', 'gs://tbjc1magic-deeplearning/'] for main func

However, users will not be able to read and write directory to the cloud storage bucket. As this being said, below commands will NOT work.

with open('gs://tbjc1magic-deeplearning/', 'w') as f:

File IO can to be handle through

from import file_io

base = 'gs://tbjc1magic-deeplearning/'

with file_io.FileIO(base + 'output/test-output.pkl', mode='w') as f:
    pickle.dump(data, f)

Similarly, you can read a file through the same way.

6. To check the current status of jobs,

gcloud ml-engine jobs list


Anaconda virtual environment setup python 2, 3 and R

After install anaconda 3

## set up python 2 environment
conda create --n python2 python=2.7
source activate python2
conda install ipykernel
python -m ipykernel install --user --name python2
## set up R environment

conda create -n r anaconda
source activate r
### install R kernel ####
conda install -c r r
### install notebook R kernel ###
conda install -c r r-irkernel
### install R packages ###
conda install -c r r-essentials
conda install -c r ggplot
conda install -c r r-nlme
conda install -c r r-lme4