Comments (8)
Could you please provide a minimal, self-complete example to reproduce this error?
from tscv.
sample X:
from sklearn.linear_model import SGDClassifier
import pandas as pd
from pandas import Timestamp
from tscv import GapWalkForward
from sklearn.model_selection import cross_val_predict
X = {'open': {Timestamp('1998-01-05 14:41:00'): 0.0,
Timestamp('1998-01-05 14:42:00'): 0.00160616768390609,
Timestamp('1998-01-05 14:43:00'): -0.0006418485237483784,
Timestamp('1998-01-05 14:44:00'): -0.00256657042027586,
Timestamp('1998-01-05 14:45:00'): -0.0025673940949936247,
Timestamp('1998-01-05 14:46:00'): -0.0009627727856226231,
Timestamp('1998-01-05 14:48:00'): -0.0009621552277100376,
Timestamp('1998-01-05 14:49:00'): 0.0,
Timestamp('1998-01-05 14:50:00'): 0.0022515278224508606,
Timestamp('1998-01-05 14:51:00'): 0.002574002574002643},
'high': {Timestamp('1998-01-05 14:41:00'): 0.0,
Timestamp('1998-01-05 14:42:00'): 0.00160616768390609,
Timestamp('1998-01-05 14:43:00'): 0.0,
Timestamp('1998-01-05 14:44:00'): -0.0028864656831302238,
Timestamp('1998-01-05 14:45:00'): -0.0025673940949936247,
Timestamp('1998-01-05 14:46:00'): -0.0012832852101379855,
Timestamp('1998-01-05 14:48:00'): -0.0009621552277100376,
Timestamp('1998-01-05 14:49:00'): -0.0009624639076034613,
Timestamp('1998-01-05 14:50:00'): 0.0022515278224508606,
Timestamp('1998-01-05 14:51:00'): 0.0038610038610038533},
'low': {Timestamp('1998-01-05 14:41:00'): 0.0,
Timestamp('1998-01-05 14:42:00'): 0.0012853470437017567,
Timestamp('1998-01-05 14:43:00'): -0.0009627727856226231,
Timestamp('1998-01-05 14:44:00'): -0.002887391722810384,
Timestamp('1998-01-05 14:45:00'): -0.0025673940949936247,
Timestamp('1998-01-05 14:46:00'): -0.0009627727856226231,
Timestamp('1998-01-05 14:48:00'): -0.0012836970474967568,
Timestamp('1998-01-05 14:49:00'): 0.00032123353678126243,
Timestamp('1998-01-05 14:50:00'): 0.002574002574002643,
Timestamp('1998-01-05 14:51:00'): 0.002574002574002643},
'close': {Timestamp('1998-01-05 14:41:00'): 0.0003209242618742447,
Timestamp('1998-01-05 14:42:00'): 0.0016066838046271403,
Timestamp('1998-01-05 14:43:00'): -0.0012832852101379855,
Timestamp('1998-01-05 14:44:00'): -0.003207184092366866,
Timestamp('1998-01-05 14:45:00'): -0.0025673940949936247,
Timestamp('1998-01-05 14:46:00'): -0.0012832852101379855,
Timestamp('1998-01-05 14:48:00'): -0.0016041065126723986,
Timestamp('1998-01-05 14:49:00'): 0.00032123353678126243,
Timestamp('1998-01-05 14:50:00'): 0.002574002574002643,
Timestamp('1998-01-05 14:51:00'): 0.0038610038610038533},
'volume': {Timestamp('1998-01-05 14:41:00'): -0.20512820512820518,
Timestamp('1998-01-05 14:42:00'): 9.0,
Timestamp('1998-01-05 14:43:00'): 28.0,
Timestamp('1998-01-05 14:44:00'): 1.0,
Timestamp('1998-01-05 14:45:00'): 7.225806451612904,
Timestamp('1998-01-05 14:46:00'): -0.967741935483871,
Timestamp('1998-01-05 14:48:00'): -0.7166666666666667,
Timestamp('1998-01-05 14:49:00'): -0.9885057471264368,
Timestamp('1998-01-05 14:50:00'): -0.7,
Timestamp('1998-01-05 14:51:00'): -0.7647058823529411}}
sample y:
y = {Timestamp('1998-01-05 14:41:00'): False,
Timestamp('1998-01-05 14:42:00'): False,
Timestamp('1998-01-05 14:43:00'): True,
Timestamp('1998-01-05 14:44:00'): True,
Timestamp('1998-01-05 14:45:00'): True,
Timestamp('1998-01-05 14:46:00'): True,
Timestamp('1998-01-05 14:48:00'): True,
Timestamp('1998-01-05 14:49:00'): True,
Timestamp('1998-01-05 14:50:00'): False,
Timestamp('1998-01-05 14:51:00'): True}
and then:
X = pd.DataFrame.from_dict(X)
y = pd.DataFrame.from_dict(y, orient='index').set_axis(['y'], axis=1)
cv = GapWalkForward(n_splits=3, gap_size=1, test_size=2)
predictions = cross_val_predict(estimator=SGDClassifier(), X=X,
y=y, cv=cv, n_jobs=6)
from tscv.
Where did you import SGDClassifier
?
from tscv.
Where did you import Timestamp
?
from tscv.
I changed code, it should work now.
from tscv.
My newly uploaded crosspredict
branch solves this issue. It enables the combination of GapWalkForward
and cross_val_predict
.
If you don't know how to install a package from a GitHub repo branch, you can download this file, put it in your package search path, and then try to do something similar to the following example.
Example:
from sklearn.model_selection import cross_val_predict
from split import GapWalkForward
class Foo:
def get_params(self, deep):
return dict()
def fit(self, X, y):
pass
def predict(self, X):
return [0 for _ in X]
cv = GapWalkForward(n_splits=3, gap_size=1, test_size=2)
cross_val_predict(estimator=Foo(), X=range(6), y=range(6), cv=cv)
Output:
array([0, 0, 0, 0, 0, 0])
from tscv.
I got the same error as before:
ValueError: cross_val_predict only works for partitions
I have to say I get the same error if I use cross_val_predict with sklearn TimeSeriesSplit. I would have to figure out how to implement cross validation predictions ith time series splits...
from tscv.
Superseded by #9
from tscv.
Related Issues (20)
- [Docs] Use this package for Nested Cross-Validation
- Intution on setting number of gaps HOT 1
- split.py depends on deprecated / newly private method `_safe_indexing` in scikit-learn 0.24.0 HOT 3
- Stratify? HOT 1
- Double count in `n_splits` in `GapLeavePOut` HOT 1
- Improve the user experience of `gap_train_test_split`
- Retrained version of GapWalkForward: GapRollForward HOT 1
- Continuous Integration
- Documentation
- Warning once is not enough HOT 1
- Documentation HOT 3
- GapWalkForward Issue with Scikit-learn 0.24.1 HOT 2
- Deprecation message for `GapWalkForward` HOT 1
- Publish on conda
- Implement Rep-Holdout HOT 11
- Error when Importing TSCV Gapwalkforward HOT 2
- Import error with latest sklearn version HOT 3
- Does this work with sklearn 1.2? HOT 4
- GapKFold CV not working with sklearn cross_val_predict HOT 1
- GapLeavePOut CV not working with sklearn cross_val_predict HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tscv.