How to do it...

Perform the following steps to implement a linear regression in MapReduce:

  1. First, load the cats dataset from the MASS package:
        > library(MASS)
        > data(cats)
        > X = matrix(cats$Bwt)
        > y = matrix(cats$Hwt)  
  1. You can then generate a linear regression model by calling the lm function:
 > model = lm(y~X) > summary(model) Call: lm(formula = y ~ X) Residuals: Min 1Q Median 3Q Max -3.5694 -0.9634 -0.0921 1.0426 5.1238 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) -0.3567 0.6923 -0.515 0.607 X 4.0341 0.2503 16.119 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 1.452 on 142 degrees of freedom Multiple R-squared: 0.6466, Adjusted R-squared: 0.6441 F-statistic: ...

Get Machine Learning with R Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.