Project 1
Preprocessing data:
The stock market data is taken and the values at the start and close of the working hours are considered and the data are preprocessed to get a valid model for predicting the outcomes.
# importing libraries
import pandas as pd
import numpy as np
# reading the data
df = pd.read_csv('NSE-TATAGLOBAL11.csv')
# looking at the first five rows of the data
print(df.head())
print('\n Shape of the data:')
print(df.shape)
# setting the index as date
df['Date'] = pd.to_datetime(df.Date,format='%Y-%m-%d')
df.index = df['Date']
#creating dataframe with date and the target variable
data = df.sort_index(ascending=True, axis=0)
new_data = pd.DataFrame(index=range(0,len(df)),columns=['Date', 'Close'])
for i in range(0,len(data)):
new_data['Date'][i] = data['Date'][i]
new_data['Close'][i] = data['Close'][i]
# NOTE: While splitting the data into train and validation set, we cannot use random splitting since that will destroy the time component. So here we have set the last year’s data into validation and the 4 years’ data before that into train set.
# splitting into train and validation
train = new_data[:987]
valid = new_data[987:]
# shapes of training set
print('\n Shape of training set:')
print(train.shape)
# shapes of validation set
print('\n Shape of validation set:')
print(valid.shape)
# In the next step, we will create predictions for the validation set and check the RMSE using the actual values.
# making predictions
preds = []
for i in range(0,valid.shape[0]):
a = train['Close'][len(train)-248+i:].sum() + sum(preds)
b = a/248
preds.append(b)
# checking the results (RMSE value)
rms=np.sqrt(np.mean(np.power((np.array(valid['Close'])-preds),2)))
print('\n RMSE value on validation set:')
print(rms)
The above code is used to get value of the dataset and then preprocess it.First the missing values in the dataset are rectified using the mean of the column and the date format is checked and the data aare arranged with respect to the date and train and test data are split and the shape of it are displayed.

The haed of the dataset is displayed in the console.The set has no missing values and the rmse value is shown.The shape of test and train data are displyed.