1

I am trying to do a gridsearch over steps, learning_rate and batch_size of a DNN regression. I've tried to do this with the simple example, the Boston dataset shown here boston example however, I can't get it to work. It does not throw any error, it just runs and runs and runs. It does this even if I set up a grid of a single point. Do you see any error in the below? Do I miss something obvious? I am new to both sklearn and skflow (I know, skflow has been merged into Tensorflow Learn, but I think the example should be the same), but I just combined the examples I found.

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_)

Thanks for any help!!

grinsbaeckchen
  • 531
  • 1
  • 6
  • 15

1 Answers1

0

Add fit_params to gird_search else TensorFlowDNNRegressor runs forever.

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

to

gs = grid_search.GridSearchCV(
         regressor, param_grid=param_grid, scoring = 'accuracy',
         verbose=10, n_jobs=-1,cv=2, fit_params={'steps': [200,400]}
)
Reporter
  • 3,897
  • 5
  • 33
  • 47