2017-03-29 144 views
2

我有一個問題,我想測試多個不具有相同命名參數的模型。您如何使用randomizedSearchCV中管道的參數列表,就像在本例中可以使用GridSearchCV一樣?sklearn randomizedSearchCV中的參數列表像GridSearchCV?

實施例從:
http://scikit-learn.org/stable/auto_examples/plot_compare_reduction.html

N_FEATURES_OPTIONS = [2, 4, 8] 
C_OPTIONS = [1, 10, 100, 1000] 
param_grid = [ 
    { 
     'reduce_dim': [PCA(iterated_power=7), NMF()], 
     'reduce_dim__n_components': N_FEATURES_OPTIONS, 
     'classify__C': C_OPTIONS 
    }, 
    { 
     'reduce_dim': [SelectKBest(chi2)], 
     'reduce_dim__k': N_FEATURES_OPTIONS, 
     'classify__C': C_OPTIONS 
    }, 
] 

grid = GridSearchCV(pipe, cv=3, n_jobs=2, param_grid=param_grid) 
digits = load_digits() 
grid.fit(digits.data, digits.target) 

回答

-1

在您使用在gridsearchCV的param_grid參數,可以在randomizedSearchCV使用param_distribution參數。

the documentation: -

param_distributions:字典辭典參數名稱(字符串) 作爲參數鍵和分佈或列表嘗試。分佈 必須提供採樣的rvs方法(例如來自 scipy.stats.distributions的那些方法)。 如果給出了一個列表,它將被統一取樣

Scikit文檔有一個比較兩種技術的很好的例子。請看看它:

相關問題