Autosklearnインストール(mac版)


python 3が必要な環境
swig 3のインストール
ruby -e "$(curl --insecure -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install swig3
指定したフォルダに書き込み権限を付与:sudo chmode 777フォルダ
brew link swig
 
xgboostのインストール:
cd ~ git clone --recursive https://github.com/dmlc/xgboost
brew install gcc --without-multilib
cd xgboost; cp make/minimum.mk ./config.mk; make -j4
cd python-package; sudo python setup.py install
Autosklearnのインストール
pip install auto-sklearn
次のようにエラーが発生した場合:
XGBoostLibraryNotFound: Cannot find XGBoost Library in the candidate path, did you install compilers and run build.sh in root path?
List of candidates:
/private/var/folders/xw/cvs2qk9d77vc8fgn7zyvp84sqjlg4_/T/pip-install-25jfq24s/xgboost/xgboost/libxgboost.dylib
/private/var/folders/xw/cvs2qk9d77vc8fgn7zyvp84sqjlg4_/T/pip-install-25jfq24s/xgboost/xgboost/../../lib/libxgboost.dylib
/private/var/folders/xw/cvs2qk9d77vc8fgn7zyvp84sqjlg4_/T/pip-install-25jfq24s/xgboost/xgboost/./lib/libxgboost.dylib
/Users/..../.conda/envs/untitled/xgboost/libxgboost.dylib
次にxgboostの下のlibxgboost.dylibは、プロンプトのデフォルトディレクトリに挿入されます.
cp libxgboost.dylib/Users/...../.conda/envs/untitled/xgboost/
 
pip install auto-sklearn
エラーが発生した場合:
手動でpyrfrをインストールする
pyrfrのインストールに関する注意事項:
pyrfr==0.6.1、ダウンロードアドレスhttps://pypi.python.org/pypi/pyrfr/0.6.1
上記のパッケージをダウンロードする解凍し、解凍してインストールファイルsetupを修正する.py
extra_compile_args = ['-O2', '-std=c++11']
extra_compile_args = ['-O2', '-std=c++11', '-stdlib=libc++', '-mmacosx-version-min=10.7']
 
cd pyrfr-0.6.1/
python setup.py install
brew link pcre
最後に、
pip install auto-sklearn
import sklearn.model_selection
import sklearn.datasets
import sklearn.metrics

import autosklearn.classification


def main():
    X, y = sklearn.datasets.load_digits(return_X_y=True)
    X_train, X_test, y_train, y_test = \
        sklearn.model_selection.train_test_split(X, y, random_state=1)

    automl = autosklearn.classification.AutoSklearnClassifier(
        time_left_for_this_task=120,
        per_run_time_limit=30,
        tmp_folder='/tmp/autosklearn_holdout_example_tmp',
        output_folder='/tmp/autosklearn_holdout_example_out',
        disable_evaluator_output=False,
        # 'holdout' with 'train_size'=0.67 is the default argument setting
        # for AutoSklearnClassifier. It is explicitly specified in this example
        # for demonstrational purpose.
        resampling_strategy='holdout',
        resampling_strategy_arguments={'train_size': 0.67}
    )
    automl.fit(X_train, y_train, dataset_name='digits')

    # Print the final ensemble constructed by auto-sklearn.
    print(automl.show_models())
    predictions = automl.predict(X_test)
    # Print statistics about the auto-sklearn run such as number of
    # iterations, number of models failed with a time out.
    print(automl.sprint_statistics())
    print("Accuracy score", sklearn.metrics.accuracy_score(y_test, predictions))


if __name__ == '__main__':
    main()