Prediction

# パッケージの読み込み
import os
os.environ['AKEBONO_DEBUG'] = 'true'

from akebono.dataset import get_dataset
from akebono.model.loader import get_trained_model
from akebono.preprocessor import get_preprocessor_for_prediction

import config
import akebono.settings as asettings
# 設定の適用
asettings.apply(config)
# train_configの確認
config.train_config
[{'dataset_config': {'dataset_loading_cache_enabled': True,
   'loader_config': {'name': 'iris'}},
  'dump_result_enabled': True,
  'evaluate_enabled': True,
  'fit_model_enabled': True,
  'model_config': {'evaluate_kwargs': {'cross_val_iterator': 'KFold@sklearn.model_selection',
    'cross_val_iterator_kwargs': {'n_splits': 10,
     'random_state': 0,
     'shuffle': True}},
   'model_type': 'multiple_classifier',
   'name': 'SklearnLogisticRegression'},
  'preprocessor_config': {'name': 'apply_standard_scaler'}},
 {'dataset_config': {'dataset_loading_cache_enabled': True,
   'loader_config': {'name': 'iris'}},
  'dump_result_enabled': True,
  'evaluate_enabled': True,
  'fit_model_enabled': True,
  'model_config': {'evaluate_kwargs': {'cross_val_iterator': 'KFold@sklearn.model_selection',
    'cross_val_iterator_kwargs': {'n_splits': 10,
     'random_state': 0,
     'shuffle': True}},
   'model_type': 'multiple_classifier',
   'name': 'SklearnLogisticRegression'}}]
# 訓練の実行
!akebono train -t tmp1
[INFO] 2019-05-01 06:00:18,647 ===== train start .. config: config ===== akebono.commands.models.train
[INFO] 2019-05-01 06:00:18,647 training .. id: 0 akebono.commands.models.train
[DEBUG] 2019-05-01 06:00:18,659 sklearn load_iris loader invoked. akebono.dataset.generator.sklearn
[DEBUG] 2019-05-01 06:00:18,662 dataset_loading_cache enabled .. None_e3b0c44298fc1c149afbf4c8_055aa78309b36ea9aeaf1e89_e3b0c44298fc1c149afbf4c8 set done. akebono.dataset.entry
[DEBUG] 2019-05-01 06:00:18,662 load dataset start. akebono.operator
[DEBUG] 2019-05-01 06:00:18,663 load dataset done. akebono.operator
[DEBUG] 2019-05-01 06:00:18,664 model_cls_str: LogisticRegression .. created. akebono.model._models.sklearn
[DEBUG] 2019-05-01 06:00:18,664 get_model done in train mode. akebono.model.entry
[DEBUG] 2019-05-01 06:00:18,664 evaluate start. akebono.operator
[DEBUG] 2019-05-01 06:00:18,665 processing .. operation_mode: train akebono.preprocessor.pipeline
[DEBUG] 2019-05-01 06:00:18,666 ApplyStandardScaler#process invoked akebono.preprocessor.statefulmodels
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
  FutureWarning)
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:459: FutureWarning: Default multi_class will be changed to 'auto' in 0.22. Specify the multi_class option to silence this warning.
  "this warning.", FutureWarning)
[DEBUG] 2019-05-01 06:00:18,670 processing .. operation_mode: train akebono.preprocessor.pipeline
[DEBUG] 2019-05-01 06:00:18,670 ApplyStandardScaler#process invoked akebono.preprocessor.statefulmodels
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
  FutureWarning)
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:459: FutureWarning: Default multi_class will be changed to 'auto' in 0.22. Specify the multi_class option to silence this warning.
  "this warning.", FutureWarning)
[DEBUG] 2019-05-01 06:00:18,673 processing .. operation_mode: train akebono.preprocessor.pipeline
[DEBUG] 2019-05-01 06:00:18,674 ApplyStandardScaler#process invoked akebono.preprocessor.statefulmodels
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
  FutureWarning)
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:459: FutureWarning: Default multi_class will be changed to 'auto' in 0.22. Specify the multi_class option to silence this warning.
  "this warning.", FutureWarning)
[DEBUG] 2019-05-01 06:00:18,677 processing .. operation_mode: train akebono.preprocessor.pipeline
[DEBUG] 2019-05-01 06:00:18,677 ApplyStandardScaler#process invoked akebono.preprocessor.statefulmodels
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
  FutureWarning)
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:459: FutureWarning: Default multi_class will be changed to 'auto' in 0.22. Specify the multi_class option to silence this warning.
  "this warning.", FutureWarning)
