如何使用Python中的GridSearchCV修复错误?

时间:2019-06-05 14:20:25

标签: python

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from sklearn.model_selection import cross_val_score  
from sklearn.linear_model import SGDClassifier
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import train_test_split
from sklearn.model_selection import StratifiedShuffleSplit


x=[0.1,0.2,0.3,0.5,4,7,10,18,6,8]
y=[0,0,0,0,1,1,1,1,1,1]
train_date,test_date,train_y,test_y=train_test_split(          
x,y,test_size=0.2,random_state=0)

print(train_date)
classifier=SGDClassifier(random_state=0)
f=classifier.get_params().keys()
print(f)
parameters_grid={'loss':['hinge','log','squared_hige', 
'squared_loss'],'penalty':['l1','L2'],'n_iter':range(5, 10), 'alpha': 
np.linspace(0.0001,0.001, num=5)}
cv=StratifiedShuffleSplit(train_y,  n_iter=10, test_size=0.2, 
random_state=0)
grid_cv=GridSearchCV(classifier, parameters_grid, scoring='f1_micro', 
cv=cv)
grid_cv.fit(train_date,train_y)
a=grid_cv.grid_score_
print(a)

1)TypeError: init ()得到了意外的关键字参数'n_iter'     2)'列表'对象不能解释为整数

0 个答案:

没有答案