%% Using Random Number to select a random row from test data of nearly 3000 rows.
% G04 : Gas : Flow rate : 160
% G06 : Gas : Flow rate : 120
% OT09 : Oil : Flow rate : 30
% OT22 : Oil : Flow rate : 22
% W09 : Water : Flow rate : 10
% W03 : Water : Flow rate : 30

random_row = randi(3600)

%

% load dataset_to_be_used_in_ml_normalized.mat test_data_normalized training_data_normalized
test_data_for_q = test_data_normalized;
% test_data_for_q.cats_original = test_data_for_q.category;
% test_data_for_q.category = knn_classify.predictFcn(test_data_for_q)

%
% Multi Sensor Inputs like pressure, temperature, density and acceleroemeters at any instantaneous time of duration 1 sec

sensor_data_1 = test_data_for_q(random_row,:)

%
%% Flow type Classification
% Classify flow type using sensor_data_1 as input.
%% Original Flow type

sensor_data_1.category 

%
%% Removing all sensor inputs and selecting only top 3 features of accelerometer channel 1 as input to classification model

sensor_data_1.category = [];
% sensor_data_1.cats_original = [];
acc_data = removevars(sensor_data_1,{'name','time','temp_in','temp_out','press_in','press_out','STec_rho','MPP_TIn','MPP_TOut','MPP_pIn','MPP_dp','active_ref','average_q','peak_value_1_1','peak_value_2_1','peak_value_3_1','meanfreq_1','zerocrossrate_1','peak2peak_fd_1','statelevels_td_low_1','statelevels_td_high_1','peak2peak_td_1','rms_1','rssq_1','peak2rms_1','bandpower_1','obw_1','powerbw_1','sfdr_1','std_1','max_1','range_1','iqr_1','mean_1','median_1','peak_value_1_2','peak_value_2_2','peak_value_3_2','statelevels_fd_low_2','statelevels_fd_high_2','peak2peak_fd_2','statelevels_td_low_2','statelevels_td_high_2','meanfreq_2','medianfreq_2','peak2peak_td_2','rms_2','rssq_2','peak2rms_2','bandpower_2','obw_2','powerbw_2','sfdr_2','zerocrossrate_2','std_2','max_2','range_2','iqr_2','mean_2','median_2','peak_value_1_3','peak_value_2_3','peak_value_3_3','statelevels_fd_low_3','statelevels_fd_high_3','peak2peak_fd_3','statelevels_td_low_3','statelevels_td_high_3','meanfreq_3','medianfreq_3','peak2peak_td_3','rms_3','rssq_3','peak2rms_3','bandpower_3','obw_3','powerbw_3','sfdr_3','zerocrossrate_3','std_3','max_3','range_3','iqr_3','mean_3','median_3','peak_value_1_4','peak_value_2_4','peak_value_3_4','statelevels_fd_low_4','statelevels_fd_high_4','peak2peak_fd_4','statelevels_td_low_4','statelevels_td_high_4','meanfreq_4','medianfreq_4','peak2peak_td_4','rms_4','rssq_4','peak2rms_4','bandpower_4','obw_4','powerbw_4','sfdr_4','zerocrossrate_4','std_4','max_4','range_4','iqr_4','mean_4','median_4'});
acc_data

%
%% Predicted Flow type
% SVM

category_prediction_1 = svm_classify.predictFcn(acc_data)

% KNN

category_prediction_2 = knn_classify.predictFcn(acc_data)

%
% Neural Network

category_prediction_3 = nn_classify.predictFcn(acc_data)

%
%% Flow Rate Prediction

%sensor_data_3 = test_data_for_q(random_row,:);
sensor_data_1.category = category_prediction_2;

%
% Removing unncessary variables in order to make data compatible with respective models

