Differential-Amplifier/Amplifier Calibration/script3.py

40 lines
1.1 KiB
Python

import numpy as np
from sklearn.linear_model import LinearRegression
# Load data from the CSV file
data = np.genfromtxt('data2.csv', delimiter=',', skip_header=1, invalid_raise=False, missing_values='NaN')
# Number of data points in each set
set_size = 80
# List to store slopes of individual fitting functions
slopes = []
# Iterate through the data sets
for i in range(len(data) // set_size):
# Extract data for the current set
set_data = data[i * set_size: (i + 1) * set_size]
# Extract x and y values
x_values = set_data[:, 1]
y_values = set_data[:, 2]
# Fit linear regression model
model = LinearRegression().fit(x_values.reshape(-1, 1), y_values)
# Get slope of the linear fitting function
slope = model.coef_[0]
# Append slope to the list
slopes.append(slope)
# Print the slope for the current set
print("Slope of linear fitting function for set", i+1, ":", slope)
# Calculate the average slope
average_slope = np.mean(slopes)
# Print the average slope
print("\nAverage slope (V / V):", average_slope*1000)
print("STDEV slope :", np.std(slopes)*1000)