0
$\begingroup$

I am on this lecture about non-iid data where we generated a timeseries data using the function below:

import numpy as np
import pandas as pd

def generate_random_stock_market(n_stock=3, seed=0):
    rng = np.random.RandomState(seed)

    date_range = pd.date_range(start="01/01/2010", end="31/12/2020")
    stocks = np.array([
        rng.randint(low=100, high=200) +
        np.cumsum(rng.normal(size=(len(date_range),)))
        for _ in range(n_stock)
    ]).T
    return pd.DataFrame(
        stocks,
        columns=[f"Stock {i+1}" for i in range(n_stock)],
        index=date_range,) 

I call the function and visualize:

stocks = generate_random_stock_market()
stocks.head()

import matplotlib.pyplot as plt
stocks.plot()
plt.ylabel("Stock value")
plt.legend(bbox_to_anchor=(1.05, 0.8), loc="upper left")
_ = plt.title("Stock values over time")

I am to build the model based on the 2nd and 3rd columns and use the 1st column for prediction. I convert the stock dataframe to matrix and vector as follows:

data = stocks.drop(columns='Stock 1')
datam = data.to_numpy()

target=stocks['Stock 1']

And finally, I create a model and use a ShuffleSplit cv to evaluate it:

from sklearn.ensemble import GradientBoostingRegressor
from sklearn.model_selection import ShuffleSplit, cross_val_score

model = GradientBoostingRegressor()
cv = ShuffleSplit(random_state=42)
score = cross_val_score(
           model, datam, target, cv=cv, n_jobs=-1, verbose=True)

print('Score is '
      f'{score.mean() :.3} +- {score.std() :.3}')

My final result is 'Score is 0.597 +- 0.0179' I would like to know if there is anything I can do to improve the performance of my model or if there was something wrong I did above. I would appreciate any kind of help. Thanks.

$\endgroup$

Your Answer

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

Browse other questions tagged or ask your own question.