Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

scikit learn - ValueError: Supported target types are: ('binary', 'multiclass'). Got 'continuous' instead. python

I run the following code:

seed = 7
np.random.seed(seed)

kfold = StratifiedKFold(n_splits=5, shuffle=True, random_state=seed)
for train, test in kfold.split(X, Y):
    model = Sequential()
    model.add(Dense(64, input_dim=12, activation='relu'))
    model.add(Dense(1))
    model.compile(optimizer='rmsprop', loss='mse', metrics=['mae'])
    model.fit(X[train], Y[train], epochs=10, verbose=1)

And got the following error:

ValueError Traceback (most recent call last) in () 6 lst_accu_stratified = [] 7 ----> 8 for train_index, test_index in skf.split(X, Y): 9 x_train_fold, x_test_fold = X_scaled[train_index], X_scaled[test_index] 10 y_train_fold, y_test_fold = Y[train_index], Y[test_index]

3 frames /usr/local/lib/python3.6/dist-packages/sklearn/model_selection/_split.py in _make_test_folds(self, X, y) 644 raise ValueError( 645 'Supported target types are: {}. Got {!r} instead.'.format( --> 646 allowed_target_types, type_of_target_y)) 647 648 y = column_or_1d(y)

ValueError: Supported target types are: ('binary', 'multiclass'). Got 'continuous' instead.

It doesn't make sense for this model not accepting continuous data. What's wrong?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...