Ejemplo n.º 1
0
                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)
Ejemplo n.º 2
0
                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))
Ejemplo n.º 3
0
                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)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
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
df1 = pd.DataFrame({"Aktual": dfy_data})
df2 = pd.DataFrame({"Prediksi": dfy_pred})
df_model = pd.concat([df1, df2], axis=1)
df_model.to_excel(path_test_DF + "/SEBELUM_LINE_1_2_HASIL.xlsx")

## 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))

pred_model2data = clfSVR_train_model.predict(img_as_array)
pred_model2data = pred_model2data.reshape(img[:, :, 0].shape)
pred_model2data[pred_model2data < 0] = 0.01