Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

grid search cv

# Import necessary modules
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import GridSearchCV

# Setup the hyperparameter grid
c_space = np.logspace(-5, 8, 15)
param_grid = {'C': c_space}

# Instantiate a logistic regression classifier: logreg
logreg = LogisticRegression()

# Instantiate the GridSearchCV object: logreg_cv
logreg_cv = GridSearchCV(logreg, param_grid, cv=5)

# Fit it to the data
logreg_cv.fit(X, y)

# Print the tuned parameter and score
print("Tuned Logistic Regression Parameters: {}".format(logreg_cv.best_params_))
print("Best score is {}".format(logreg_cv.best_score_))
Comment

gridsearch cv

>>> from sklearn import svm, datasets
>>> from sklearn.model_selection import GridSearchCV
>>> iris = datasets.load_iris()
>>> parameters = {'kernel':('linear', 'rbf'), 'C':[1, 10]}
>>> svc = svm.SVC()
>>> clf = GridSearchCV(svc, parameters)
>>> clf.fit(iris.data, iris.target)
GridSearchCV(estimator=SVC(),
             param_grid={'C': [1, 10], 'kernel': ('linear', 'rbf')})
>>> sorted(clf.cv_results_.keys())
['mean_fit_time', 'mean_score_time', 'mean_test_score',...
 'param_C', 'param_kernel', 'params',...
 'rank_test_score', 'split0_test_score',...
 'split2_test_score', ...
 'std_fit_time', 'std_score_time', 'std_test_score']
Comment

PREVIOUS NEXT
Code Example
Python :: spyder - comment banch of codee 
Python :: how to take input complex number in python 
Python :: pandas dataframe read string as date 
Python :: python function to scale selected features in a dataframe pandas 
Python :: how to import file from another directory in python 
Python :: neuronal network exemple python 
Python :: how to add two numbers in python 
Python :: sqlite query in python 
Python :: get ContentType with django get_model 
Python :: python pyqt5 sleep 
Python :: csv module remove header title python 
Python :: list python virtual environments 
Python :: timestamp to date time till milliseconds python 
Python :: spacy config 
Python :: how to append a number to a list in python 
Python :: read files and write into another files python 
Python :: python notebook breakpoints 
Python :: palindrome string python 
Python :: delete an element by value from a list if it made of white spaces python 
Python :: np random seed 
Python :: string remove everything after character python 
Python :: kafka get last offset of topic python 
Python :: python nested list comprehension 
Python :: the following packages have unmet dependencies python3-tornado 
Python :: how to get images on flask page 
Python :: execute linux command in python 
Python :: dataframe to dictionary 
Python :: how to make a stopwatch in python 
Python :: how to check libraries in python 
Python :: how to sort a list of dictionary by value in descending order? 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =