Skip to main content
Tweeted twitter.com/StackElectronix/status/1456139154958471171
Became Hot Network Question
edited tags
Link
Null
  • 7.7k
  • 17
  • 37
  • 48
Source Link
Jerzy
  • 41
  • 3

How to calculate resistance from points using linear regression?

I have a lists of current and voltage of one device and I would like to calculate the resistance. There are some errors with the coordinate, so I have made a script where I calculate the line by linear regression.

from scipy.stats import linregress
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

voltage = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
current = np.array([3, 6, 6, 10, 9, 15, 14, 16, 20, 25])
slope, intercept, r_value, p_value, std_err = linregress(voltage, current)
print(linregress(voltage, current))

plt.plot(voltage, current, 'o', label='original data')
plt.plot(voltage, intercept + slope * voltage, 'r', label='fitted line')
plt.xlabel('Voltage')
plt.ylabel('Current')
plt.show()

Which plots me: enter image description here

and prints:

LinregressResult(slope=2.206060606060606, intercept=0.2666666666666675, rvalue=0.9703665463597563, pvalue=3.2552108142876276e-06, stderr=0.1942232770783282, intercept_stderr=1.2051237414984548)

What is the value of the resistance for this device, how to calculate it from line?