Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

voting classifier grid search

from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC
from sklearn.ensemble import VotingClassifier
from sklearn.model_selection import GridSearchCV

X = np.array([[-1.0, -1.0], [-1.2, -1.4], [-3.4, -2.2], [1.1, 1.2],[-1.0, -1.0], [-1.2, -1.4], [-3.4, -2.2], [1.1, 1.2]])
y = np.array([1, 1, 2, 2,1, 1, 2, 2])

eclf = VotingClassifier(estimators=[ 
    ('svm', SVC(probability=True)),
    ('lr', LogisticRegression()),
    ], voting='soft')

#Use the key for the classifier followed by __ and the attribute
params = {'lr__C': [1.0, 100.0],
      'svm__C': [2,3,4],}

grid = GridSearchCV(estimator=eclf, param_grid=params, cv=2)

grid.fit(X,y)

print (grid.best_params_)
#{'lr__C': 1.0, 'svm__C': 2}
Comment

PREVIOUS NEXT
Code Example
Python :: torch split classes stratified 
Python :: python selenium firefox handle ssl bypass 
Python :: why mentioning user agent in request library 
Python :: sqlite to python list 
Python :: strategy forex with python 
Python :: how to convert csv columns to text python 
Python :: pandan jaya lrt 
Python :: is python not a real programing laguage because lines dont end in ; 
Python :: dataframeclient influxdb example 
Python :: removing an item from a list and adding it to another list python 
Python :: pymol load coords 
Python :: pandas dataframe not able to change values 
Python :: right click vs left click pygame 
Python :: max value from multiple columns pandas 
Python :: py random sample 
Python :: flask make_response render_template 
Python :: django models filter(x in list) 
Python :: kivy file chooser path selector 
Python :: copy bdc to feature class arcpy 
Python :: InvalidArgumentError: logits and labels must be broadcastable: logits_size=[16,3] labels_size=[16,2] [[node categorical_smooth_loss/softmax_cross_entropy_with_logits 
Python :: Connection to Python debugger failed: Interrupted function call: accept failed 
Python :: svm classification involving pipelines 
Python :: decorrelation of data using PCA 
Python :: function transformer and feature union 
Python :: how to install python on linux chromebook 
Python :: for con condicion 
Python :: ERROR: Target path exists but is not a directory, will not continue. 
Python :: How to draw a Ninja Design using python turtle 
Python :: 5.2.5: Counting 10 to 100 by ... 
Python :: how many python programmers in the world 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =