You are on page 1of 7
414924, 1:23 PM Bitcoin Price Prediction - Colaboratory import nusay a8 np import pandas as pd import matplotlib.pyplot as plt From datetine import datetine fro keras.nodels import Sequential from keras. layers import Dense, LSTM, Dropout, GRU ros keras.layers import * From sklearn.preprocessing import MinMaxScaler from sklearn.netrics import mean_squared error, ean_absolute_error from sklearn.nodel_selection import train_test_split From keras.callbacks import farlyStopping From keras.optinizers inport Adam, SGD AF = pd.read_csv(*/content/8TC-USD.csv" ) AF = df. sort_values(“Date').reset_index(drop=True) af. head() pate open High Low Close Adj Close vo 0 ‘172015 320434998 320.434998 914,002091 314.240093 914.248093 80 1 11172018 430.721008 436.248002 427.515015 434.334015 434.934015 3627 2 1W1R017 —969.658020 1002.080017958.698075 998.925012 998925012 14777 3 wiz018 14142.200200 14112.200200 13184,700200 19687.200200 12667,200200 1029120 411172019 3748.713379_3850.913818 3707.231201 _3843.520020 3843520020 432420 Next steps: Generate code with d¢ | € View recommended plots af. shape (2123, 7) Select the column ‘Close" for daily price af[ close") 4F{ "Close" J astype( float) ple. Figure(Figsiz« 28,7)) plt.plot(4f[ Date" J.values, df{ Close" ].values, label = ‘Bitcoin Stock Price’, color = ‘red") plt.xticks(np.arange(see,d¢.shape(@],22@)) plt.xlabel(‘Date') plt.ylabel( ‘Close ($)") plt.legend() plt.show() Intps:icolab research google. cordrve/gONuTZDhThishmemgMUSVBGWo8U3JIEMh=en#scrolT raxglnfogkSSpriniMode=true wr 414924, 1:23 PMA Bicoin Price Prediction - Colaboratory —_ ¥ Data Preprocessing hnun_shape = 2008 train = df.tloc{:num_shape, 1:2].values test = dF -iloc{nue_shape:, 1:2].values ‘Scaling our features using normalization. Normalizing data helps the algorithm in converging Le. to find local/ global minimum efficiently. sc = Minvaxscaler(feature_range = (8, 1)) train_scaled = sc. fit_transform( = 4s 227s /step - loss: 0.0051 vy Prediction aF_volune = np.vstack((train, test)) Anputs = df_volune[éf_volune.shape[@] - test.shape[e] - window:] inputs = inputs.reshape(-1,1) Anputs = se. transfora(inputs) hhum_2 = df_volune.shape[@] ~ num_shape + window 1 for 4 in range(windox, mum 2): X test_= np.reshape(input X_kestappend(X test_) [i-window:i, @], (window, 1)) X test = np.stack(x test) predict = model.predict(x test) predict = sc.inverse_transform(predict) 4b = 25 2985/step Intps:ifolab research google. comdrvegONuTZDhThishmemgMUoVBGWoSLU3IEhy iscroITO=TeXgHrfogKSSprintMode=true 414924, 1:23 PMA Bitcoin Price Prediction - Colaboratory GFF = predict - test print("AMSE:", np.sert(np-nean(4iffr*2))) fwse: 2127.1281081885868 plt.figure(Figsize=(28,7)) plt.plot(df[ 'Date®].values[17@0:], df_velune[17@@:], color = ‘red', label = ‘Real Bitcoin Price’) plt.plot(dfl ‘bate®][-predict.snape[@):].values, predict, color = ‘blue’, label = ‘Predicted Bitcoin Price’) plt.xticks(np-arange(220,df{ 1808: ].shape[@],28)) plt.title(’Bitcoin Price Prediction’) plt.xlabel(‘Date') plt.ylabel( ‘Price ($)") pit. Legend() plt.show() y GRU 4 The GRU architecture ‘nodelGRU = Secuential() ‘nodelGRU.add(GRUCunits#50, return_sequences*Toue, input_shapes(X train, shape(],1))) ‘sode1GRU.add(Dropout (@.2)) ‘nodelGRU.ad4(cRUCunits=58, return_sequence: ‘nodelGRV. add(oropout (@.2)) rue, Anput_shape=(X_train.shape[1],1))) snodelGRU.ad4(cRU(units=58, return_sequences=Toue, input_shape=(X_train.shape[1],1))) ssodelGRU.adé(oropout (8.2)) snodelGRU.add(6RU(units=5@)) ‘modelGRU.add(oropout (@.2)) ‘modelGRU.add(Dense(units=1)) ‘nodelGRU. susmary() Model: “sequential_ “Tayer (ype) —=~=~*~*~*~*~*~C«S Rp Shape S*S*«éi ra cru (GRU) (Wore, 68, 50) 7950) ropout_4 (Dropout) (Wore, 68, 58) ° Intps:ilolab research google. convdrvegONuTZDhThishmemgMUsVBGWoSUU3JIEh=en#scroTo=T@XglnfogkSspriniMode=true 414924, 1:23 PMA Bicoin Price Prediction - Colaboratory erat (ot) (one, 68, 50) 15300 dropout_s (Oropout) (one, 68, 50) ° era (Gt) (one, 68, 50) 15300 dropout_6 (Oropout) (one, 68, 50) ° eras (ot) (one, 50) 15300 éropout_7 (Oropout) (one, 50) ° dense_a (Derse) (one, 2) su Total parans: 52981 (210.55 KB) Trainable parans: 53901 (218.55 KB) Non-trainable parans: @ (2.80 Byte) node1GRU.conpile(optinizer='adan’, loss='nean_squared_error') modelGRU.fit(X train, y_train, epochs=160, baten_size=128) Intps:ifolab research google. comdrvegONuTZDhThishmemgMUoVBGWoSLU3IEhy iscroITO=TeXgHrfogKSSprintMode=true 414924, 1:23 PMA 36/26 [~ Epoch 97/108 26/16 Epoch 98/108 36/16 [ Epoch 59/108 36/36 [~ Epoch 180/180 36/36 [+ Bitcoin Price Prediction - Colaboratory 45 243ns/step 35 177es/step 3s 76ns/step 3s 17ans/step 45 2450s/step ‘ckeras.src.callbacks.istory at @x7a7@8e250fa0> predict = modelGRu.predict(x test) predict ~ sc.inverse_transferm(predict) st GiFF = predict - test Print("RNSE:", np.sqrt(np-nean(4itfe*2))) pit. pit. pit. pit. pit. pit. pit. pit. pit. as 2127.2281081885868 Figure(Figsize=(28,7)) plot (df[ "Date" J.values[1700:], df_volune[17#0:], color = + 15 2305/step oss loss: loss: oss: oss: “red! plot (df{ "Date" ]{-predict.shape[@]:].values, predict, color = xticks (np. arange( 200, 4f(1800: title("Bitcoin Price Prediction’) xlabel( Date") ylabel('Price ($)") egend() show) -shape[@],28)) + 0.0045, 2.0083 e000 0.0039 0.0039 |) label = "Real Biteoin Price”) blue’, label = “Precicted Bitcoin Price") Intps:ilolab research google. convdrvegONuTZDhThishmemgMUsVBGWoSUU3JIEh=en#scroTo=T@XglnfogkSspriniMode=true uw

You might also like