#!/usr/bin/env python # coding: utf-8 # In[ ]: import pandas as pd import matplotlib.pyplot as plt import numpy as np from math import sqrt from sklearn.metrics import mean_squared_error dff6=pd.read_csv('d:\\fanavard\\C_btt144C5.csv') # In[2]: import time start_time = time.time() from sklearn.ensemble import RandomForestRegressor x_train11=dff6.iloc[range(1,8000),:-20] x_test11=dff6.iloc[range(8800,10778),:-20] y_train11=dff6.iloc[range(1,8000),-10:] y_test11=dff6.iloc[range(8800,10778),-10:] regressor=RandomForestRegressor(n_estimators=100,random_state=0) cc=regressor.fit(x_train11,y_train11) end_time = time.time() print("Total execution time: {}".format(end_time - start_time)) # In[ ]: y_random_predC=cc.predict(x_test11) y_random_predC # In[5]: rmserandomC=sqrt(mean_squared_error(y_test11, y_random_predC)) rmserandomC # In[6]: import time start_time = time.time() from sklearn.neural_network import MLPRegressor #solver=lbfgs #activation=tanh mlp = MLPRegressor( hidden_layer_sizes=(100,), activation='logistic', solver='lbfgs', alpha=0.001, batch_size='auto', learning_rate='constant', learning_rate_init=0.01, power_t=0.5, max_iter=1000, shuffle=True, random_state=9, tol=0.0001, verbose=False, warm_start=False, momentum=0.9, nesterovs_momentum=True, early_stopping=False, validation_fraction=0.1, beta_1=0.9, beta_2=0.999, epsilon=1e-08) mlpC = mlp.fit(x_train11, y_train11) end_time = time.time() print("Total execution time: {}".format(end_time - start_time)) # In[ ]: y_mlp_predC=mlpC.predict(x_test11) y_mlp_predC # In[8]: rmsemlpC=sqrt(mean_squared_error(y_test11, y_mlp_predC)) rmsemlpC # In[9]: df=pd.read_csv(r'd:\\fanavard\\C_lastrow.csv') # In[10]: # tabdil log(an/an-1) be adad df3=df.iloc[-1,:-20] #df3.to_csv(r'd:\\fanavard\\B_last.csv') df4=df3.astype(np.float64) df5=df.iloc[-11,-11] y_pred1=mlpC.predict(df4.values.reshape(1,-1)) y=10**y_pred1 y1=np.zeros((1,10)) y1[0,0]=df5*y[0,0] for i in range(1,10): y1[0,i]=y1[0,i-1]*y[0,i-1] #y2=y1*y[0,1] #y3=y2*y[0,2] #y4=y3*y[0,3] #y5=y4*y[0,4] #y6=y5*y[0,5] #y7=y6*y[0,6] #y8=y7*y[0,7] #y9=y8*y[0,8] #y10=y9*y[0,9] y2=pd.DataFrame(y1) y2.to_csv('d:\\fanavard\\C_last1.csv') y2 # In[11]: y_predrand=cc.predict(df4.values.reshape(1,-1)) yrand=10**y_predrand y1rand=np.zeros((1,10)) y1rand[0,0]=df5*yrand[0,0] for i in range(1,10): y1rand[0,i]=y1rand[0,i-1]*yrand[0,i-1] #y2=y1*y[0,1] #y3=y2*y[0,2] #y4=y3*y[0,3] #y5=y4*y[0,4] #y6=y5*y[0,5] #y7=y6*y[0,6] #y8=y7*y[0,7] #y9=y8*y[0,8] #y10=y9*y[0,9] y2rand=pd.DataFrame(y1rand) y2rand.to_csv('d:\\fanavard\\C_last2.csv') y2rand # In[ ]: