{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.11","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":96164,"databundleVersionId":11418275,"sourceType":"competition"}],"dockerImageVersionId":31040,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-06-17T14:59:07.235045Z","iopub.execute_input":"2025-06-17T14:59:07.235743Z","iopub.status.idle":"2025-06-17T14:59:07.242285Z","shell.execute_reply.started":"2025-06-17T14:59:07.235710Z","shell.execute_reply":"2025-06-17T14:59:07.241395Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/drw-crypto-market-prediction/sample_submission.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T14:59:09.399745Z","iopub.execute_input":"2025-06-17T14:59:09.400541Z","iopub.status.idle":"2025-06-17T14:59:09.578478Z","shell.execute_reply.started":"2025-06-17T14:59:09.400514Z","shell.execute_reply":"2025-06-17T14:59:09.577575Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T14:59:11.105023Z","iopub.execute_input":"2025-06-17T14:59:11.105328Z","iopub.status.idle":"2025-06-17T14:59:11.116131Z","shell.execute_reply.started":"2025-06-17T14:59:11.105307Z","shell.execute_reply":"2025-06-17T14:59:11.115247Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df['label'] = df['prediction'].apply(lambda x:1 if x>0 else 0)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T14:59:13.819939Z","iopub.execute_input":"2025-06-17T14:59:13.820259Z","iopub.status.idle":"2025-06-17T14:59:14.053831Z","shell.execute_reply.started":"2025-06-17T14:59:13.820238Z","shell.execute_reply":"2025-06-17T14:59:14.052928Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T14:59:17.534554Z","iopub.execute_input":"2025-06-17T14:59:17.534863Z","iopub.status.idle":"2025-06-17T14:59:17.545108Z","shell.execute_reply.started":"2025-06-17T14:59:17.534843Z","shell.execute_reply":"2025-06-17T14:59:17.544106Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(df[['prediction', 'label']].describe())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T14:59:20.219742Z","iopub.execute_input":"2025-06-17T14:59:20.220107Z","iopub.status.idle":"2025-06-17T14:59:20.280518Z","shell.execute_reply.started":"2025-06-17T14:59:20.220084Z","shell.execute_reply":"2025-06-17T14:59:20.279314Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from scipy.stats import pearsonr\nimport matplotlib.pyplot as plt \nimport seaborn as sns","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:00:38.886974Z","iopub.execute_input":"2025-06-17T15:00:38.887307Z","iopub.status.idle":"2025-06-17T15:00:38.891793Z","shell.execute_reply.started":"2025-06-17T15:00:38.887285Z","shell.execute_reply":"2025-06-17T15:00:38.890643Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"corr,p_value = pearsonr(df['prediction'], df['label'])\nprint(f\"Pearson Correlation: {corr:.4f}\")\nprint(f\"P-value : {p_value:.4e}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:00:40.631837Z","iopub.execute_input":"2025-06-17T15:00:40.632166Z","iopub.status.idle":"2025-06-17T15:00:40.656293Z","shell.execute_reply.started":"2025-06-17T15:00:40.632146Z","shell.execute_reply":"2025-06-17T15:00:40.655348Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(10 , 6))\nsns.scatterplot(x='label', y='prediction', data=df, alpha=0.3)\nsns.regplot(x='label', y='prediction', data=df, scatter=False, color='red')\nplt.title(f'predictions vs labels (pearson r = {corr:.4f})')\nplt.xlabel('True Label')\nplt.ylabel('Prediction')\nplt.grid(True)\nplt.tight_layout()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:00:42.786569Z","iopub.execute_input":"2025-06-17T15:00:42.786879Z","iopub.status.idle":"2025-06-17T15:01:15.934205Z","shell.execute_reply.started":"2025-06-17T15:00:42.786859Z","shell.execute_reply":"2025-06-17T15:01:15.933013Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Feature Engineering","metadata":{}},{"cell_type":"code","source":"df['SMA_20'] = df['prediction'].rolling(window=20).mean()\ndf['SMA_50'] = df['prediction'].rolling(window=50).mean()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:02:05.691547Z","iopub.execute_input":"2025-06-17T15:02:05.691921Z","iopub.status.idle":"2025-06-17T15:02:05.732411Z","shell.execute_reply.started":"2025-06-17T15:02:05.691897Z","shell.execute_reply":"2025-06-17T15:02:05.731419Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:02:07.492211Z","iopub.execute_input":"2025-06-17T15:02:07.492568Z","iopub.status.idle":"2025-06-17T15:02:07.506295Z","shell.execute_reply.started":"2025-06-17T15:02:07.492545Z","shell.execute_reply":"2025-06-17T15:02:07.505396Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"delta = df['prediction'].diff()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:02:10.761807Z","iopub.execute_input":"2025-06-17T15:02:10.762094Z","iopub.status.idle":"2025-06-17T15:02:10.767486Z","shell.execute_reply.started":"2025-06-17T15:02:10.762075Z","shell.execute_reply":"2025-06-17T15:02:10.766268Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"delta","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:02:14.191869Z","iopub.execute_input":"2025-06-17T15:02:14.192220Z","iopub.status.idle":"2025-06-17T15:02:14.200636Z","shell.execute_reply.started":"2025-06-17T15:02:14.192197Z","shell.execute_reply":"2025-06-17T15:02:14.199439Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"gain = delta.where(delta > 0, 0)\nlose = delta.where(delta < 0, 0)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:02:16.931431Z","iopub.execute_input":"2025-06-17T15:02:16.931811Z","iopub.status.idle":"2025-06-17T15:02:16.949936Z","shell.execute_reply.started":"2025-06-17T15:02:16.931788Z","shell.execute_reply":"2025-06-17T15:02:16.948821Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"avg_gain = gain.rolling(window=14).mean()\navg_lose = lose.rolling(window=14).mean()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:02:19.096781Z","iopub.execute_input":"2025-06-17T15:02:19.097164Z","iopub.status.idle":"2025-06-17T15:02:19.139436Z","shell.execute_reply.started":"2025-06-17T15:02:19.097138Z","shell.execute_reply":"2025-06-17T15:02:19.138272Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"rs = avg_gain / avg_lose","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:02:20.981519Z","iopub.execute_input":"2025-06-17T15:02:20.982259Z","iopub.status.idle":"2025-06-17T15:02:20.987269Z","shell.execute_reply.started":"2025-06-17T15:02:20.982234Z","shell.execute_reply":"2025-06-17T15:02:20.986153Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"rs","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:02:22.351754Z","iopub.execute_input":"2025-06-17T15:02:22.352103Z","iopub.status.idle":"2025-06-17T15:02:22.361057Z","shell.execute_reply.started":"2025-06-17T15:02:22.352081Z","shell.execute_reply":"2025-06-17T15:02:22.359922Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:02:24.911603Z","iopub.execute_input":"2025-06-17T15:02:24.911962Z","iopub.status.idle":"2025-06-17T15:02:24.925421Z","shell.execute_reply.started":"2025-06-17T15:02:24.911939Z","shell.execute_reply":"2025-06-17T15:02:24.924307Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df['RSI'] = 100 - (100/(1+rs))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:02:28.196549Z","iopub.execute_input":"2025-06-17T15:02:28.196899Z","iopub.status.idle":"2025-06-17T15:02:28.205706Z","shell.execute_reply.started":"2025-06-17T15:02:28.196877Z","shell.execute_reply":"2025-06-17T15:02:28.204671Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:04:01.292148Z","iopub.execute_input":"2025-06-17T15:04:01.292530Z","iopub.status.idle":"2025-06-17T15:04:01.306478Z","shell.execute_reply.started":"2025-06-17T15:04:01.292505Z","shell.execute_reply":"2025-06-17T15:04:01.305438Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df['EMA_20'] = df['prediction'].ewm(span=20, adjust=False).mean()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:04:04.526664Z","iopub.execute_input":"2025-06-17T15:04:04.527681Z","iopub.status.idle":"2025-06-17T15:04:04.544625Z","shell.execute_reply.started":"2025-06-17T15:04:04.527652Z","shell.execute_reply":"2025-06-17T15:04:04.543751Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:04:05.846562Z","iopub.execute_input":"2025-06-17T15:04:05.847461Z","iopub.status.idle":"2025-06-17T15:04:05.860880Z","shell.execute_reply.started":"2025-06-17T15:04:05.847435Z","shell.execute_reply":"2025-06-17T15:04:05.859833Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"features = ['SMA_20', 'SMA_50', 'RSI', 'EMA_20']\nX = df[features].dropna()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:04:08.647101Z","iopub.execute_input":"2025-06-17T15:04:08.647462Z","iopub.status.idle":"2025-06-17T15:04:08.698119Z","shell.execute_reply.started":"2025-06-17T15:04:08.647438Z","shell.execute_reply":"2025-06-17T15:04:08.697282Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:04:11.651792Z","iopub.execute_input":"2025-06-17T15:04:11.652134Z","iopub.status.idle":"2025-06-17T15:04:11.665527Z","shell.execute_reply.started":"2025-06-17T15:04:11.652111Z","shell.execute_reply":"2025-06-17T15:04:11.664653Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y = df['prediction'].shift(-1).dropna()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:04:14.211439Z","iopub.execute_input":"2025-06-17T15:04:14.211756Z","iopub.status.idle":"2025-06-17T15:04:14.221741Z","shell.execute_reply.started":"2025-06-17T15:04:14.211735Z","shell.execute_reply":"2025-06-17T15:04:14.220868Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:04:16.151269Z","iopub.execute_input":"2025-06-17T15:04:16.151584Z","iopub.status.idle":"2025-06-17T15:04:16.158004Z","shell.execute_reply.started":"2025-06-17T15:04:16.151565Z","shell.execute_reply":"2025-06-17T15:04:16.157185Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X = X.iloc[:-1]\ny = y.iloc[:-1]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:04:18.516765Z","iopub.execute_input":"2025-06-17T15:04:18.517078Z","iopub.status.idle":"2025-06-17T15:04:18.521571Z","shell.execute_reply.started":"2025-06-17T15:04:18.517057Z","shell.execute_reply":"2025-06-17T15:04:18.520597Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:04:19.731454Z","iopub.execute_input":"2025-06-17T15:04:19.731814Z","iopub.status.idle":"2025-06-17T15:04:19.746845Z","shell.execute_reply.started":"2025-06-17T15:04:19.731790Z","shell.execute_reply":"2025-06-17T15:04:19.745838Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:04:22.616896Z","iopub.execute_input":"2025-06-17T15:04:22.617630Z","iopub.status.idle":"2025-06-17T15:04:22.625204Z","shell.execute_reply.started":"2025-06-17T15:04:22.617600Z","shell.execute_reply":"2025-06-17T15:04:22.624238Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:04:25.311258Z","iopub.execute_input":"2025-06-17T15:04:25.312166Z","iopub.status.idle":"2025-06-17T15:04:25.315994Z","shell.execute_reply.started":"2025-06-17T15:04:25.312141Z","shell.execute_reply":"2025-06-17T15:04:25.314867Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(X.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:04:26.576240Z","iopub.execute_input":"2025-06-17T15:04:26.576578Z","iopub.status.idle":"2025-06-17T15:04:26.581413Z","shell.execute_reply.started":"2025-06-17T15:04:26.576556Z","shell.execute_reply":"2025-06-17T15:04:26.580313Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(y.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:04:28.526177Z","iopub.execute_input":"2025-06-17T15:04:28.526499Z","iopub.status.idle":"2025-06-17T15:04:28.531281Z","shell.execute_reply.started":"2025-06-17T15:04:28.526479Z","shell.execute_reply":"2025-06-17T15:04:28.530252Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"min_len = min(len(X), len(y))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:04:30.581497Z","iopub.execute_input":"2025-06-17T15:04:30.581863Z","iopub.status.idle":"2025-06-17T15:04:30.586527Z","shell.execute_reply.started":"2025-06-17T15:04:30.581839Z","shell.execute_reply":"2025-06-17T15:04:30.585373Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"min_len","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:04:32.281626Z","iopub.execute_input":"2025-06-17T15:04:32.281974Z","iopub.status.idle":"2025-06-17T15:04:32.287795Z","shell.execute_reply.started":"2025-06-17T15:04:32.281952Z","shell.execute_reply":"2025-06-17T15:04:32.286808Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X = X.iloc[:min_len].reset_index(drop=True)\ny = y.iloc[:min_len].reset_index(drop=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:04:37.321446Z","iopub.execute_input":"2025-06-17T15:04:37.322133Z","iopub.status.idle":"2025-06-17T15:04:37.348957Z","shell.execute_reply.started":"2025-06-17T15:04:37.322108Z","shell.execute_reply":"2025-06-17T15:04:37.348116Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train , X_test, y_train, y_test = train_test_split(X,y, test_size=0.2, random_state=42)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:04:40.151417Z","iopub.execute_input":"2025-06-17T15:04:40.151741Z","iopub.status.idle":"2025-06-17T15:04:40.196260Z","shell.execute_reply.started":"2025-06-17T15:04:40.151720Z","shell.execute_reply":"2025-06-17T15:04:40.195328Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Model Selection and Training ","metadata":{}},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestRegressor\nmodel = RandomForestRegressor(n_estimators=100, random_state=42)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:04:42.616571Z","iopub.execute_input":"2025-06-17T15:04:42.617459Z","iopub.status.idle":"2025-06-17T15:04:42.621320Z","shell.execute_reply.started":"2025-06-17T15:04:42.617436Z","shell.execute_reply":"2025-06-17T15:04:42.620417Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.fit(X_train, y_train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:04:43.816361Z","iopub.execute_input":"2025-06-17T15:04:43.816675Z","iopub.status.idle":"2025-06-17T15:12:00.130200Z","shell.execute_reply.started":"2025-06-17T15:04:43.816654Z","shell.execute_reply":"2025-06-17T15:12:00.129383Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Model Evaluation and Optimization","metadata":{}},{"cell_type":"code","source":"from sklearn.metrics import mean_squared_error","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:13:50.381592Z","iopub.execute_input":"2025-06-17T15:13:50.381978Z","iopub.status.idle":"2025-06-17T15:13:50.386582Z","shell.execute_reply.started":"2025-06-17T15:13:50.381953Z","shell.execute_reply":"2025-06-17T15:13:50.385404Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_pred = model.predict(X_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:13:52.001308Z","iopub.execute_input":"2025-06-17T15:13:52.002433Z","iopub.status.idle":"2025-06-17T15:14:00.581197Z","shell.execute_reply.started":"2025-06-17T15:13:52.002402Z","shell.execute_reply":"2025-06-17T15:14:00.580233Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"mae = mean_squared_error(y_test, y_pred)\nrsme = np.sqrt(mean_squared_error(y_test, y_pred))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:14:02.046756Z","iopub.execute_input":"2025-06-17T15:14:02.047427Z","iopub.status.idle":"2025-06-17T15:14:02.054537Z","shell.execute_reply.started":"2025-06-17T15:14:02.047399Z","shell.execute_reply":"2025-06-17T15:14:02.053574Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(f'MAE: {mae}')\nprint(f'RSME: {rsme}')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:14:03.976557Z","iopub.execute_input":"2025-06-17T15:14:03.976862Z","iopub.status.idle":"2025-06-17T15:14:03.981742Z","shell.execute_reply.started":"2025-06-17T15:14:03.976842Z","shell.execute_reply":"2025-06-17T15:14:03.980682Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df['Predicted_RandomForestRegressor']= model.predict(df[features].fillna(0))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:31:57.437850Z","iopub.execute_input":"2025-06-17T15:31:57.438890Z","iopub.status.idle":"2025-06-17T15:32:39.226942Z","shell.execute_reply.started":"2025-06-17T15:31:57.438860Z","shell.execute_reply":"2025-06-17T15:32:39.226049Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:32:39.234775Z","iopub.execute_input":"2025-06-17T15:32:39.235056Z","iopub.status.idle":"2025-06-17T15:32:39.249217Z","shell.execute_reply.started":"2025-06-17T15:32:39.235036Z","shell.execute_reply":"2025-06-17T15:32:39.248392Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import seaborn as sns \nimport matplotlib.pyplot as plt ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:40:22.922926Z","iopub.execute_input":"2025-06-17T15:40:22.923229Z","iopub.status.idle":"2025-06-17T15:40:22.927166Z","shell.execute_reply.started":"2025-06-17T15:40:22.923207Z","shell.execute_reply":"2025-06-17T15:40:22.926307Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sns.histplot(df['prediction'], bins=100)\nplt.title('Predictions Distribution')\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:40:24.988276Z","iopub.execute_input":"2025-06-17T15:40:24.988622Z","iopub.status.idle":"2025-06-17T15:40:25.863061Z","shell.execute_reply.started":"2025-06-17T15:40:24.988601Z","shell.execute_reply":"2025-06-17T15:40:25.862031Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y = df['prediction'].shift(-1).dropna()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:40:28.258377Z","iopub.execute_input":"2025-06-17T15:40:28.259113Z","iopub.status.idle":"2025-06-17T15:40:28.270420Z","shell.execute_reply.started":"2025-06-17T15:40:28.259084Z","shell.execute_reply":"2025-06-17T15:40:28.269559Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:40:29.383377Z","iopub.execute_input":"2025-06-17T15:40:29.384068Z","iopub.status.idle":"2025-06-17T15:40:29.390994Z","shell.execute_reply.started":"2025-06-17T15:40:29.384041Z","shell.execute_reply":"2025-06-17T15:40:29.390260Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(10, 6))\nsns.scatterplot(x='prediction', y='Predicted_RandomForestRegressor', data=df, alpha=0.4)\nplt.title('Actual Predictions vs RandomForestRegressor')\nplt.xlabel('Raw Prediction')\nplt.ylabel('Raw RandomForestRegressor')\nplt.axhline(0 , color='red', linestyle='--')\nplt.axvline(0 , color='Blue', linestyle='--')\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:40:31.663367Z","iopub.execute_input":"2025-06-17T15:40:31.663715Z","iopub.status.idle":"2025-06-17T15:40:33.172833Z","shell.execute_reply.started":"2025-06-17T15:40:31.663692Z","shell.execute_reply":"2025-06-17T15:40:33.171478Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(10, 6))\nsns.heatmap(df.corr(numeric_only=True), annot=True, fmt='.2f', cmap='coolwarm')\nplt.title('Correlations Matrix')\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:40:37.132973Z","iopub.execute_input":"2025-06-17T15:40:37.133268Z","iopub.status.idle":"2025-06-17T15:40:37.624746Z","shell.execute_reply.started":"2025-06-17T15:40:37.133246Z","shell.execute_reply":"2025-06-17T15:40:37.623542Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(14, 6))\ndf['prediction'].plot(label='Prediction', alpha=0.7)\ndf['SMA_20'].plot(label='SMA 20')\ndf['SMA_50'].plot(label='SMA 50')\ndf['EMA_20'].plot(label='EWA_20')\nplt.legend()\nplt.title('Predictions VS SMA/EMA')\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:40:40.498326Z","iopub.execute_input":"2025-06-17T15:40:40.498718Z","iopub.status.idle":"2025-06-17T15:40:50.277386Z","shell.execute_reply.started":"2025-06-17T15:40:40.498694Z","shell.execute_reply":"2025-06-17T15:40:50.276479Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df['Target_class'] = (df['prediction']>0).astype(int)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:40:56.857871Z","iopub.execute_input":"2025-06-17T15:40:56.858178Z","iopub.status.idle":"2025-06-17T15:40:56.865889Z","shell.execute_reply.started":"2025-06-17T15:40:56.858156Z","shell.execute_reply":"2025-06-17T15:40:56.864853Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:40:57.773016Z","iopub.execute_input":"2025-06-17T15:40:57.773304Z","iopub.status.idle":"2025-06-17T15:40:57.788518Z","shell.execute_reply.started":"2025-06-17T15:40:57.773284Z","shell.execute_reply":"2025-06-17T15:40:57.787555Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df['residual'] = df['prediction'] - df['Predicted_RandomForestRegressor']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:41:01.083179Z","iopub.execute_input":"2025-06-17T15:41:01.083967Z","iopub.status.idle":"2025-06-17T15:41:01.091211Z","shell.execute_reply.started":"2025-06-17T15:41:01.083940Z","shell.execute_reply":"2025-06-17T15:41:01.090412Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:41:02.628088Z","iopub.execute_input":"2025-06-17T15:41:02.628434Z","iopub.status.idle":"2025-06-17T15:41:02.644085Z","shell.execute_reply.started":"2025-06-17T15:41:02.628412Z","shell.execute_reply":"2025-06-17T15:41:02.643110Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(10, 5))\nsns.histplot(df['residual'], bins=100, kde=True)\nplt.title('Prediction Error (Residual) Distribution')\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:41:05.413190Z","iopub.execute_input":"2025-06-17T15:41:05.413514Z","iopub.status.idle":"2025-06-17T15:41:08.241790Z","shell.execute_reply.started":"2025-06-17T15:41:05.413494Z","shell.execute_reply":"2025-06-17T15:41:08.240687Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sample = df.iloc[-500:]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:41:11.163367Z","iopub.execute_input":"2025-06-17T15:41:11.163662Z","iopub.status.idle":"2025-06-17T15:41:11.168203Z","shell.execute_reply.started":"2025-06-17T15:41:11.163641Z","shell.execute_reply":"2025-06-17T15:41:11.167317Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sample","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:41:12.448237Z","iopub.execute_input":"2025-06-17T15:41:12.449090Z","iopub.status.idle":"2025-06-17T15:41:12.462345Z","shell.execute_reply.started":"2025-06-17T15:41:12.449061Z","shell.execute_reply":"2025-06-17T15:41:12.461398Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.figure(figsize=(14, 6))\nplt.plot(sample['prediction'], label='Actual Prediction')\nplt.plot(sample['Predicted_RandomForestRegressor'], label='RandomForest')\nplt.title('Actual predictions vs Predicted (last Observation)')\nplt.legend()\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-17T15:41:14.253048Z","iopub.execute_input":"2025-06-17T15:41:14.253536Z","iopub.status.idle":"2025-06-17T15:41:14.514597Z","shell.execute_reply.started":"2025-06-17T15:41:14.253511Z","shell.execute_reply":"2025-06-17T15:41:14.513722Z"}},"outputs":[],"execution_count":null}]}