python - scikit-learn: cross_val_predict only works for partitions -
i struggling work out how implement timeseriessplit in sklearn.
the suggested answer @ link below yields same valueerror.
sklearn timeseriessplit cross_val_predict works partitions
here relevant bit code:
from sklearn.model_selection import cross_val_predict sklearn import svm features = df[df.columns[0:6]] target = df['target'] clf = svm.svc(random_state=0) pred = cross_val_predict(clf, features, target, cv=timeseriessplit(n_splits=5).split(features))
valueerror traceback (most recent call last) in () ----> 1 pred = cross_val_predict(clf, features, target, cv=timeseriessplit(n_splits=5).split(features))
/home/jedwards/anaconda3/envs/py36/lib/python3.6/site-packages/sklearn/model_selection/_validation.py in cross_val_predict(estimator, x, y, groups, cv, n_jobs, verbose, fit_params, pre_dispatch, method) 407 408 if not _check_is_permutation(test_indices, _num_samples(x)): --> 409 raise valueerror('cross_val_predict works partitions') 410 411 inv_test_indices = np.empty(len(test_indices), dtype=int)
valueerror: cross_val_predict works partitions
cross_val_predict cannot work timeseriessplit first partition of timeseriessplit never part of test dataset, meaning there no predictions made it.
e.g. when dataset [1, 2, 3, 4, 5]
- fold 1 - train: [1], test: [2]
- fold 2 - train: [1, 2], test: [3]
- fold 3 - train: [1, 2, 3], test: [4]
- fold 4 - train: [1, 2, 3, 4], test: [5]
in none of folds 1 in test set
if want have predictions on 2-5, can manually loop through splits generated cv , store predictions 2-5 yourself.
Comments
Post a Comment