image_output_1.png
import matplotlib.pyplot as plt

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

demo_data = pd.read_csv('/kaggle/input/pac-regression-4/PAC1954_Demo_default_data.csv')
num_samples = demo_data.shape[0]
split = round(num_samples * 0.7)
train_demo_data_x = np.array(demo_data[' Vsense_Ch1'].iloc[0:split]).reshape(-1, 1)
test_demo_data_x = np.array(demo_data[' Vsense_Ch1'].iloc[split + 1:num_samples]).reshape(-1, 1)
train_demo_data_y = np.array(demo_data['Count'].iloc[0:split]).reshape(-1, 1)
test_demo_data_y = np.array(demo_data['Count'].iloc[split + 1:num_samples]).reshape(-1, 1)

fig, ax = plt.subplots(figsize=(10,10))
ax.plot(train_demo_data_y[0:80], train_demo_data_x[0:80], 'bo', label='Initial Vsense Data') #, c = 'blue')
#ax.plot(train_demo_data_y[200:], train_demo_data_x[200:], 'r+', label='Additional Vsense Data') #, c = 'blue')
#ax.plot(x_values[0:max_plot], y[0:max_plot], label='Decision Tree Regressor', c = 'green')
#ax.plot(x_values[0:max_plot], error_detection[0:max_plot], label='Error', c = 'red')
plt.xlabel("Window Position")
plt.ylabel("Vsense")
plt.title("Input Data")
plt.legend(loc='center right')
plt.show()

dtr_model_demo_data = dtr(max_depth=8)
dtr_model_demo_data.fit(train_demo_data_y[0:80], train_demo_data_x[0:80])
prediction_demo_data_y = dtr_model_demo_data.predict(test_demo_data_y)
dtr_model_demo_data_all = dtr(max_depth=8)
dtr_model_demo_data_all.fit(train_demo_data_y, train_demo_data_x)
prediction_demo_data_all_y = dtr_model_demo_data_all.predict(test_demo_data_y)

# look at the data a little
#max_plot = test_demo_data_y.shape[0]
max_plot = 160
x_values = [(x+10) for x in range(0,max_plot)]
fig, ax = plt.subplots(figsize=(20,10))
ax.plot(x_values[0:max_plot], test_demo_data_x[0:max_plot], label='PAC Vsense Training Data', c = 'blue')
ax.plot(x_values[0:max_plot], prediction_demo_data_y[0:max_plot], label='Model 80 samples Prediction', c = 'red')
#ax.plot(x_values[0:max_plot], prediction_demo_data_all_y[0:max_plot], label='Model All Data Prediction', c = 'orange')
#ax.plot(x_values[0:max_plot], y[0:max_plot], label='Decision Tree Regressor', c = 'red')
#ax.plot(x_values[0:max_plot], error_detection[0:max_plot], label='Error', c = 'red')
plt.xlabel("Sample")
plt.ylabel("Vsense")
plt.title("Training Data and Model Prediction")
plt.legend()
plt.show()

fig, ax = plt.subplots(figsize=(10,10))
ax.plot(train_demo_data_y[0:80], train_demo_data_x[0:80], 'bo', label='Initial Vsense Data') #, c = 'blue')
ax.plot(train_demo_data_y[200:], train_demo_data_x[200:], 'r+', label='Additional Vsense Data') #, c = 'blue')
#ax.plot(x_values[0:max_plot], y[0:max_plot], label='Decision Tree Regressor', c = 'green')
#ax.plot(x_values[0:max_plot], error_detection[0:max_plot], label='Error', c = 'red')
plt.xlabel("Window Position")
plt.ylabel("Vsense")
plt.title("Input Data")
plt.legend(loc='center right')
plt.show()

max_plot = 160
x_values = [(x+10) for x in range(0,max_plot)]
fig, ax = plt.subplots(figsize=(20,10))
ax.plot(x_values[0:max_plot], test_demo_data_x[0:max_plot], label='PAC Vsense Training Data', c = 'blue')
ax.plot(x_values[0:max_plot], prediction_demo_data_y[0:max_plot], label='Model 80 samples Prediction', c = 'red')
ax.plot(x_values[0:max_plot], prediction_demo_data_all_y[0:max_plot], label='Model All Data Prediction', c = 'orange')
plt.xlabel("Sample")
plt.ylabel("Vsense")
plt.title("Training Data and Model Predictions")
plt.legend()
plt.show()

ch2_train_data4 = pd.read_csv('/kaggle/input/pac-regression-4/PAC_regression_training4.csv')
ch2_test_data4 = pd.read_csv('/kaggle/input/pac-regression-4/PAC_regression_test4.csv')
train_vsense_ch1_data4_x = np.array(ch2_train_data4[' Vsense_Ch1']).reshape(-1, 1)
test_vsense_ch1_data4_x = np.array(ch2_test_data4[' Vsense_Ch1'].iloc[3:]).reshape(-1, 1)
train_y = np.array(ch2_train_data4['Count']).reshape(-1, 1)
test_y = np.array(ch2_test_data4['Count']).reshape(-1, 1)

fig, ax = plt.subplots(figsize=(10, 10))
ax.plot(ch2_train_data4['Count'], ch2_train_data4[' Vsense_Ch1'], 'bo', label='PAC Vsense Data')
plt.xlabel('Window Position')
plt.ylabel('Vsense')
plt.title('Input Data')
plt.legend()
plt.show()