Simple question: is the result of a slope calculation in Python (say, stats.linregress() function) in units of radians, or unitless (e.g. what's 18 deg or 0.314 rad would be equivalent to 0.2 in the function output)?
scipy.stats.linregress returns the slope in terms of rise over run. As Stephen C. Steels answer says, the units of the resultant slope is the units of the y-axis multiplied by the inverse of the units of the x-axis (eg if y-units are metres, and x-units are seconds, then slope's units will be metres/second).
If you want the angle of slope (in radians and degrees), use arctangent:
import math from scipy.stats import linregress slope = linregress(xs, ys) # slope in units of y / x slope_angle = math.atan(slope) # slope angle in radians slope_angle_degrees = math.degrees(slope_angle) # slope angle in degrees
Slope and angle both measure how "not flat" something is, but they do so very differently. For instance, if you have a board that's not flat, the angle between the board and the ground measures how much you would rotate the board to make it flat, while the slope measures the height of the board divided by its horizontal length. They are related by slope = tangent(angle), but they are different concepts with different units. Also, while slope makes sense for any two dimensions, angle makes sense only when the dimensions are in the same space. So, for instance, 50 miles per hour can be interpreted as the slope of the graph of a car's position, but it would not make sense to try to convert that into an angle.
While there are ways to encode units in computer programs, as a general rule computer programs simply do not work with units. It's up to whoever uses a program to deal with units. The stats.linregress() function takes no units as inputs, and gives no units as outputs. If, rather than "what are the units of the output", you mean "what units should I add to the output for a physical interpretation", then you should add the units of y divided by the units of x. Note that if your input has multiple features with multiple units, then each coefficient will have different units. (This is why features are generally normalized before regularizing; regularization involves taking the sum of the coefficients (or their squares), and adding numbers with different units doesn't make sense.)
The library calculates the numerical value of the slope given the numerical values of your coordinates. It interpretation as a quantity (that is, a numerical value combined with units) is up to your program. Unless the library function is doing something very strange, the units for the slope through a set of points (x, y) would be unit of slope = (unit of y)/(unit of x).
So, for example, if x and y are both distances expressed in the identical units, the slope would be dimensionless. However, if x is a time in seconds, and y is a voltage in volts, then the slope would be in volts/second.
protected by gnat Jan 12 '18 at 23:16
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?