[DEBUG] 2019-05-01 06:00:18,680 processing .. operation_mode: train akebono.preprocessor.pipeline
[DEBUG] 2019-05-01 06:00:18,680 ApplyStandardScaler#process invoked akebono.preprocessor.statefulmodels
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
  FutureWarning)
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:459: FutureWarning: Default multi_class will be changed to 'auto' in 0.22. Specify the multi_class option to silence this warning.
  "this warning.", FutureWarning)
[DEBUG] 2019-05-01 06:00:18,683 processing .. operation_mode: train akebono.preprocessor.pipeline
[DEBUG] 2019-05-01 06:00:18,683 ApplyStandardScaler#process invoked akebono.preprocessor.statefulmodels
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
  FutureWarning)
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:459: FutureWarning: Default multi_class will be changed to 'auto' in 0.22. Specify the multi_class option to silence this warning.
  "this warning.", FutureWarning)
[DEBUG] 2019-05-01 06:00:18,686 processing .. operation_mode: train akebono.preprocessor.pipeline
[DEBUG] 2019-05-01 06:00:18,686 ApplyStandardScaler#process invoked akebono.preprocessor.statefulmodels
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
  FutureWarning)
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:459: FutureWarning: Default multi_class will be changed to 'auto' in 0.22. Specify the multi_class option to silence this warning.
  "this warning.", FutureWarning)
[DEBUG] 2019-05-01 06:00:18,689 processing .. operation_mode: train akebono.preprocessor.pipeline
[DEBUG] 2019-05-01 06:00:18,689 ApplyStandardScaler#process invoked akebono.preprocessor.statefulmodels
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
  FutureWarning)
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:459: FutureWarning: Default multi_class will be changed to 'auto' in 0.22. Specify the multi_class option to silence this warning.
  "this warning.", FutureWarning)
[DEBUG] 2019-05-01 06:00:18,692 processing .. operation_mode: train akebono.preprocessor.pipeline
[DEBUG] 2019-05-01 06:00:18,692 ApplyStandardScaler#process invoked akebono.preprocessor.statefulmodels
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
  FutureWarning)
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:459: FutureWarning: Default multi_class will be changed to 'auto' in 0.22. Specify the multi_class option to silence this warning.
  "this warning.", FutureWarning)
[DEBUG] 2019-05-01 06:00:18,695 processing .. operation_mode: train akebono.preprocessor.pipeline
[DEBUG] 2019-05-01 06:00:18,695 ApplyStandardScaler#process invoked akebono.preprocessor.statefulmodels
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
  FutureWarning)
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:459: FutureWarning: Default multi_class will be changed to 'auto' in 0.22. Specify the multi_class option to silence this warning.
  "this warning.", FutureWarning)
[DEBUG] 2019-05-01 06:00:18,715 evaluate done. akebono.operator
[DEBUG] 2019-05-01 06:00:18,715 fit start. akebono.operator
[DEBUG] 2019-05-01 06:00:18,715 processing .. operation_mode: train akebono.preprocessor.pipeline
[DEBUG] 2019-05-01 06:00:18,716 ApplyStandardScaler#process invoked akebono.preprocessor.statefulmodels
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
  FutureWarning)
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:459: FutureWarning: Default multi_class will be changed to 'auto' in 0.22. Specify the multi_class option to silence this warning.
  "this warning.", FutureWarning)
