library(MASS)

data1<-Boston


cr<-cor(data1)
corrplot::corrplot(cr,type = 'lower')

corrplot::corrplot(cr,method = 'number')

split<-sample(2,nrow(data1),replace = T,prob=c(0.8,0.2))

train<-data1[split==1,]


test<-data1[split==2,]
         

model<-lm(medv~.-indus-age,data = train)

summary(model)
## 
## Call:
## lm(formula = medv ~ . - indus - age, data = train)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -15.2504  -2.8666  -0.5864   1.9972  25.9778 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  38.271517   5.798273   6.601 1.30e-10 ***
## crim         -0.105737   0.034812  -3.037  0.00254 ** 
## zn            0.042153   0.014996   2.811  0.00518 ** 
## chas          2.289875   1.063797   2.153  0.03195 *  
## nox         -18.612367   4.103161  -4.536 7.58e-06 ***
## rm            3.792754   0.454692   8.341 1.19e-15 ***
## dis          -1.558189   0.214532  -7.263 1.98e-12 ***
## rad           0.295983   0.071706   4.128 4.46e-05 ***
## tax          -0.011133   0.003754  -2.966  0.00320 ** 
## ptratio      -0.995191   0.146563  -6.790 4.04e-11 ***
## black         0.008952   0.003097   2.891  0.00405 ** 
## lstat        -0.524153   0.053588  -9.781  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 4.912 on 402 degrees of freedom
## Multiple R-squared:  0.7341, Adjusted R-squared:  0.7268 
## F-statistic: 100.9 on 11 and 402 DF,  p-value: < 2.2e-16
prdeic<-predict(model,test)

plot(test$medv,type ="l",lty=1.8,col="green")
lines(prdeic,type="l",col="blue")