Python Forum
Removing data in a plot
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Removing data in a plot
#1
For a project I needed to calculate and display a 10fold cross-validation on a time-series. After plotting my results look like this:

http://imgur.com/a/15wbF

As you can see, both plots also contain the first fold, which I circled green. This fold is not noteworthy and I would like to remove it. Due to the fact, that I work with time series data my 10fold cross-validation has this structure:

Train 0 - Test 1
Train 1 - Test 2
Train 1,2 - Test 3
Train 1,2,3 - Tet 4
...
Train 1,2,3,4,5,6,7,8,9 - Test 10

My code looks like this:

tscv = TimeSeriesSplit(n_splits=10

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

X=X.values.reshape(-1,1)
y=y.values.reshape(-1,1)

# Cross-validation
linreg=LinearRegression()
rmse=[]
prediction=np.zeros(y.shape)
for train_index, test_index in tscv.split(X):
   X_train, X_test = X[train_index], X[test_index]
   y_train, y_test = y[train_index], y[test_index]
   linreg.fit(X_train,y_train)
   y_pred=linreg.predict(X_test)
   prediction[test_index]=y_pred
   rmse.append(np.sqrt(metrics.mean_squared_error(y_test, y_pred)))  
   print('RMSE: %.10f' % np.sqrt(metrics.mean_squared_error(y_test, y_pred)))

# Plotting
fig, axes = pl.subplots()
pl.plot(y,label='Actual')
pl.plot(prediction, color='red',label='Predicted',)
pl.ylabel('Price')
pl.xlabel('Fold')
pl.gca().xaxis.grid(True)
pl.setp(axes, xticks=[51,98,145,192,239,286,333,380,427,474,521], xticklabels=['          1','          2','          3', '          4','          5','          6','          7','          8','          9','          10'])
pl.legend()
pl.show()

prediction = prediction[:,0]
y = y[:,0]

m, b = np.polyfit(prediction, y, 1)

plrange=np.arange(0,0.000001,0.00000005)

pl.plot(prediction, y,'ro')
pl.plot(prediction, m*prediction + b)
pl.xlabel('Predicted')
pl.ylabel('Actual')
pl.xlim()
pl.gca().xaxis.grid(True)
pl.show()
Now my question: Is it possible to remove the first fold (Train 0 - Test 1) before plotting?

Thanks in advance!
Reply


Messages In This Thread
Removing data in a plot - by ulrich48155 - Jun-08-2017, 02:25 PM
RE: Removing data in a plot - by zivoni - Jun-08-2017, 09:11 PM
RE: Removing data in a plot - by ulrich48155 - Jun-10-2017, 07:38 PM
RE: Removing data in a plot - by zivoni - Jun-19-2017, 06:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Exclamation URGENT: How to plot data from text file. Trying to recreate plots from MATLAB JamieAl 4 3,472 Dec-03-2023, 06:56 AM
Last Post: Pedroski55
  Fit straight line to pandas time series data with semilog plot schniefen 2 1,500 Mar-10-2023, 01:08 PM
Last Post: jefsummers
  Plot time series data schniefen 3 1,268 Mar-04-2023, 04:22 PM
Last Post: noisefloor

Forum Jump:

User Panel Messages

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