29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
import numpy as np
|
|
from sklearn.metrics import r2_score
|
|
import matplotlib.pyplot as plt
|
|
|
|
# Load data from the CSV file, skipping the first row (header) and handling missing or bad values
|
|
data = np.genfromtxt('data.csv', delimiter=',', skip_header=1, invalid_raise=False, missing_values='NaN')
|
|
|
|
# Remove rows containing missing values
|
|
data = data[~np.isnan(data).any(axis=1)]
|
|
|
|
# Extract columns
|
|
wavegen_output = data[:, 0]
|
|
diff_amplifier_measured = data[:, 2]
|
|
wavegen_measured = data[:, 1]
|
|
|
|
# Define polynomial degree
|
|
degree = 1
|
|
|
|
# Calculate polynomial fits
|
|
coefficients_output = np.polyfit(wavegen_output, diff_amplifier_measured, degree)
|
|
coefficients_measured = np.polyfit(wavegen_measured, diff_amplifier_measured, degree)
|
|
|
|
# Generate polynomial functions using the coefficients
|
|
poly_func_output = np.poly1d(coefficients_output)
|
|
poly_func_measured = np.poly1d(coefficients_measured)
|
|
|
|
# Calculate R^2 value
|
|
r_squared_output = r2_score(diff_amplifier_measured, poly_func_output(wavegen_output))
|
|
r_squared_measured = r2_score(diff_amplifier_measured, poly_func_measured(wavegen_measured)) |