Machine Learning 4 : Linear Regression
LINEAR REGRESSION
In linear regression, the relationships are modeled using linear predictor functions whose unknown model parameters are estimated from the data. Basically a regression output is not discrete but a function like:
y = ax + b
y is target
a is slope
b is intercept
Error metrics:
The error is calculated
error = actual data - predicted data
The best linear regression is the one that
minimizes all points( actual - predicted)2
algo: ordinary least squares (ols) - gradient descent
But it’s not perfect because it’s an high value if you have multiple data point and lower with fewer, so it’s not comparable very well.
Instead R2
R squared measures the fraction of the variance of the dependent variable expressed by the regression. In simple linear regression it is simply the square of the correlation coefficient. It’s independent from the number of data.
(not good) 0 < r2 > 1 (good)
Sklearn:
from sklearn.linear_model import LinearRegression
clf = LinearRegression()
clf.fit(feature_training, label_training)
prediction = clf.predict(feature_test)
accuracy = clf.score(feature_test, label_test) [ -> R2 error metric ]
slope = clf.coef_
intercept = clf.intercept_
0 commenti