Pre*_*and 4 machine-learning python-3.x
我正在使用网格搜索以获得最佳拟合
k=['rbf', 'linear','poly','sigmoid']
c= [1,5,10,20,30,50,80,100]
g=[1e-7,1e-6,1e-5,1e-4,1e-2,0.0001]
param_grid=dict(kernel=k, C=c, gamma=g)
print (param_grid)
grid = GridSearchCV(SVC, param_grid,scoring='accuracy')
grid.fit(X_t_train, y_t_train)
print()
print("Grid scores on development set:")
print()
print (grid.grid_scores_)
print("Best parameters set found on development set:")
print()
print(grid.best_params_)
print("Grid best score:")
print()
print (grid.best_score_)
Run Code Online (Sandbox Code Playgroud)
我收到一个TypeError:get_params()缺少1个必需的位置参数:grid.fit()中的'self'
出现此错误是因为估计器必须使用对象而不是类进行初始化。您需要执行以下任一操作:
grid = GridSearchCV(SVC(), param_grid, scoring='accuracy')
Run Code Online (Sandbox Code Playgroud)
或类似这样的东西:
clf = SVC()
grid = GridSearchCV(clf, param_grid, scoring='accuracy')
Run Code Online (Sandbox Code Playgroud)