text_html_output_1.png
from datetime import datetime, timedelta

from sklearn import preprocessing

from sklearn.ensemble import RandomForestRegressor

import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

df = pd.read_csv('../input/crypto-markets.csv', parse_dates=['date'], index_col='date')

btc = df[df['symbol'] == 'BTC']
btc.drop(['volume', 'symbol', 'name', 'ranknow', 'market'], axis=1, inplace=True)

btc.isnull().any()

btc.shape

sns.set()
sns.set_style('whitegrid')

from sklearn import preprocessing
btc.dropna(inplace=True)
X = btc.drop('Price_After_Month', axis=1)
X = preprocessing.scale(X)
y = btc['Price_After_Month']

from sklearn.ensemble import RandomForestRegressor
reg = RandomForestRegressor(n_estimators=200, random_state=101)
reg.fit(X_train, y_train)
accuracy = reg.score(X_test, y_test)
accuracy = accuracy * 100
accuracy = float('{0:.4f}'.format(accuracy))

preds = reg.predict(X_test)

X_30 = X[-30:]
forecast = reg.predict(X_30)

from datetime import datetime, timedelta
last_date = btc.iloc[-1].name
modified_date = last_date + timedelta(days=1)
date = pd.date_range(modified_date, periods=30, freq='D')
df1 = pd.DataFrame(forecast, columns=['Forecast'], index=date)
btc = btc.append(df1)

btc['close'].plot(figsize=(12, 6), label='Close')
btc['Forecast'].plot(label='forecast')
plt.legend()