update
This commit is contained in:
49
1d-qsar/cuda/extract_log_CV_MSE.py
Normal file
49
1d-qsar/cuda/extract_log_CV_MSE.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import re
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
def extract_cv_mse(log_path):
|
||||
"""
|
||||
从日志文件中提取特征数和对应的CV MSE。
|
||||
日志行格式示例:
|
||||
"Current number of features: 156, CV MSE: 4.9253"
|
||||
"""
|
||||
feature_counts = []
|
||||
cv_mses = []
|
||||
pattern = re.compile(r"Current number of features:\s*(\d+),\s*CV MSE:\s*([\d\.]+)")
|
||||
with open(log_path, "r") as f:
|
||||
for line in f:
|
||||
match = pattern.search(line)
|
||||
if match:
|
||||
feature_counts.append(int(match.group(1)))
|
||||
cv_mses.append(float(match.group(2)))
|
||||
return feature_counts, cv_mses
|
||||
|
||||
def plot_cv_mse(log_path, output_image="cv_mse_curve.png"):
|
||||
"""
|
||||
根据日志文件中的数据绘制 CV MSE 曲线,并保存图片
|
||||
"""
|
||||
feature_counts, cv_mses = extract_cv_mse(log_path)
|
||||
|
||||
if not feature_counts:
|
||||
print("没有在日志文件中找到有效的 'Current number of features' 数据。")
|
||||
return
|
||||
|
||||
plt.figure(figsize=(8,6))
|
||||
plt.plot(feature_counts, cv_mses, marker='o', linestyle='-')
|
||||
plt.xlabel("Number of Features")
|
||||
plt.ylabel("CV MSE")
|
||||
plt.title("CV MSE vs. Number of Features")
|
||||
plt.grid(True)
|
||||
plt.savefig(output_image, dpi=300)
|
||||
plt.close()
|
||||
print(f"CV MSE 曲线图已保存为: {output_image}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
if len(sys.argv) < 2:
|
||||
print("用法: python script.py <log_file_path>")
|
||||
else:
|
||||
log_file = sys.argv[1]
|
||||
plot_cv_mse(log_file)
|
||||
|
||||
# python 1d-qsar/cuda/RFE_cuml_permutation_update.log
|
||||
Reference in New Issue
Block a user