Giter Club home page Giter Club logo

Comments (8)

WenjieZ avatar WenjieZ commented on July 23, 2024

Could you please provide a minimal, self-complete example to reproduce this error?

from tscv.

MislavSag avatar MislavSag commented on July 23, 2024

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.

WenjieZ avatar WenjieZ commented on July 23, 2024

Where did you import SGDClassifier?

from tscv.

WenjieZ avatar WenjieZ commented on July 23, 2024

Where did you import Timestamp?

from tscv.

MislavSag avatar MislavSag commented on July 23, 2024

I changed code, it should work now.

from tscv.

WenjieZ avatar WenjieZ commented on July 23, 2024

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.

MislavSag avatar MislavSag commented on July 23, 2024

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.

WenjieZ avatar WenjieZ commented on July 23, 2024

Superseded by #9

from tscv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.