best_gamma = gamma best_epsilon = epsilon best_parm = { 'C': best_C, 'Gamma': best_gamma, 'Epsilon': best_epsilon } clfSVR_Model = SVR(kernel='rbf', C=best_C, gamma=best_gamma, epsilon=best_epsilon) clfSVR_Model.fit(X_train, y_train) Acc_Model = clfSVR_Model.score(X_test, y_test) y_pred = clfSVR_Model.predict(X_test) RMSE_Model = F2020ML.F2020_RMSE(y_test, y_pred) ## Make data frame from predic model data = {'Predict': y_pred, 'Actual': y_test} test_df1 = pd.DataFrame(data) test_df1.head(5) path = r"D:\TIFF DATA\SUMATERA\GEE_WA_SUMSEL\SUMSEL 1" write = pd.ExcelWriter(path + '/Data_Cidanau.xlsx', engine='xlsxwriter') test_df1.to_excel(write, sheet_name='Sheet1') write.save() ## Prediction model with data image new_shape = (img.shape[0] * img.shape[1], img.shape[2]) img_as_array = img[:, :, :6].reshape(new_shape) print('Reshaped from {o} to {n}'.format(o=img.shape, n=img_as_array.shape))
best_C = C best_gamma = gamma best_epsilon = epsilon best_parm = { 'C': best_C, 'Gamma': best_gamma, 'Epsilon': best_epsilon } clfSVR1 = SVR(kernel='rbf', C=best_C, epsilon=best_epsilon, gamma=best_gamma) clfSVR1.fit(X_train, y_train) clfSVR1.score(X_test, y_test) # tes= clfSVR1.score(X_test, y_test) # y_pred = clfSVR1.predict(X_test) y_pred = clfSVR1.predict(X_test) a = F2020ML.F2020_RMSE(y_test, y_pred) new_shape = (img.shape[0] * img.shape[1], img.shape[2]) img_as_array = img[:, :, :6].reshape(new_shape) print('Reshaped from {o} to {n}'.format(o=img.shape, n=img_as_array.shape)) # Now predict for each pixel class_prediction = clfSVR1.predict(img_as_array) class_prediction = class_prediction.reshape(img[:, :, 0].shape) # class_prediction = Min_Max_Norm(class_prediction) # Make data prediction to TIF file output_path = path1 + "frci6.TIF" raster = path1 + 'Cidanau_Stack_150319.tiff' in_path = gdal.Open(raster)
path = 'D:/00RCode/Result/Data Sumatera/' dframe = pd.read_excel(path + 'FRCI_Line_7.xlsx') colmn = ['Band_3', 'Band_4', 'Band_5', 'Band_6', 'Band_7'] colmn = [ 'Band_2', 'Band_3', 'Band_4', 'Band_5', 'Band_6', 'Band_7', 'DEM', 'ASPECT_R', 'SLOPE_R' ] trget = 'frci' trget = 'frci_5m' dfx = pd.DataFrame(dframe, columns=colmn) dfy = np.asarray(dframe[trget]) X_train, X_test, y_train, y_test = train_test_split(dfx, dfy, test_size=0.3, random_state=4) sc = StandardScaler() X_train = sc.fit_transform(X_train) X_test = sc.transform(X_test) clfSVR = SVR(kernel='rbf', C=1, epsilon=0.1) clfSVR.fit(X_train, y_train) score = clfSVR.score(X_test, y_test) y_pred = clfSVR.predict(X_test) print(F2020ML.F2020_DF(dframe)) print(dframe.head()) print(F2020ML.F2020_RMSE(y_test, y_pred)) # print(F2020ML.F2020_RSQRT(y_test, y_pred)) print(score, clfSVR)
## Run Modul_ML and Modul_TOPO import pandas as pd import numpy as np from Modul_Topo import FTEST01 from Modul_Topo.FORESTS2020 import allFunc from Modul_ML.F17122018ML import F2020ML df = pd.read_excel('C:/Users/user/Dropbox/FORESTS2020/00AllData/Data 580.xlsx') # print(df.head()) column = ['Band_2', 'Band_3', 'Band_4', 'Band_5', 'Band_6', 'Band_7'] target = 'frci' dfX = pd.DataFrame(df, columns=column) dfY = np.asarray(df[target]) # Check SVR and RFR parameters print('Values SVR: ', F2020ML.F2020_SVR(dfX, dfY, 0.3, 4)) print('Values RFR: ', F2020ML.F2020_RFR(dfX, dfY, 0.3, 4))
best_gamma = gamma best_epsilon = epsilon best_parm = { 'C': best_C, 'Gamma': best_gamma, 'Epsilon': best_epsilon } clfSVR_Model = SVR(kernel='rbf', C=best_C, gamma=best_gamma, epsilon=best_epsilon) clfSVR_Model.fit(X_train, y_train) Acc_Model = clfSVR_Model.score(X_test, y_test) y_pred = clfSVR_Model.predict(X_test) RMSE_Model = F2020ML.F2020_RMSE(y_test, y_pred) ## Load Dataframe for test the model path_load = r"D:\TIFF DATA\SUMATERA\GEE_WA_SUMSEL\Data Latihan\L8_SMT_1_6_SEBELUM" load_df = pd.read_excel(path_load + '/WA_Line_14_15_Sebelum_SMT_Balance.xlsx') select_col_test = ['Band_2', 'Band_3', 'Band_4', 'Band_5', 'Band_6', 'Band_7'] select_row_test = 'frci5m' dfx_test = pd.DataFrame(load_df, columns=select_col_test) dfy_test = np.asarray(load_df[select_row_test]) y_pred_test = clfSVR_Model.predict(dfx_test) # y_pred_df = y_pred.ravel(X_test) # y_test_df = y_test.ravel() df1 = pd.DataFrame({"y1": dfy_test}) df2 = pd.DataFrame({"y2": y_pred_test}) df_model = pd.concat([df1, df2], axis=1)
best_C = C best_gamma = gamma best_epsilon = epsilon best_parm = { 'C': best_C, 'Gamma': best_gamma, 'Epsilon': best_epsilon } clfSVR1 = SVR(kernel='rbf', C=best_C, epsilon=best_epsilon, gamma=best_gamma) clfSVR1.fit(X_train, y_train) clfSVR1.score(X_test, y_test) # tes= clfSVR1.score(X_test, y_test) # y_pred = clfSVR1.predict(X_test) y_pred = clfSVR1.predict(X_test) a = F2020ML.F2020_RMSE(y_test, y_pred) new_shape = (img.shape[0] * img.shape[1], img.shape[2]) img_as_array = img[:, :, :6].reshape(new_shape) print('Reshaped from {o} to {n}'.format(o=img.shape, n=img_as_array.shape)) # Now predict for each pixel class_prediction = clfSVR1.predict(img_as_array) class_prediction = class_prediction.reshape(img[:, :, 0].shape) # class_prediction = Min_Max_Norm(class_prediction) # Make data prediction to TIF file # output_path = path1 + "frci6.TIF" # raster = path1 + 'Cidanau_Stack_150319.tiff' # in_path = gdal.Open(raster)
gdal_array.GDALTypeCodeToNumericTypeCode(load_stack_data.GetRasterBand(1).DataType)) for b in range(img.shape[2]): img[:, :, b] = load_stack_data.GetRasterBand(b + 1).ReadAsArray() plt.imshow(img[:, :, 4], cmap=plt.get_cmap('terrain')) plt.title('DATA LandSat') ## Load Dataframe for make the model path_train_DF = r"D:\00RCode\Result\Data Sumatera\Data Sumatera No_Normalize" loadFile = pd.read_excel(path_train_DF + '/Cidanau_Join_LINE6_61.18.xlsx') select_col = ['Band_2', 'Band_3', 'Band_4', 'Band_5', 'Band_6', 'Band_7'] select_row = 'frci' dfx = pd.DataFrame(loadFile, columns=select_col) dfy = np.asarray(loadFile[select_row]) ## clfSVR_train_model = F2020ML.SVR_Model(dfx, dfy, test_size=0.3, r_state=5) print(clfSVR_train_model) ## Load Dataframe for test the model --- 1 path_test_DF = r"D:\TIFF DATA\F2020 All Data\SUMSEL\MALTA\Sebelum" load_df = pd.read_excel(path_test_DF + '/SEBELUM_LINE_1_2_SUMSEL_BALANCE.xlsx') select_col_test = ['Band_2', 'Band_3', 'Band_4', 'Band_5', 'Band_6', 'Band_7'] select_row_test = 'frci5m' dfx_data = pd.DataFrame(load_df, columns=select_col_test) dfy_data = np.asarray(load_df[select_row_test]) ## Prediction data from model --- 2 dfy_pred = clfSVR_train_model.predict(dfx_data) Model_RMSE = F2020ML.F2020_RMSE(dfy_data, dfy_pred) print(Model_RMSE) ## Save Prediction data --- 3