2016-05-23 23 views
1

我正在嘗試對DNN迴歸的步驟,learning_rate和batch_size進行網格搜索。我試圖用這個簡單的例子來做到這一點,這裏顯示的波士頓數據集boston example然而,我無法讓它工作。它不會拋出任何錯誤,它只是運行並運行並運行。即使我設置了一個點的網格,它也會這樣做。 您是否在下面看到任何錯誤?我錯過了明顯的東西嗎? 我對sklearn和skflow都很陌生(我知道,skflow已經合併到Tensorflow Learn中,但我認爲這個例子應該是一樣的),但我只是結合了我發現的例子。即使網格只是一個點,帶有skflow/TF的Gridsearchcv也會永久運行

from sklearn import datasets, cross_validation, metrics 
from sklearn import preprocessing, grid_search 
import skflow 

# Load dataset 
boston = datasets.load_boston() 
X, y = boston.data, boston.target 

# Split dataset into train/test 
X_train, X_test, y_train, y_test=cross_validation.train_test_split(X, y,test_size=0.2, random_state=42) 

# scale data (training set) to 0 mean and unit Std. dev 
scaler = preprocessing.StandardScaler() 
X_train = scaler.fit_transform(X_train) 
regressor = skflow.TensorFlowDNNRegressor(hidden_units=[10, 10], 
steps=5000, learning_rate=0.1, batch_size=10) 

# use a full grid over all parameters 
param_grid = {"steps": [200,400], 
       "learning_rate": [0.1,0.2], 
       "batch_size": [10,32]} 

# run grid search 
gs = grid_search.GridSearchCV(regressor, param_grid=param_grid, scoring = 'accuracy', verbose=10, n_jobs=-1,cv=2) 
gs.fit(X_train, y_train) 

# summarize the results of the grid search 
print(gs.best_score_) 
print(gs.best_params_) 

感謝您的任何幫助!

回答

0

將fit_params添加到gird_search else TensorFlowDNNRegressor永遠運行。

gs = grid_search.GridSearchCV(
     regressor, param_grid=param_grid, 
     scoring = 'accuracy', verbose=10, n_jobs=-1,cv=2 
    ) 

gs = grid_search.GridSearchCV(
     regressor, param_grid=param_grid, scoring = 'accuracy', 
     verbose=10, n_jobs=-1,cv=2, fit_params={'steps': [200,400]} 
) 
相關問題