-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReconstructed_Data.py
75 lines (55 loc) · 2.32 KB
/
Reconstructed_Data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from statsmodels.nonparametric.smoothers_lowess import lowess
plt.rcParams['font.family'] = 'Times New Roman'
plt.rcParams['font.size'] = 12
# Step 1: Load the detection result data set
data_path = r'C:\Users\Dell\Desktop\SVM_outlier.csv'
data = pd.read_csv(data_path)
# Separate normal and outlier values
normal_data = data[data['outliers'] == 1]
outliers_data = data[data['outliers'] == -1]
# Step 3: smooth
smoothed_outliers_data = outliers_data.copy()
for column in ['AC', 'DEN']:
smoothed_values = lowess(
endog=smoothed_outliers_data[column],
exog=smoothed_outliers_data['DEPTH'],
frac=0.05
)
smoothed_outliers_data[column] = smoothed_values[:, 1]
reconstructed_data = pd.concat([normal_data, smoothed_outliers_data]).sort_values(by='DEPTH')
# Save to CSV file
output_file_path = r'C:\Users\Dell\Desktop\SVM_outlier_Reconstructed_Data.csv'
reconstructed_data.to_csv(output_file_path, index=False)
# Step 5: Save to CSV file
output_file_path = r'C:\Users\Dell\Desktop\SVM_outlier_Reconstructed_Data.csv'
reconstructed_data.to_csv(output_file_path, index=False)
# Determine the maximum and minimum values for the DEPTH column
depth_min = data['DEPTH'].min()
depth_max = data['DEPTH'].max()
# visualization
plt.figure(figsize=(10, 5))
plt.subplot(1, 2, 1)
plt.plot(data['AC'], data['DEPTH'], color='blue', label='Original AC', linewidth=1.5)
plt.plot(reconstructed_data['AC'], reconstructed_data['DEPTH'], color='green', label='Reconstructed AC', linewidth=1.5)
plt.ylim(top=1345.9, bottom=1125)
plt.gca().invert_yaxis()
plt.ylabel('DEPTH')
plt.xlabel('AC')
#plt.title('AC vs DEPTH')
#plt.legend(loc='upper left')
plt.subplot(1, 2, 2)
plt.plot(data['DEN'], data['DEPTH'], color='blue', label='Original DEN', linewidth=1.5)
plt.plot(reconstructed_data['DEN'], reconstructed_data['DEPTH'], color='green', label='Reconstructed DEN', linewidth=1.5)
plt.ylim(top=1345.9, bottom=1125)
plt.gca().invert_yaxis()
plt.ylabel('DEPTH')
plt.xlabel('DEN')
plt.title('DEN vs DEPTH')
plt.legend(loc='upper left')
plt.tight_layout()
plt.show()
image_output_path = r'C:\Users\Dell\Desktop\SVM_outlier_Reconstruction_Comparison.png'
plt.savefig(image_output_path, dpi=600)