<jupyter_start><jupyter_text>**Importing the Libraries**<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestRegressor
from sklearn import metrics<jupyter_output><empty_output><jupyter_text>**Data Collection and Processing**<jupyter_code># loading the csv data to a Pandas DataFrame
df=pd.read_csv("/content/gld_price_data.csv")
# print first 5 rows in the dataframe
df.head()
# print last 5 rows of the dataframe
df.tail()
# number of rows and columns
df.shape
# getting some basic informations about the data
df.info()
# checking the number of missing values
df.isnull().sum()
# getting the statistical measures of the data
df.describe()<jupyter_output><empty_output><jupyter_text>**Correlation:**1.  Positive Correlation2.  Negative Correlation<jupyter_code>correlation = df.corr()
# constructing a heatmap to understand the correlatiom
plt.figure(figsize = (8,8))
sns.heatmap(correlation, cbar=True, square=True, fmt='.1f',annot=True, annot_kws={'size':8}, cmap='Blues')
# correlation values of GLD
print(correlation['GLD'])
# checking the distribution of the GLD Price
sns.distplot(df['GLD'],color='green')<jupyter_output>/usr/local/lib/python3.7/dist-packages/seaborn/distributions.py:2619: FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms).
  warnings.warn(msg, FutureWarning)<jupyter_text>**Splitting the Features and Target**<jupyter_code>X = df.drop(['Date','GLD'],axis=1)
Y = df['GLD']
print(X)
print(Y)<jupyter_output>0        84.860001
1        85.570000
2        85.129997
3        84.769997
4        86.779999
           ...    
2285    124.589996
2286    124.330002
2287    125.180000
2288    124.489998
2289    122.543800
Name: GLD, Length: 2290, dtype: float64<jupyter_text>**Splitting into Training data and Test Data**<jupyter_code>X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size = 0.2, random_state=2)<jupyter_output><empty_output><jupyter_text>**Model Training: Random Forest Regressor**<jupyter_code>regressor = RandomForestRegressor(n_estimators=100)
# training the model
regressor.fit(X_train,Y_train)<jupyter_output><empty_output><jupyter_text>**Model Evaluation**<jupyter_code># prediction on Test Data
test_data_prediction = regressor.predict(X_test)
print(test_data_prediction)
# R squared error
error_score = metrics.r2_score(Y_test, test_data_prediction)
print("R squared error : ", error_score)<jupyter_output>R squared error :  0.9898948306035942<jupyter_text>**Compare the Actual Values and Predicted Values in a Plot**<jupyter_code>Y_test = list(Y_test)
plt.plot(Y_test, color='blue', label = 'Actual Value')
plt.plot(test_data_prediction, color='green', label='Predicted Value')
plt.title('Actual Price vs Predicted Price')
plt.xlabel('Number of values')
plt.ylabel('GLD Price')
plt.legend()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11150159744408945, 'fraction_numerical': 0.04952076677316294, 'mean_word_length': 6.384433962264151, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '416875', 'license': 'Apache-2.0', 'n_tokens_mistral': 1184, 'n_tokens_neox': 1059, 'n_words': 266, 'path': 'Gold_Price_.ipynb', 'repo_name': 'codebytekeys/Gold-Price-Prediction', 'size': '3130'}