sensor_data_2 = removevars(sensor_data_1,{'name','time','temp_in','temp_out','press_in','press_out','STec_rho','MPP_TIn','MPP_TOut','MPP_pIn','MPP_dp','average_q','peak_value_1_3','peak_value_2_3','peak_value_3_3','statelevels_fd_low_3','statelevels_fd_high_3','peak2peak_fd_3','statelevels_td_low_3','statelevels_td_high_3','meanfreq_3','medianfreq_3','peak2peak_td_3','rms_3','rssq_3','peak2rms_3','bandpower_3','obw_3','powerbw_3','sfdr_3','zerocrossrate_3','std_3','max_3','range_3','iqr_3','mean_3','median_3','peak_value_1_4','peak_value_2_4','peak_value_3_4','statelevels_fd_low_4','statelevels_fd_high_4','peak2peak_fd_4','statelevels_td_low_4','statelevels_td_high_4','meanfreq_4','medianfreq_4','peak2peak_td_4','rms_4','rssq_4','peak2rms_4','bandpower_4','obw_4','powerbw_4','sfdr_4','zerocrossrate_4','std_4','max_4','range_4','iqr_4','mean_4','median_4'});
sensor_data_3 = removevars(sensor_data_1,{'name','time','temp_in','temp_out','press_in','press_out','STec_rho','MPP_TIn','MPP_TOut','MPP_pIn','MPP_dp','active_ref','average_q','peak_value_1_2','peak_value_2_2','peak_value_3_2','statelevels_fd_low_2','statelevels_fd_high_2','peak2peak_fd_2','statelevels_td_low_2','statelevels_td_high_2','meanfreq_2','medianfreq_2','peak2peak_td_2','rms_2','rssq_2','peak2rms_2','bandpower_2','obw_2','powerbw_2','sfdr_2','zerocrossrate_2','std_2','max_2','range_2','iqr_2','mean_2','median_2','peak_value_1_3','peak_value_2_3','peak_value_3_3','statelevels_fd_low_3','statelevels_fd_high_3','peak2peak_fd_3','statelevels_td_low_3','statelevels_td_high_3','meanfreq_3','medianfreq_3','peak2peak_td_3','rms_3','rssq_3','peak2rms_3','bandpower_3','obw_3','powerbw_3','sfdr_3','zerocrossrate_3','std_3','max_3','range_3','iqr_3','mean_3','median_3','peak_value_1_4','peak_value_2_4','peak_value_3_4','statelevels_fd_low_4','statelevels_fd_high_4','peak2peak_fd_4','statelevels_td_low_4','statelevels_td_high_4','meanfreq_4','medianfreq_4','peak2peak_td_4','rms_4','rssq_4','peak2rms_4','bandpower_4','obw_4','powerbw_4','sfdr_4','zerocrossrate_4','std_4','max_4','range_4','iqr_4','mean_4','median_4'});
sensor_data_4 = removevars(sensor_data_1,{'name','time','temp_in','temp_out','press_in','press_out','STec_rho','MPP_TIn','MPP_TOut','MPP_pIn','MPP_dp','active_ref','average_q','peak_value_1_1','peak_value_2_1','peak_value_3_1','statelevels_fd_low_1','statelevels_fd_high_1','peak2peak_fd_1','statelevels_td_low_1','statelevels_td_high_1','meanfreq_1','medianfreq_1','peak2peak_td_1','rms_1','rssq_1','peak2rms_1','bandpower_1','obw_1','powerbw_1','sfdr_1','zerocrossrate_1','std_1','max_1','range_1','iqr_1','mean_1','median_1','peak_value_1_3','peak_value_2_3','peak_value_3_3','statelevels_fd_low_3','statelevels_fd_high_3','peak2peak_fd_3','statelevels_td_low_3','statelevels_td_high_3','meanfreq_3','medianfreq_3','peak2peak_td_3','rms_3','rssq_3','peak2rms_3','bandpower_3','obw_3','powerbw_3','sfdr_3','zerocrossrate_3','std_3','max_3','range_3','iqr_3','mean_3','median_3','peak_value_1_4','peak_value_2_4','peak_value_3_4','statelevels_fd_low_4','statelevels_fd_high_4','peak2peak_fd_4','statelevels_td_low_4','statelevels_td_high_4','meanfreq_4','medianfreq_4','peak2peak_td_4','rms_4','rssq_4','peak2rms_4','bandpower_4','obw_4','powerbw_4','sfdr_4','zerocrossrate_4','std_4','max_4','range_4','iqr_4','mean_4','median_4'});
sensor_data_5 = removevars(sensor_data_1,{'name','time','temp_in','temp_out','press_in','press_out','STec_rho','MPP_TIn','MPP_TOut','MPP_pIn','MPP_dp','active_ref','average_q','peak_value_1_4','peak_value_2_4','peak_value_3_4','statelevels_fd_low_4','statelevels_fd_high_4','peak2peak_fd_4','statelevels_td_low_4','statelevels_td_high_4','meanfreq_4','medianfreq_4','peak2peak_td_4','rms_4','rssq_4','peak2rms_4','bandpower_4','obw_4','powerbw_4','sfdr_4','zerocrossrate_4','std_4','max_4','range_4','iqr_4','mean_4','median_4'});

%% Original Flow Rate
% Flow rate mentioned by active reference for the experiment

sensor_data_2.active_ref

%
%% Predicted Flow Rate
%% Accelerometer channel 1 & 2
% Ensemble Bagged (7 features)

en_ch12_feat8.predictFcn(sensor_data_2)

% GPR (51 features)

gp_ch12_feat51.predictFcn(sensor_data_2)

%% Accelerometer channel 1
% GPR (5 features)

gp_ch1_feat5.predictFcn(sensor_data_3)

%
%% Accelerometer channel 2 (GP)
% GPR (4 features)

gp_ch2_feat4.predictFcn(sensor_data_4)

%
%% Accelerometer channel 1,2 and 3 Ensemble bagged

ens_ch123_feat8.predictFcn(sensor_data_5)