[DEBUG] 2019-05-01 06:00:18,735 fit done. akebono.operator
[DEBUG] 2019-05-01 06:00:18,735 dump_train_result start. akebono.operator
[DEBUG] 2019-05-01 06:00:18,735 dump_with_operation_rule invoked. akebono.preprocessor.pipeline
[DEBUG] 2019-05-01 06:00:18,735 dump_train_result done. akebono.operator
[INFO] 2019-05-01 06:00:18,751 training .. id: 1 akebono.commands.models.train
[DEBUG] 2019-05-01 06:00:18,752 dataset_loading_cache enabled .. None_e3b0c44298fc1c149afbf4c8_055aa78309b36ea9aeaf1e89_e3b0c44298fc1c149afbf4c8 get done. akebono.dataset.entry
[DEBUG] 2019-05-01 06:00:18,752 load dataset start. akebono.operator
[DEBUG] 2019-05-01 06:00:18,752 load dataset done. akebono.operator
[DEBUG] 2019-05-01 06:00:18,752 model_cls_str: LogisticRegression .. created. akebono.model._models.sklearn
[DEBUG] 2019-05-01 06:00:18,752 get_model done in train mode. akebono.model.entry
[DEBUG] 2019-05-01 06:00:18,752 evaluate start. akebono.operator
[DEBUG] 2019-05-01 06:00:18,753 processing .. operation_mode: train akebono.preprocessor.pipeline
[DEBUG] 2019-05-01 06:00:18,753 Identify#process invoked. akebono.preprocessor.statelessmodels
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
  FutureWarning)
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:459: FutureWarning: Default multi_class will be changed to 'auto' in 0.22. Specify the multi_class option to silence this warning.
  "this warning.", FutureWarning)
[DEBUG] 2019-05-01 06:00:18,755 processing .. operation_mode: train akebono.preprocessor.pipeline
[DEBUG] 2019-05-01 06:00:18,755 Identify#process invoked. akebono.preprocessor.statelessmodels
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
  FutureWarning)
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:459: FutureWarning: Default multi_class will be changed to 'auto' in 0.22. Specify the multi_class option to silence this warning.
  "this warning.", FutureWarning)
[DEBUG] 2019-05-01 06:00:18,756 processing .. operation_mode: train akebono.preprocessor.pipeline
[DEBUG] 2019-05-01 06:00:18,757 Identify#process invoked. akebono.preprocessor.statelessmodels
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
  FutureWarning)
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:459: FutureWarning: Default multi_class will be changed to 'auto' in 0.22. Specify the multi_class option to silence this warning.
  "this warning.", FutureWarning)
[DEBUG] 2019-05-01 06:00:18,758 processing .. operation_mode: train akebono.preprocessor.pipeline
[DEBUG] 2019-05-01 06:00:18,758 Identify#process invoked. akebono.preprocessor.statelessmodels
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
  FutureWarning)
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:459: FutureWarning: Default multi_class will be changed to 'auto' in 0.22. Specify the multi_class option to silence this warning.
  "this warning.", FutureWarning)
[DEBUG] 2019-05-01 06:00:18,760 processing .. operation_mode: train akebono.preprocessor.pipeline
[DEBUG] 2019-05-01 06:00:18,760 Identify#process invoked. akebono.preprocessor.statelessmodels
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
  FutureWarning)
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:459: FutureWarning: Default multi_class will be changed to 'auto' in 0.22. Specify the multi_class option to silence this warning.
  "this warning.", FutureWarning)
[DEBUG] 2019-05-01 06:00:18,761 processing .. operation_mode: train akebono.preprocessor.pipeline
[DEBUG] 2019-05-01 06:00:18,761 Identify#process invoked. akebono.preprocessor.statelessmodels
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
  FutureWarning)
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:459: FutureWarning: Default multi_class will be changed to 'auto' in 0.22. Specify the multi_class option to silence this warning.
  "this warning.", FutureWarning)
[DEBUG] 2019-05-01 06:00:18,763 processing .. operation_mode: train akebono.preprocessor.pipeline
[DEBUG] 2019-05-01 06:00:18,763 Identify#process invoked. akebono.preprocessor.statelessmodels
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
  FutureWarning)
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:459: FutureWarning: Default multi_class will be changed to 'auto' in 0.22. Specify the multi_class option to silence this warning.
  "this warning.", FutureWarning)
[DEBUG] 2019-05-01 06:00:18,764 processing .. operation_mode: train akebono.preprocessor.pipeline
[DEBUG] 2019-05-01 06:00:18,765 Identify#process invoked. akebono.preprocessor.statelessmodels
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
  FutureWarning)
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:459: FutureWarning: Default multi_class will be changed to 'auto' in 0.22. Specify the multi_class option to silence this warning.
  "this warning.", FutureWarning)
[DEBUG] 2019-05-01 06:00:18,766 processing .. operation_mode: train akebono.preprocessor.pipeline
[DEBUG] 2019-05-01 06:00:18,766 Identify#process invoked. akebono.preprocessor.statelessmodels
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
  FutureWarning)
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:459: FutureWarning: Default multi_class will be changed to 'auto' in 0.22. Specify the multi_class option to silence this warning.
  "this warning.", FutureWarning)
