Call:
stats::lm(formula = Sale_Price ~ Gr_Liv_Area, data = data)
Coefficients:
(Intercept) Gr_Liv_Area
4.8552133 0.0002437
tidymodels3
Aufgabe
Berechnen Sie ein lineares Modell mit tidymodels und zwar anhand des ames Datensatzes.
Modellgleichung: Sale_Price ~ Gr_Liv_Area, data = ames.
Berechnen Sie ein multiplikatives (exponenzielles) Modell.
Rücktransformieren Sie die Log-Werte in “Roh-Dollar”.
Lösung
Multiplikatives Modell:
Nicht vergessen: AV-Transformation in beiden Samples!
Datensatz aufteilen:
Modell definieren:
Modell fitten:
Modellgüte im Train-Sample:
Modellgüte im Train-Sample:
Call:
stats::lm(formula = Sale_Price ~ Gr_Liv_Area, data = data)
Residuals:
Min 1Q Median 3Q Max
-1.02587 -0.06577 0.01342 0.07202 0.39231
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 4.855e+00 7.355e-03 660.12 <2e-16 ***
Gr_Liv_Area 2.437e-04 4.648e-06 52.43 <2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.1271 on 2928 degrees of freedom
Multiple R-squared: 0.4842, Adjusted R-squared: 0.484
F-statistic: 2749 on 1 and 2928 DF, p-value: < 2.2e-16
R-Quadrat via easystats:
# R2 for Linear Regression
R2: 0.484
adj. R2: 0.484
| term | estimate | std.error | statistic | p.value |
|---|---|---|---|---|
| (Intercept) | 4.8552133 | 0.0073550 | 660.12345 | 0 |
| Gr_Liv_Area | 0.0002437 | 0.0000046 | 52.42983 | 0 |
Vorhersagen im Test-Sample:
| .pred |
|---|
| 5.073540 |
| 5.179049 |
| 5.307462 |
| 5.112527 |
| 5.180998 |
| 5.095714 |
preds ist ein Tibble, also müssen wir noch die Spalte .pred. herausziehen, z.B. mit pluck(preds, ".pred"):
| Sale_Price | Gr_Liv_Area | preds | .pred |
|---|---|---|---|
| 5.021189 | 896 | 5.073540 | 5.073540 |
| 5.235528 | 1329 | 5.179049 | 5.179049 |
| 5.595972 | 1856 | 5.307462 | 5.307462 |
| 5.152288 | 1056 | 5.112527 | 5.112527 |
| 5.264818 | 1337 | 5.180998 | 5.180998 |
| 4.982271 | 987 | 5.095714 | 5.095714 |
Oder mit unnest:
| Sale_Price | Gr_Liv_Area | .pred |
|---|---|---|
| 5.021189 | 896 | 5.073540 |
| 5.235528 | 1329 | 5.179049 |
| 5.595972 | 1856 | 5.307462 |
| 5.152288 | 1056 | 5.112527 |
| 5.264818 | 1337 | 5.180998 |
| 4.982271 | 987 | 5.095714 |
Oder wir binden einfach die Spalte an den Tibble:
| Sale_Price | Gr_Liv_Area | .pred |
|---|---|---|
| 5.021189 | 896 | 5.073540 |
| 5.235528 | 1329 | 5.179049 |
| 5.595972 | 1856 | 5.307462 |
| 5.152288 | 1056 | 5.112527 |
| 5.264818 | 1337 | 5.180998 |
| 4.982271 | 987 | 5.095714 |
Modellgüte im Test-Sample:
| .metric | .estimator | .estimate |
|---|---|---|
| rsq | standard | 0.5167906 |
Zur Interpretation von Log10-Werten
[1] 5e+05
[1] 0
Rücktransformation (ohne Bias-Korrektur):
Categories:
- ds1
- tidymodels
- prediction
- yacsda
- statlearning
- lm
- num