craete json配置文件,用于优化RandomizedSearchCV中的参数

时间:2018-04-24 12:58:03

标签: python json scikit-learn grid-search

我定义了一个包含一些参数的字典,以便使用RandomizedSearchCV进行优化,如下所示

import numpy as np

from time import time
from scipy.stats import randint as sp_randint

from sklearn.model_selection import GridSearchCV
from sklearn.model_selection import RandomizedSearchCV
from sklearn.datasets import load_digits
from sklearn.ensemble import RandomForestClassifier

# get some data
digits = load_digits()
X, y = digits.data, digits.target

# build a classifier
clf = RandomForestClassifier(n_estimators=20)

# specify parameters and distributions to sample from
param_dist = {"max_depth": [3, None],
              "max_features": sp_randint(1, 11),
              "min_samples_split": sp_randint(1, 11),
              "min_samples_leaf": sp_randint(1, 11),
              "bootstrap": [True, False],
              "criterion": ["gini", "entropy"]}

# run randomized search
n_iter_search = 20
random_search = RandomizedSearchCV(clf, param_distributions=param_dist,
                                   n_iter=n_iter_search)

现在我想将相同的参数放在json文件中......是否可能?

我创建了一个json文件,如下所示

{
"max_depth": [3, null],
"max_features": ?,
"min_samples_split": ?,
"min_samples_leaf": ?,
"bootstrap": [true, false],
"criterion": ["gini", "entropy"]
}

但我不知道如何通过参数“

0 个答案:

没有答案