簡體   English   中英

Sklearn MLP分類器隱藏層優化(RandomizedSearchCV)

[英]Sklearn MLP Classifier Hidden Layers Optimization (RandomizedSearchCV)

我設置了以下參數:

parameter_space = {
    'hidden_layer_sizes': [(sp_randint.rvs(100,600,1),sp_randint.rvs(100,600,1),), (sp_randint.rvs(100,600,1),)],
    'activation': ['tanh', 'relu', 'logistic'],
    'solver': ['sgd', 'adam', 'lbfgs'],
    'alpha': stats.uniform(0.0001, 0.9),
    'learning_rate': ['constant','adaptive']}

除hidden_​​layer_sizes以外的所有參數均按預期工作。

當前,hidden_​​layer_sizes random值是預先計算的,並且在所有迭代中保持不變。

有沒有一種方法可以針對RandomizedSearchCV每次迭代, RandomizedSearchCV選擇1或2層MLP,其中隱藏層神經元在100到600之間。

有任何想法/其他相關提示嗎?

RandomizedSearchCV使用ParameterSampler ,該參數期望有一個隨機采樣的列表或一個具有屬性 rvs()的對象。 您可以通過模仿這個對象

class RandIntMatrix(object):
    def __init__(self, low, high, shape=(1)):
        self.low = low
        self.high = high
        self.shape = shape

    def rvs(self, random_state=None):
        np.random.seed(random_state)
        return np.random.randint(self.low, self.high, self.shape)

print (RandIntMatrix(100, 600, 3).rvs())  # [ 506 124 310]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM