1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| param_grid = { "C":[0.1,0.3,0.5,0.7,0.9,1.0,1.3,1.5,1.7,2.0], "kernel":["linear","poly","rbf","sigmoid"] } model = SVC() kfold = KFold(n_splits=5,random_state=42) grid = GridSearchCV(estimator=model,param_grid=param_grid,scoring="accuracy",cv=kfold) grid_result = grid.fit(X,y) print("Best: {} using {}".format(grid_result.best_score_,grid_result.best_params_)) means = grid_result.cv_results_["mean_test_score"] stds = grid_result.cv_results_["std_test_score"] params = grid_result.cv_results_["params"] for mean,stdev,param in zip(means,stds,params): print("{} ({}) with {}".format(mean,stdev,param))
from sklearn.model_selection import RandomizedSearchCV from scipy.stats import randint
param_distribs = { 'n_estimators': randint(low=1, high=200), 'max_features': randint(low=1, high=8), }
forest_reg = RandomForestRegressor(random_state=42) rnd_search = RandomizedSearchCV(forest_reg, param_distributions=param_distribs, n_iter=10, cv=5, scoring='neg_mean_squared_error', random_state=42) rnd_search.fit(housing_prepared, housing_labels)
|