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')
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))
Total execution time: 12569.059749603271
y_random_predC=cc.predict(x_test11)
y_random_predC
rmserandomC=sqrt(mean_squared_error(y_test11, y_random_predC))
rmserandomC
0.00624448742182425
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))
Total execution time: 16.39056086540222
y_mlp_predC=mlpC.predict(x_test11)
y_mlp_predC
rmsemlpC=sqrt(mean_squared_error(y_test11, y_mlp_predC))
rmsemlpC
0.006049094337857621
df=pd.read_csv(r'd:\\fanavard\\C_lastrow.csv')
# 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
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | |
---|---|---|---|---|---|---|---|---|---|---|
0 | 63.083508 | 63.167126 | 63.063352 | 63.061589 | 62.954159 | 62.966345 | 62.963259 | 62.833833 | 62.90911 | 62.977791 |
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
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | |
---|---|---|---|---|---|---|---|---|---|---|
0 | 62.967888 | 62.935792 | 62.828084 | 62.733267 | 62.809714 | 62.605582 | 62.624054 | 62.768516 | 62.78658 | 62.723926 |