ValueError:y中填充最少的类只有1个成员,这个成员太少了

时间:2017-02-25 18:09:39

标签: python scikit-learn sklearn-pandas

我收到错误:ValueError: The least populated class in y has only 1 member, which is too few. The minimum number of groups for any class cannot be less than 2.

X的形状是(138,4),y是(138,)。调用grid.fit(X,y)方法时会发生此错误。请帮我解决错误

xls_file = pd.read_excel('C:/Users/PC/Desktop/Book1.xls', sheetname='Sheet1', header=1)
# Create Variables. All the X and y values are picked from the excel files and converted to numpy arrays

wellno = xls_file.iloc[:, 0].values
T = xls_file.iloc[:, 1].values
Rs = xls_file.iloc[:, 6].values
API = xls_file.iloc[:, 2].values
gamma_g = xls_file.iloc[:, 3].values
Pb = xls_file.iloc[:, 4].values
Bo = xls_file.iloc[:, 5].values

y = Pb
X = np.c_[T, Rs, gamma_g, API]

X_2d = X[:, :2]
y_2d = y

C_range = np.logspace(-2, 10, 13)
gamma_range = np.logspace(-9, 3, 13)
param_grid = dict(gamma=gamma_range, C=C_range)
cv = StratifiedShuffleSplit(n_splits=5, test_size=0.2, random_state=42)
grid = GridSearchCV(SVC(), param_grid=param_grid, cv=cv)
grid.fit(X, y)

0 个答案:

没有答案