0
$\begingroup$

I need help with below code:

dataset.tail(4)

                Date    Close
    1274    1/24/2019   4871.96
    1275    1/25/2019   4925.82
    1276    1/28/2019   4888.58
    1277    1/29/2019   4928.18

I want to split my dataset to training and test using:

training_data=dataset[dataset.Date<datetime(2018, 1, 1)]

But I get the following error:

TypeError                                 
Traceback (most recent call last)
<ipython-input-74-904bd8b45617> in <module>()
----> 1 training_data=dataset[dataset.Date<datetime(2018, 1, 1)]
      2 training_data.tail(4)

TypeError: 'module' object is not callable
$\endgroup$
1
$\begingroup$

Your code looks incomplete but you can definitely try the following to split your dataset-

X_train, X_test, y_train, y_test = train_test_split(dataset, 
                                                    y,
                                                    test_size=0.3, 
                                                    shuffle=False)

Note: y will be a series object for your dependent variable.

Because of this reason, using train_test_split with shuffle=True is not a good practice and should strictly be avoided.

Alternately, for time series you can use TimeSeriesSplit() and look for the implementation here.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you will check do you have an idea about sampling technique implementation by one step or n step prediction $\endgroup$ – Rawia Sammout Apr 12 '19 at 11:07
0
$\begingroup$

It appears that you're importing the datetime module, then using that to compare dates. The module itself cannot be applied, rather, you must access one of its functions such as:

training_data=dataset[dataset.Date<datetime.datetime(2018, 1, 1)]

An alternative would be:

training_data=dataset[pd.to_datetime('2018-01-01')]
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.