3
$\begingroup$

What I am trying to achieve.

I want to forecast Natural Gas prices under the column "NG Open" based on other parameters in the data set below for all Contract Months ,which is scraped from a public website. I have copied only few rows as sample as total rows are 100 that are scraped.I am using XG Boosting algorithm .I am using KFold Validation to be on safe side instead of train_test_split

 Contracts     NG Open  NGHigh  NGLow   NGLast    NGVolumes   

  2018-12-01    3.907   4.384   3.907   4.272       0 
  2019-01-01    3.917   4.408   3.917   4.291       264295  
  2019-02-01    3.800   4.267   3.785   4.148       155303          
  2019-03-01    3.515   4.007   3.496   3.865       51299       
  2019-04-01    2.735   2.829   2.704   2.793       73226           
  2019-05-01    2.632   2.691   2.602   2.667       54540       
  2019-06-01    2.638   2.719   2.634   2.692       34269

Code

 from matplotlib import pyplot
 import numpy as np
 import pandas as pd
 from sklearn.ensemble import GradientBoostingRegressor 
 from sklearn.model_selection import KFold
 from sklearn.model_selection import cross_val_score
 from sklearn.metrics import mean_squared_error

 dataset = pd.read_excel("C:\Futures\Futures.xls")
 dataset['CO Last'] = dataset['CO Last'].str.rstrip('s')
 dataset['Contracts'] = dataset['Contracts'].str.rstrip('(E)')
 dataset['Contracts'] = pd.to_datetime(dataset['Contracts'])
 dataset  = dataset.set_index('Contracts')


 X = dataset[['NG High', 'NG Low', 'NG Last', 'NG Volumes']]
 y = dataset['NG Open']



 gbrt=GradientBoostingRegressor() 
 kfold = KFold(n_splits=10, random_state=7, shuffle = True)
 results = cross_val_score(gbrt, X, y, cv=kfold)
 print("Accuracy: %.2f%% (%.2f%%)" % (results.mean()*100, results.std()*100))


gbrt.fit(X_train, y_train)
y_pred = gbrt.predict(X_test)



lin_mse = mean_squared_error(y_pred, y_test)
lin_rmse = np.sqrt(lin_mse)
print('Liner Regression RMSE: %.4f' % lin_rmse)

Performance on model.

Accuracy: 99.04% (1.06%) Liner Regression RMSE: 0.0482

Now that the model is showing an accuracy of 99% how can I generate the predicted "NG Open" prices collated to contract months for all the rows and new set of data based on other columns?

I assume its is y_newdata = gbrt.predict(X1?) X1 being a new table?

$\endgroup$

closed as off-topic by Sycorax, kjetil b halvorsen, Peter Flom Nov 19 '18 at 11:27

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – Sycorax, kjetil b halvorsen, Peter Flom
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ Are you asking how to call gbrt.predict on all of your data or something else? $\endgroup$ – Sycorax Nov 19 '18 at 4:02
  • $\begingroup$ Yes. I want to predict all the values based on contra t months as index. $\endgroup$ – Siddharth Kulkarni Nov 19 '18 at 9:24
  • $\begingroup$ Can someone reopen the question? I just looking for pointers with respect to last code. $\endgroup$ – Siddharth Kulkarni Nov 19 '18 at 12:44