[DEBUG] 2019-05-01 06:00:18,768 processing .. operation_mode: train akebono.preprocessor.pipeline
[DEBUG] 2019-05-01 06:00:18,768 Identify#process invoked. akebono.preprocessor.statelessmodels
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
  FutureWarning)
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:459: FutureWarning: Default multi_class will be changed to 'auto' in 0.22. Specify the multi_class option to silence this warning.
  "this warning.", FutureWarning)
[DEBUG] 2019-05-01 06:00:18,786 evaluate done. akebono.operator
[DEBUG] 2019-05-01 06:00:18,786 fit start. akebono.operator
[DEBUG] 2019-05-01 06:00:18,786 processing .. operation_mode: train akebono.preprocessor.pipeline
[DEBUG] 2019-05-01 06:00:18,786 Identify#process invoked. akebono.preprocessor.statelessmodels
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.
  FutureWarning)
/usr/local/lib/python3.5/dist-packages/sklearn/linear_model/logistic.py:459: FutureWarning: Default multi_class will be changed to 'auto' in 0.22. Specify the multi_class option to silence this warning.
  "this warning.", FutureWarning)
[DEBUG] 2019-05-01 06:00:18,805 fit done. akebono.operator
[DEBUG] 2019-05-01 06:00:18,805 dump_train_result start. akebono.operator
[DEBUG] 2019-05-01 06:00:18,805 dump_with_operation_rule invoked. akebono.preprocessor.pipeline
[DEBUG] 2019-05-01 06:00:18,805 dump_train_result done. akebono.operator
[INFO] 2019-05-01 06:00:18,822 ===== train done ===== akebono.commands.models.train
[DEBUG] 2019-05-01 06:00:18,822 train normally completed. __main__
# 予測用データセットのconfig
dataset_config = {
    'loader_config': {
        'name': 'iris',
    },
    'target_column': None, # 予測の際は、target_columnをNoneにする
}
dataset = get_dataset(dataset_config)
[DEBUG] 2019-05-01 06:00:45,129 sklearn load_iris loader invoked. akebono.dataset.generator.sklearn
[DEBUG] 2019-05-01 06:00:45,132 dataset_loading_cache enabled .. None_e3b0c44298fc1c149afbf4c8_055aa78309b36ea9aeaf1e89_e3b0c44298fc1c149afbf4c8 set done. akebono.dataset.entry
# 予測で使うモデルの指定
scenario_tag = 'tmp1'
train_id = '0'

# モデルと、前処理モジュールの読み込み
model, model_config = get_trained_model(scenario_tag, train_id)
preprocessor = get_preprocessor_for_prediction(scenario_tag, train_id)
[DEBUG] 2019-05-01 06:00:54,146 train_result is None .. load from scenario_tag: tmp1, train_id: 0 akebono.model.loader
[DEBUG] 2019-05-01 06:00:54,147 dirpath: _storage/default/operation_results/tmp1 akebono.io.operation.loader
[DEBUG] 2019-05-01 06:00:54,149 model_cls_str: LogisticRegression .. created. akebono.model._models.sklearn
[DEBUG] 2019-05-01 06:00:54,150 get_model done in predict mode. akebono.model.entry
[DEBUG] 2019-05-01 06:00:54,151 train_result is None .. load from scenario_tag: tmp1, train_id: 0 akebono.preprocessor.entry
[DEBUG] 2019-05-01 06:00:54,152 dirpath: _storage/default/operation_results/tmp1 akebono.io.operation.loader
[DEBUG] 2019-05-01 06:00:54,153 load_with_operation_rule invoked. akebono.preprocessor.pipeline
# datasetから予測用した入力を取得し、前処理を実行
# fXが前処理後のデータで、モデルへの入力となる
X = dataset.get_predictor()
fX, _ = preprocessor.process(X, None)
[DEBUG] 2019-05-01 06:01:03,369 processing .. operation_mode: predict akebono.preprocessor.pipeline
[DEBUG] 2019-05-01 06:01:03,373 ApplyStandardScaler#process invoked akebono.preprocessor.statefulmodels
# 予測の実行
model.predict(fX)
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 1, 2, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1,
       1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1,
       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2,
       2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
       2, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2])