<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Preparing dataset of kaggle "dogs and cats".
https
Step1:  download dataset
Step2:  Copy files to valid and sample
Step3:  Arrangement files
<ASSISTANT_TASK:>
Python Code:
%%bash
source activate  root # you need to change here to your env name
pip install kaggle-cli
Explanation: Preparing dataset of kaggle "dogs and cats".
https://www.kaggle.com/c/dogs-vs-cats-redux-kernels-edition
This script is based on
https://github.com/fastai/courses/blob/master/deeplearning1/nbs/dogs_cats_redux.ipynb
Installing "kg" command
https://github.com/floydwch/kaggle-cli
End of explanation
%%bash
source activate  root # you need to change here to your env name
rm -rf data
mkdir -p data
pushd data
  kg download
  unzip -q train.zip
  unzip -q test.zip
popd
Explanation: download dataset
End of explanation
from glob import glob
import numpy as np
from shutil import move, copyfile
%mkdir -p data/train
%mkdir -p data/valid
%mkdir -p data/sample/train
%mkdir -p data/sample/valid
%pushd data/train
g = glob('*.jpg')
shuf = np.random.permutation(g)
for i in range(200): copyfile(shuf[i], '../sample/train/' + shuf[i])
shuf = np.random.permutation(g)
for i in range(200): copyfile(shuf[i], '../sample/valid/' + shuf[i])
# validation files are moved     
shuf = np.random.permutation(g)
for i in range(1000): move(shuf[i], '../valid/' + shuf[i])
%popd
Explanation: Copy files to valid and sample
End of explanation
%pushd data/train
%     mkdir cat dog
%     mv cat*.jpg cat
%     mv dog*.jpg dog
%popd
%pushd data/valid
%     mkdir cat dog
%     mv cat*.jpg cat
%     mv dog*.jpg dog
%popd
%pushd data/sample/train
%     mkdir cat dog
%     mv cat*.jpg cat
%     mv dog*.jpg dog
%popd
%pushd data/sample/valid
%     mkdir cat dog
%     mv cat*.jpg cat
%     mv dog*.jpg dog
%popd
%pushd data/test
%     mkdir unknown
%     mv *.jpg unknown
%popd
Explanation: Arrangement files
End of explanation
<END_TASK>