Linear Regression in R and Python - रस ग्रहणाचे प्रयत्न




R library functions for Linear Regression


package: stats
function: lm()
Returns an object of type: list



> typeof(lm.D9)
[1] "list"

> class(lm.D9)
[1] "lm"


> attributes(lm.D9)
$`names`
 [1] "coefficients"  "residuals"     "effects"       "rank"         
 [5] "fitted.values" "assign"        "qr"            "df.residual"  
 [9] "contrasts"     "xlevels"       "call"          "terms"        
[13] "model"        

$class
[1] "lm"


Further reading: 
https://www.machinelearningplus.com/machine-learning/complete-introduction-linear-regression-r/


Alternatives to lm:
http://www.sumsar.net/blog/2015/03/a-speed-comparison-between-flexible-linear-regression-alternatives-in-r/



Python library functions for Linear Regression

library: scikitlearn
object? : linear_model

Example: copied from python documentation
>>> import numpy as np
>>> from sklearn.linear_model import LinearRegression
>>> X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]])
>>> # y = 1 * x_0 + 2 * x_1 + 3
>>> y = np.dot(X, np.array([1, 2])) + 3
>>> reg = LinearRegression().fit(X, y)
>>> reg.score(X, y)
1.0
>>> reg.coef_
array([1., 2.])
>>> reg.intercept_ 
3.0000...
>>> reg.predict(np.array([[3, 5]]))
array([16.])

Good read:
http://scikit-learn.org/stable/modules/linear_model.html


Comments

Popular posts from this blog

Download course assignments from coursera (deeplearning.ai)