Python Forum
10fold cross-validation on time series
Thread Rating:
  • 2 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
10fold cross-validation on time series
#1
Hello python experts, 
I'm relatively new to python but have to solve a problem for a university project. I hope you guys can help me. 

My task is to do a 10fold cross-validation on a time series in which 90% should be training data and 10% should be for testing. In the end I should evaluate the testing set with the RMSE. Furhtermore, the data should not be shuffeld, as it is a time series. After doing some research I came up with this:

X = mergedf['AnzahlTweets']
y = mergedf['Kurs']

for train_index, test_index in tscv.split(X):
   print("TRAIN:", train_index, "TEST:", test_index)
   X_train, X_test = X[train_index], X[test_index]
   y_train, y_test = y[train_index], y[test_index]

linreg=LinearRegression()
linreg.fit(X_train,y_train)
y_pred=linreg.predict(X_test)
print('RMSE:',np.sqrt(metrics.mean_squared_error(y_test, y_pred)))
Now I got two questions: is this the right approach for my task and if so, why do I get this error 'ValueError: Input contains NaN, infinity or a value too large for dtype('float64').'? It seems like X_train, X_test, y_train, y_test just consists of 'NaN' although X and y have values.

I hope you can help me. Thanks in advance!
Reply


Messages In This Thread
10fold cross-validation on time series - by ulrich48155 - May-04-2017, 04:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Fit straight line to pandas time series data with semilog plot schniefen 2 1,560 Mar-10-2023, 01:08 PM
Last Post: jefsummers
  Plot time series data schniefen 3 1,356 Mar-04-2023, 04:22 PM
Last Post: noisefloor
  Help on Time Series problem Kishore_Bill 1 4,853 Feb-27-2020, 09:07 AM
Last Post: Kishore_Bill
  Rookie Stock Prediction Cross Validation using Graeber 3 2,911 Sep-17-2018, 10:40 PM
Last Post: Graeber
  Cross-validation: evaluating estimator performance Grin 1 2,663 Jun-29-2018, 05:15 AM
Last Post: scidam
  help with cross Item97 27 11,521 Nov-28-2017, 09:18 PM
Last Post: Item97
  Visualisation of gaps in time series data ulrich48155 11 19,431 Jul-04-2017, 11:47 PM
Last Post: zivoni

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020