gridsearchcv

Solutions on MaxInterview for gridsearchcv by the best coders in the world

showing results for - "gridsearchcv"
Faye
21 Jan 2019
1x_train,x_test,y_train,y_test=train_test_split(x,y,random_state=50)
2xgb=XGBClassifier()
3----------------------------------------------------------------------
4from sklearn.model_selection import GridSearchCV
5parameters=[{'learning_rate':[0.1,0.2,0.3,0.4],'max_depth':[3,4,5,6,7,8],'colsample_bytree':[0.5,0.6,0.7,0.8,0.9]}]
6            
7gscv=GridSearchCV(xgb,parameters,scoring='accuracy',n_jobs=-1,cv=10)
8grid_search=gscv.fit(x,y)
9grid_search.best_params_
10-----------------------------------------------------------------------
11x_train,x_test,y_train,y_test=train_test_split(x,y,random_state=50)
12xgb=XGBClassifier(colsample_bytree=0.8, learning_rate=0.4, max_depth=4)
13xgb.fit(x,y)
14pred=xgb.predict(x_test)
15print('Accuracy=  ',accuracy_score(y_test,pred))
16-----------------------------------------------------------------------
17#Cross validating (for classification) the model and checking the cross_val_score,model giving highest score will be choosen as final model.
18from sklearn.model_selection import cross_val_predict
19xgb=XGBClassifier(colsample_bytree=0.8, learning_rate=0.4, max_depth=4)
20cvs=cross_val_score(xgb,x,y,scoring='accuracy',cv=10)
21print('cross_val_scores=  ',cvs.mean())
22y_pred=cross_val_predict(xgb,x,y,cv=10)
23conf_mat=confusion_matrix(y_pred,y)
24conf_mat
25---------------------------------------------------------------------------
26#Cross validating(for regression) the model and checking the cross_val_score,model giving highest score will be choosen as final model.
27gbm=GradientBoostingRegressor(max_depth=7,min_samples_leaf=1,n_estimators=100)
28cvs=cross_val_score(xgb,x,y,scoring='r2',cv=5)
29print('cross_val_scores=  ',cvs.mean())
30-------------------------------------------------------------------------------
31#parameters
32#xgboost:-
33parameters=[{'learning_rate':[0.1,0.2,0.3,0.4],'max_depth':[3,4,5,6,7,8],'colsample_bytree':[0.5,0.6,0.7,0.8,0.9]}]
34#random forest
35parameters=[{'max_depth':[5,7,9,10],'min_samples_leaf':[1,2],'n_estimators':[100,250,500]}]
36#gradientboost
37parameters=[{'max_depth':[5,7,9,10],'min_samples_leaf':[1,2],'n_estimators':[100,250,500]}]
38#kneighbors
39parameters={'n_neighbors':[5,6,8,10,12,14,15]}
40#logistic regression
41parameters={'penalty':['l1','l2'],'C':[1,2,3,4,5]}
42#gaussiannb
43parameters={'var_smoothing': np.logspace(0,-9, num=100)}
44#SVC
45parameters=[{'C':[0.1,0.5,1,2,3],'kernel':['rbf','poly']}]
46#adaboost
47parameters=[{'base_estimator':[lr],'learning_rate':[1,0.1,0.001],'n_estimators':[100,150,250]}]
48#decesion tree
49parameters=[{'criterion':['gini','entropy'],'max_depth':[5,7,9,10],'min_samples_leaf':[1,2]}]
Maeline
06 Jun 2016
1from sklearn.svm import LinearSVC
2from sklearn.linear_model import LogisticRegression
3from sklearn.ensemble import RandomForestClassifier
4from sklearn.neural_network import MLPClassifier
5from sklearn.model_selection import GridSearchCV
6from sklearn.model_selection import train_test_split
7
8X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
9
10names = [
11         "Naive Bayes",
12         "Linear SVM",
13         "Logistic Regression",
14         "Random Forest",
15         "Multilayer Perceptron"
16        ]
17
18classifiers = [
19    MultinomialNB(),
20    LinearSVC(),
21    LogisticRegression(),
22    RandomForestClassifier(),
23    MLPClassifier()
24]
25
26parameters = [
27              {'vect__ngram_range': [(1, 1), (1, 2)],
28              'clf__alpha': (1e-2, 1e-3)},
29              {'vect__ngram_range': [(1, 1), (1, 2)],
30              'clf__C': (np.logspace(-5, 1, 5))},
31              {'vect__ngram_range': [(1, 1), (1, 2)],
32              'clf__C': (np.logspace(-5, 1, 5))},
33              {'vect__ngram_range': [(1, 1), (1, 2)],
34              'clf__max_depth': (1, 2)},
35              {'vect__ngram_range': [(1, 1), (1, 2)],
36              'clf__alpha': (1e-2, 1e-3)}
37             ]
38
39for name, classifier, params in zip(names, classifiers, parameters):
40    clf_pipe = Pipeline([
41        ('vect', TfidfVectorizer(stop_words='english')),
42        ('clf', classifier),
43    ])
44    gs_clf = GridSearchCV(clf_pipe, param_grid=params, n_jobs=-1)
45    clf = gs_clf.fit(X_train, y_train)
46    score = clf.score(X_test, y_test)
47    print("{} score: {}".format(name, score))
48
Sara
23 May 2020
1>>> from sklearn import svm, datasets
2>>> from sklearn.model_selection import GridSearchCV
3>>> iris = datasets.load_iris()
4>>> parameters = {'kernel':('linear', 'rbf'), 'C':[1, 10]}
5>>> svc = svm.SVC()
6>>> clf = GridSearchCV(svc, parameters)
7>>> clf.fit(iris.data, iris.target)
8GridSearchCV(estimator=SVC(),
9             param_grid={'C': [1, 10], 'kernel': ('linear', 'rbf')})
10>>> sorted(clf.cv_results_.keys())
11['mean_fit_time', 'mean_score_time', 'mean_test_score',...
12 'param_C', 'param_kernel', 'params',...
13 'rank_test_score', 'split0_test_score',...
14 'split2_test_score', ...
15 'std_fit_time', 'std_score_time', 'std_test_score']
queries leading to this page
what is gridsearchcvevaluation metric to be recall in grid search cv 23https 3a 2f 2fscikit learn org 2fstable 2fmodules 2fgenerated 2fsklearn model selection gridsearchcv html 23sklearn model selection gridsearchcvgridsearch scoringgrid search cv cv resultgridsearchcv mathgrid search cv rewieghersvm gridsearchcvgridsearchcv how does it workgrid search scoringsyntax for sgb parameters in grid search cvgridsearchcv iidgrid search cv meaninggridsearch multiple metric best estimatorscoring types in gridsearchcvupdate model with best parameters grid search scikitbest grid search to list out all grid search parametersverbose gridsearchsklearn gridgrid searchcvsklearn gridsearchcvgrid search for model selectiongridsearchcv scoringgridsearchcv estimatorgridsearchcv python sv 2cgridsearchcv api 7egridsearchcv params collectiongridsearchcv with multiple modelsgrid search gammagridsearchcv skleargridsearch importgridsearchcv sklearn examplewhat does gridsearchcv do 3fgridsearchcv njobsgridsearchcv variables gridsearchcv scoring for regressionget model parameters from gridsearchcvscikit learn grid search get gridgrid search scikitgridsearchcv best paramsgrid search cv scoringhow to defined model and pass to gridsearchaccelerat scikit gridsearchcvuse of gridsearchcvgridsearchcv get best modelgridsearchcv return train scorewhy use gridsearchcvgridsearchcv codegrid search resultsgrid search get scoreswhat is gridsearchcv gammagrid search cv examplehow to import gridsearchbest params for last test core gridsearchcvgridsearchcv puthongrid search adb in sklearnsvc grid searchimport grid search cvgridsearchcv objectsgridsearchcv regressionsklearn find best modelgridsearchcv outputhow to import gridsearchcvgrid cvgridsearchcv functionhow long does gridsearchcv takesklearn grid searchgrid search best scoregridsearchcv castgrid search sklearngridsearchcv pythonsvc gridsearchcvgrid search and gridsearchcvgridsearchcv algorithmgridsearchcv best modelto get top 3 grid search resultgridsearchcv helpsklearn gridsearchcv use bestparamsscikit grid searchtwo tier custom model gridsearch pythonhow to pass valeus of a numpy array to gridsearchcvgridsearch cv scikit learngridsearchcv sklarnwhat is gridsearchcv in sklearngridsearchcv lhow to use gridsearchcvgridsearchcv methodgridsearch 28 29get list of accuracy from the gridsearchcvgridsearchcv sklearngrid search get best modelto list out all gridsearch parametersgrid search cvname 27gridsearchcv 27 is not definedgrid search cv not showing all parametersgrid fit sklearntypes of grid search cvn jobs in gridsearchcvcv selection gridhow to perform grid cv in pythongridsearchcv iid 3dfalseimport gridsearchcv pythongrid search cv in pythonhow to specify cv in gridsearchcv svmhow to set the number of evals in gridsearchhow to specify cv in gridsearchcvgrid search cv verbosescikit learn gridsearchcvgridsearchcv examplegridsearchcv foldsgridsearchcv what it issklearn find best parametershyperparameter tuning grid searchscikit gridsearchcvsklearn gridsearchcv get best modelgrid search n jobs 3d 1grid search scikit learnhow work gridsearchcvn jobs gridsearchcvscikit gridsearchcv examplegridsearchcv function in pythonchange param gridsearch best estimatorgridsearchcv in pythonnameerror 3a name 27gridsearchcv 27 is not definedgridsearchcv score examplegridsearchcv seedusing gridsearchcvgridsearchcv documentationgridsearchcv sklearn steady scoregridsearchcv example pythonsklearn gridsearchcv score examplegridsearchcv svmsklearn model selection gridsearchcvgrid search best estimator from sklearn grid search import gridsearchcvsklearn grid serachcv results attribute train mean score of the gridsearchcvgrid search pythongridsearchcv cvpython gridsearchcvsklearn grid search cvgridsearchcv fit gridsearchcv n jobsgridsearchcv for model selectiongrid search best paramscheck grid search valuesfrom sklearn model selection import gridsearchcvuse gridsearch parametersgridsearchcv bestgridsearchcv 28 29gridsearchcv python sklearngrid search max itergrid search verboseget results of gridsearchcvgridsearchcv python scoringscikit learn grid searchnumbers of models fitted by gridsearchcvgridsearchcv extract optimal featureshow to find the number of fits in grid search cvgrid search cv sklearngrid search scoring optiongridsearchcv best parameterssklearn fit paramsgridsearchcvgridsearchcv params gridgreed search cvgrid seach cvsklearn metrics gridsearchcvsklearn gridsearchcv score methodgridsearchcv in machine learninggridsearchcv with castgridsearchcv grid scoresgridsearchcv cv meaninggridsearchcv workinggridsearchcv optimizergridsearchcv best params gridsearchcv error scoregridsearch rfehow to make gridsearchcvgridsearchcv cv 3dgrid search to use more than one algorithmimport gridseachcvgridsearchcv scoresklear gridsearchcvsklearn gridsearchcv fithow does gridsearchcv workgridsearch cv python librarygrid search for hyperparameter tuninghow to use grid search cvgridsearchcv 28 29gridsearchcv score functiongridsearchcv scorecv parameter in gridsearchcvgridsearchcv svcscikit learn gridsearchcvgridsearchcv verboserole of cv in gridsearch algorithmbest params for last test score gridsearchcvdifferent types of params that can be passed to gridsearchpredict gridsearchcvimport gridsearchcvgridsearchcv implementationgridsearchcv score examplescikit learn grid search printgridaccuracy gread search cvgridsearchcv params for every classifier gridsearchcv refitgrid search cv best estimator 27gridsearchcv 27 sklearn grid search with all parameterswhat is gridsearchcv used forpython grid search cvgridsearchcv multiple modelslogistic regression how to select iterations in grid search cvsklearn paramspredict on grid search cv pythongrid search fit 28 29gridsearchcv anncoerf arguments sklearnbest params grid searchgridsearch for final estimator sklearngridsearch 28 29 in pythongridsearchcv algortihm for grid search cvn jobs in grid searchgridsearchcv return oofprint gridsearchcv resultsexample of grid searchexample of gridsearchcvgidsearchcvgrid search parametersscoring gridsearchgridsearchcv 28gridsearchcv usageself made model gridsearch pythongrid search attributesgridsearchcv return dictionaryhow to get test predictions from gridsearchcvgridsearchcv with many estimatorgaussiannb gridsearchcvgridsearchcv scoresgridsearchcv attributesbest params gridsearchcvgridsearchcv skelarncv grid searchfonction gridsearchcvgrid search and cvgrid search best modelgrid searchcv predictionsgrid search cv fitgrid score skscitkit learn grid scoregridsearchcv parametersgrid searchgrid search cv jobsreal python gridsearchcvsvm python best estimator logistic regression grid search cv iteratiions gridsearchcvwhat does gridsearchcv dogridsearchcv