#clear enviroment
rm(list = ls())
#Working directory
setwd("C:/Users/USER/Desktop/JOOUST")
# Import dataset
library(readxl)
Anxiety <- read_excel("Anxiety.xlsx")Supervised Machine Learning
Linear Regression Algorithm
Cleaning data set:Convert character to factor variable
Anxiety$Gender<-as.factor(Anxiety$Gender)
Anxiety$FamiliyHistry<-as.factor(Anxiety$FamiliyHistry)
Anxiety$Medication<-as.factor(Anxiety$Medication)
Anxiety$Dizziness<-as.factor(Anxiety$Dizziness)library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
Divide data set
set.seed(2)
ind<-sample(2,nrow(Anxiety),replace = T,prob = c(0.8,0.2))
Train_dataset<-Anxiety[ind==1,]
Test_dataset<-Anxiety[ind==2,]Exploratory Analysis
library(corrplot)corrplot 0.95 loaded
corr <- Anxiety %>%
select(AnxietyAttack,Age,SleepHrs,CaffeineIntake,HeartRate) %>%
replace(is.na(.), 0)
correlation = cor(corr)
corrplot(correlation, type="upper", method="color", addCoef.col = "black")Implementing Model From Training data set
Model<-lm(AnxietyAttack~Age+Gender+FamiliyHistry+Medication+SleepHrs+CaffeineIntake+HeartRate+Dizziness,data =Train_dataset )
summary(Model)
Call:
lm(formula = AnxietyAttack ~ Age + Gender + FamiliyHistry + Medication +
SleepHrs + CaffeineIntake + HeartRate + Dizziness, data = Train_dataset)
Residuals:
Min 1Q Median 3Q Max
-4.8937 -2.4876 -0.2633 2.4895 4.7226
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.5556910 0.1826466 30.418 <2e-16 ***
Age -0.0040530 0.0021767 -1.862 0.0626 .
GenderMale 0.0453431 0.0596408 0.760 0.4471
GenderOther 0.2289252 0.1543316 1.483 0.1380
FamiliyHistryYes 0.0366965 0.0596894 0.615 0.5387
MedicationYes 0.0216700 0.0732075 0.296 0.7672
SleepHrs -0.0113479 0.0145983 -0.777 0.4370
CaffeineIntake 0.0001757 0.0002025 0.868 0.3856
HeartRate 0.0005990 0.0008375 0.715 0.4745
DizzinessYes 0.0940909 0.0638457 1.474 0.1406
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 2.861 on 9568 degrees of freedom
Multiple R-squared: 0.001114, Adjusted R-squared: 0.0001746
F-statistic: 1.186 on 9 and 9568 DF, p-value: 0.299
Optimize model
R-squared value indicates the perfection and accuracy of the predictive values.If R-square is closer to 1.0,then the linear model is best suited. In context to our Training data set model R-square is 0.001114 which is very low,therefore the trained data set model is not accurate for predication.
On the other hand,the coefficients of the covariates are not statistically significant because there p-value is above 0.05.
Model validation
predic<-predict(Model,Test_dataset)
predic 1 2 3 4 5 6 7 8
5.608667 5.567660 5.546457 5.562770 5.516937 5.508822 5.674886 5.518631
9 10 11 12 13 14 15 16
5.523803 5.647284 5.597838 5.476738 5.530308 5.685527 5.374573 5.495984
17 18 19 20 21 22 23 24
5.560071 5.591872 5.420765 5.644663 5.610245 5.510620 5.364314 5.497779
25 26 27 28 29 30 31 32
5.625910 5.420671 5.627937 5.561136 5.512245 5.445776 5.394218 5.401787
33 34 35 36 37 38 39 40
5.445967 5.598570 5.498213 5.504291 5.449153 5.577370 5.671011 5.619132
41 42 43 44 45 46 47 48
5.364889 5.548936 5.423444 5.418655 5.534596 5.488988 5.561701 5.408094
49 50 51 52 53 54 55 56
5.633099 5.487312 5.718591 5.649456 5.572739 5.787775 5.524046 5.483049
57 58 59 60 61 62 63 64
5.833325 5.544461 5.440369 5.479079 5.525832 5.599989 5.622811 5.558398
65 66 67 68 69 70 71 72
5.532715 5.427332 5.466073 5.678108 5.484759 5.528338 5.543118 5.630059
73 74 75 76 77 78 79 80
5.521192 5.468610 5.625953 5.625652 5.460793 5.383369 5.446189 5.445489
81 82 83 84 85 86 87 88
5.369855 5.439171 5.419178 5.667864 5.494138 5.675848 5.345673 5.687815
89 90 91 92 93 94 95 96
5.464021 5.350775 5.572993 5.565025 5.441024 5.512733 5.593105 5.647842
97 98 99 100 101 102 103 104
5.566569 5.507648 5.465332 5.401545 5.422617 5.568675 5.514203 5.542323
105 106 107 108 109 110 111 112
5.666243 5.422766 5.406366 5.482165 5.487784 5.621071 5.606741 5.570371
113 114 115 116 117 118 119 120
5.551435 5.546564 5.465160 5.708958 5.619910 5.570375 5.573637 5.482173
121 122 123 124 125 126 127 128
5.407691 5.472653 5.432598 5.642668 5.503309 5.511448 5.463648 5.364624
129 130 131 132 133 134 135 136
5.498958 5.382536 5.467698 5.355663 5.505545 5.608299 5.473808 5.447884
137 138 139 140 141 142 143 144
5.414504 5.542786 5.477722 5.512949 5.548688 5.294102 5.414236 5.519177
145 146 147 148 149 150 151 152
5.587118 5.595521 5.568640 5.667606 5.463231 5.550322 5.545329 5.422551
153 154 155 156 157 158 159 160
5.484655 5.585264 5.530023 5.618198 5.579033 5.658970 5.551374 5.468134
161 162 163 164 165 166 167 168
5.526082 5.588311 5.541651 5.615996 5.458960 5.433535 5.535755 5.481654
169 170 171 172 173 174 175 176
5.467551 5.507081 5.484571 5.587442 5.474663 5.468228 5.507692 5.642981
177 178 179 180 181 182 183 184
5.556454 5.484727 5.459842 5.609093 5.392981 5.474370 5.446799 5.535891
185 186 187 188 189 190 191 192
5.506831 5.518861 5.561186 5.572468 5.553001 5.608288 5.469347 5.416177
193 194 195 196 197 198 199 200
5.456104 5.466009 5.406865 5.562219 5.479420 5.386632 5.452986 5.321307
201 202 203 204 205 206 207 208
5.462555 5.427039 5.777664 5.369577 5.543244 5.391134 5.554747 5.493760
209 210 211 212 213 214 215 216
5.644009 5.561400 5.505871 5.505759 5.524462 5.650333 5.460192 5.563588
217 218 219 220 221 222 223 224
5.489397 5.456569 5.601375 5.441069 5.610550 5.421031 5.647285 5.388176
225 226 227 228 229 230 231 232
5.497620 5.662622 5.580849 5.374018 5.398054 5.546818 5.375333 5.495521
233 234 235 236 237 238 239 240
5.532806 5.505553 5.411864 5.586629 5.578177 5.398979 5.662542 5.575572
241 242 243 244 245 246 247 248
5.473378 5.598164 5.403611 5.439699 5.441731 5.338676 5.366845 5.553137
249 250 251 252 253 254 255 256
5.443864 5.585983 5.505163 5.356363 5.363934 5.577391 5.579434 5.429930
257 258 259 260 261 262 263 264
5.607494 5.603273 5.484578 5.502091 5.561167 5.303735 5.522813 5.470994
265 266 267 268 269 270 271 272
5.536106 5.700914 5.468317 5.536463 5.504370 5.530814 5.577852 5.668059
273 274 275 276 277 278 279 280
5.501666 5.468778 5.541621 5.546462 5.470321 5.571195 5.462448 5.646525
281 282 283 284 285 286 287 288
5.608290 5.450091 5.332577 5.603905 5.395602 5.461600 5.580169 5.545036
289 290 291 292 293 294 295 296
5.355842 5.402938 5.497199 5.652671 5.559339 5.468491 5.532304 5.568437
297 298 299 300 301 302 303 304
5.537652 5.541019 5.502366 5.437827 5.519609 5.346536 5.359069 5.392076
305 306 307 308 309 310 311 312
5.441527 5.368214 5.479331 5.456029 5.454168 5.540708 5.434604 5.497633
313 314 315 316 317 318 319 320
5.534285 5.550883 5.505349 5.397604 5.428093 5.574440 5.430918 5.417104
321 322 323 324 325 326 327 328
5.552491 5.342495 5.380011 5.632704 5.529644 5.464982 5.285107 5.569681
329 330 331 332 333 334 335 336
5.590446 5.569885 5.592989 5.475691 5.528295 5.370299 5.359700 5.568331
337 338 339 340 341 342 343 344
5.511110 5.481101 5.600223 5.439261 5.542913 5.448360 5.358513 5.550042
345 346 347 348 349 350 351 352
5.381535 5.620830 5.646375 5.444046 5.489315 5.441158 5.433062 5.531783
353 354 355 356 357 358 359 360
5.515204 5.581898 5.471024 5.581052 5.472994 5.552724 5.487227 5.483329
361 362 363 364 365 366 367 368
5.466403 5.317912 5.527091 5.352773 5.418716 5.564067 5.435127 5.483160
369 370 371 372 373 374 375 376
5.392475 5.487267 5.358834 5.525920 5.526611 5.435641 5.639797 5.365775
377 378 379 380 381 382 383 384
5.644335 5.520807 5.472288 5.471645 5.473445 5.441618 5.462301 5.589392
385 386 387 388 389 390 391 392
5.505246 5.477869 5.647210 5.492179 5.640807 5.413308 5.610200 5.512144
393 394 395 396 397 398 399 400
5.540790 5.546167 5.434235 5.475944 5.581310 5.441732 5.569173 5.460057
401 402 403 404 405 406 407 408
5.555114 5.437690 5.567652 5.432829 5.512064 5.413637 5.586697 5.330667
409 410 411 412 413 414 415 416
5.782127 5.655184 5.381779 5.478674 5.478216 5.734186 5.496757 5.460673
417 418 419 420 421 422 423 424
5.565342 5.557095 5.556458 5.513652 5.451519 5.546423 5.604997 5.535341
425 426 427 428 429 430 431 432
5.610204 5.462369 5.359868 5.428182 5.621660 5.600655 5.493158 5.704207
433 434 435 436 437 438 439 440
5.465823 5.283180 5.461938 5.613586 5.445492 5.561014 5.330244 5.555329
441 442 443 444 445 446 447 448
5.613256 5.592248 5.446396 5.420850 5.414230 5.421998 5.471405 5.487711
449 450 451 452 453 454 455 456
5.704005 5.553372 5.398693 5.358945 5.544308 5.698700 5.483333 5.382534
457 458 459 460 461 462 463 464
5.551866 5.433372 5.536288 5.546260 5.476195 5.411173 5.442173 5.492446
465 466 467 468 469 470 471 472
5.353543 5.549579 5.563978 5.361965 5.573305 5.461101 5.426966 5.498020
473 474 475 476 477 478 479 480
5.656327 5.447653 5.362866 5.388954 5.488685 5.545852 5.492858 5.382015
481 482 483 484 485 486 487 488
5.465670 5.461713 5.467957 5.421595 5.615459 5.464954 5.421449 5.437118
489 490 491 492 493 494 495 496
5.485828 5.351639 5.430033 5.361469 5.379019 5.436290 5.611388 5.388536
497 498 499 500 501 502 503 504
5.500954 5.504722 5.478906 5.552935 5.563341 5.569541 5.338792 5.391059
505 506 507 508 509 510 511 512
5.654733 5.622463 5.555703 5.378101 5.367360 5.650044 5.398690 5.360743
513 514 515 516 517 518 519 520
5.467585 5.408297 5.541386 5.467083 5.384656 5.606600 5.450004 5.446238
521 522 523 524 525 526 527 528
5.461124 5.588814 5.413080 5.505667 5.486053 5.372424 5.511890 5.526535
529 530 531 532 533 534 535 536
5.538300 5.447578 5.409166 5.526491 5.430633 5.369109 5.433335 5.603903
537 538 539 540 541 542 543 544
5.572155 5.523884 5.559118 5.426891 5.531628 5.417020 5.462561 5.429509
545 546 547 548 549 550 551 552
5.585118 5.712634 5.481986 5.430967 5.478587 5.547790 5.431314 5.593271
553 554 555 556 557 558 559 560
5.677358 5.434702 5.595788 5.529800 5.559522 5.557033 5.637159 5.479891
561 562 563 564 565 566 567 568
5.446148 5.441914 5.404423 5.546929 5.551625 5.507364 5.412217 5.552551
569 570 571 572 573 574 575 576
5.410011 5.409610 5.633001 5.414717 5.515397 5.309281 5.642802 5.610574
577 578 579 580 581 582 583 584
5.370563 5.669118 5.626833 5.496004 5.572565 5.398851 5.457107 5.515568
585 586 587 588 589 590 591 592
5.537527 5.544068 5.447965 5.560433 5.477281 5.600472 5.525655 5.483990
593 594 595 596 597 598 599 600
5.516003 5.381252 5.591410 5.533952 5.570724 5.486366 5.515707 5.376056
601 602 603 604 605 606 607 608
5.701828 5.425443 5.389757 5.538182 5.511976 5.429197 5.524883 5.466559
609 610 611 612 613 614 615 616
5.505710 5.605507 5.426866 5.488367 5.426589 5.493231 5.440793 5.482063
617 618 619 620 621 622 623 624
5.501710 5.454808 5.581223 5.421610 5.641916 5.470280 5.508393 5.510183
625 626 627 628 629 630 631 632
5.631706 5.633825 5.290569 5.411847 5.542510 5.546403 5.385177 5.554033
633 634 635 636 637 638 639 640
5.465647 5.563080 5.369834 5.589412 5.593070 5.400853 5.700635 5.375986
641 642 643 644 645 646 647 648
5.536799 5.616702 5.462666 5.525260 5.449471 5.527075 5.840950 5.479207
649 650 651 652 653 654 655 656
5.450302 5.539720 5.531600 5.475207 5.535152 5.453463 5.422270 5.465828
657 658 659 660 661 662 663 664
5.564460 5.534109 5.384732 5.508543 5.360027 5.464001 5.422132 5.451196
665 666 667 668 669 670 671 672
5.455238 5.376834 5.471704 5.578258 5.418060 5.520724 5.397895 5.405504
673 674 675 676 677 678 679 680
5.523957 5.504885 5.354766 5.319179 5.508028 5.634172 5.346124 5.439580
681 682 683 684 685 686 687 688
5.566260 5.434729 5.679168 5.398274 5.389868 5.690191 5.314628 5.474858
689 690 691 692 693 694 695 696
5.434575 5.422192 5.331408 5.473123 5.431476 5.619445 5.461407 5.526440
697 698 699 700 701 702 703 704
5.521629 5.572190 5.542095 5.542683 5.653962 5.499926 5.483097 5.504782
705 706 707 708 709 710 711 712
5.352134 5.440416 5.387901 5.518698 5.539767 5.715572 5.424183 5.426100
713 714 715 716 717 718 719 720
5.538166 5.592524 5.404432 5.519967 5.459677 5.621928 5.549270 5.599766
721 722 723 724 725 726 727 728
5.459258 5.457800 5.624532 5.513532 5.377635 5.503015 5.687815 5.555997
729 730 731 732 733 734 735 736
5.312091 5.699225 5.585490 5.603357 5.470418 5.348428 5.602068 5.394018
737 738 739 740 741 742 743 744
5.496090 5.376476 5.371106 5.544661 5.581506 5.448460 5.467528 5.679594
745 746 747 748 749 750 751 752
5.544001 5.430752 5.380344 5.540295 5.518843 5.569407 5.645654 5.497678
753 754 755 756 757 758 759 760
5.596353 5.594979 5.400149 5.554979 5.376834 5.466968 5.456661 5.575777
761 762 763 764 765 766 767 768
5.503163 5.295978 5.453957 5.429756 5.472539 5.546680 5.670231 5.476722
769 770 771 772 773 774 775 776
5.446431 5.416093 5.554903 5.431528 5.510070 5.495201 5.480100 5.389102
777 778 779 780 781 782 783 784
5.484829 5.389518 5.870446 5.464220 5.542125 5.636038 5.327508 5.642519
785 786 787 788 789 790 791 792
5.787449 5.417618 5.467927 5.555267 5.492223 5.443565 5.454126 5.618103
793 794 795 796 797 798 799 800
5.708573 5.347148 5.642713 5.590827 5.583819 5.852208 5.598270 5.496502
801 802 803 804 805 806 807 808
5.436726 5.747849 5.412035 5.450321 5.502645 5.453220 5.397826 5.551833
809 810 811 812 813 814 815 816
5.532300 5.348198 5.608438 5.472352 5.516603 5.475898 5.452556 5.588580
817 818 819 820 821 822 823 824
5.445953 5.505214 5.401485 5.578966 5.693572 5.510185 5.458532 5.521363
825 826 827 828 829 830 831 832
5.606827 5.426914 5.507017 5.548051 5.498577 5.459189 5.354811 5.475382
833 834 835 836 837 838 839 840
5.511826 5.475099 5.517649 5.559130 5.613506 5.434006 5.456936 5.572789
841 842 843 844 845 846 847 848
5.487940 5.574947 5.569484 5.396092 5.451933 5.623084 5.452040 5.492079
849 850 851 852 853 854 855 856
5.680249 5.485720 5.367226 5.531261 5.467806 5.656710 5.468104 5.437095
857 858 859 860 861 862 863 864
5.439025 5.595740 5.505838 5.436945 5.511333 5.535720 5.569750 5.762156
865 866 867 868 869 870 871 872
5.509685 5.490642 5.523413 5.471344 5.411420 5.476334 5.383082 5.457288
873 874 875 876 877 878 879 880
5.548142 5.472085 5.497299 5.362777 5.434558 5.539651 5.497198 5.438223
881 882 883 884 885 886 887 888
5.496765 5.688073 5.333837 5.463551 5.902287 5.294836 5.618804 5.475611
889 890 891 892 893 894 895 896
5.560708 5.598227 5.626058 5.521959 5.625717 5.530375 5.494451 5.792197
897 898 899 900 901 902 903 904
5.523565 5.565598 5.417646 5.473432 5.408333 5.423789 5.536226 5.682601
905 906 907 908 909 910 911 912
5.511731 5.579685 5.525271 5.550097 5.447105 5.481051 5.452688 5.521469
913 914 915 916 917 918 919 920
5.585084 5.514416 5.461663 5.622411 5.507720 5.455341 5.465984 5.550447
921 922 923 924 925 926 927 928
5.606632 5.471070 5.606052 5.570642 5.454889 5.430584 5.615102 5.541591
929 930 931 932 933 934 935 936
5.580690 5.414620 5.312530 5.591448 5.442860 5.630052 5.448153 5.433997
937 938 939 940 941 942 943 944
5.581868 5.554792 5.332985 5.373339 5.391008 5.516763 5.557812 5.624108
945 946 947 948 949 950 951 952
5.465170 5.524501 5.423886 5.436611 5.596154 5.531829 5.498371 5.492924
953 954 955 956 957 958 959 960
5.347177 5.504325 5.631963 5.543109 5.410188 5.546587 5.553477 5.427386
961 962 963 964 965 966 967 968
5.665223 5.431121 5.457287 5.765834 5.632173 5.517704 5.590168 5.443487
969 970 971 972 973 974 975 976
5.354909 5.520385 5.617380 5.501405 5.485190 5.489233 5.629588 5.484518
977 978 979 980 981 982 983 984
5.396371 5.481452 5.337273 5.648209 5.375824 5.347134 5.469736 5.426028
985 986 987 988 989 990 991 992
5.328871 5.455688 5.473609 5.588403 5.614803 5.511403 5.407177 5.619251
993 994 995 996 997 998 999 1000
5.448738 5.508628 5.399087 5.555937 5.634087 5.510487 5.768266 5.749919
1001 1002 1003 1004 1005 1006 1007 1008
5.348537 5.381246 5.449438 5.426552 5.620357 5.634718 5.295622 5.563845
1009 1010 1011 1012 1013 1014 1015 1016
5.548745 5.669448 5.569720 5.633811 5.607706 5.654699 5.532569 5.500254
1017 1018 1019 1020 1021 1022 1023 1024
5.469145 5.534891 5.597642 5.611159 5.823954 5.531009 5.486536 5.636311
1025 1026 1027 1028 1029 1030 1031 1032
5.393809 5.474558 5.607496 5.499249 5.595855 5.572326 5.643718 5.522265
1033 1034 1035 1036 1037 1038 1039 1040
5.409606 5.507035 5.608736 5.430268 5.535496 5.484588 5.538149 5.415679
1041 1042 1043 1044 1045 1046 1047 1048
5.518940 5.704041 5.580791 5.653541 5.402621 5.333989 5.486816 5.460035
1049 1050 1051 1052 1053 1054 1055 1056
5.534092 5.491447 5.417143 5.486992 5.725663 5.541049 5.626454 5.458756
1057 1058 1059 1060 1061 1062 1063 1064
5.485872 5.587676 5.542062 5.506193 5.495568 5.419821 5.342538 5.559342
1065 1066 1067 1068 1069 1070 1071 1072
5.400048 5.492764 5.715775 5.411798 5.443562 5.575182 5.403321 5.439110
1073 1074 1075 1076 1077 1078 1079 1080
5.628729 5.575303 5.513984 5.444867 5.472142 5.522870 5.450822 5.525760
1081 1082 1083 1084 1085 1086 1087 1088
5.644924 5.437989 5.359467 5.522881 5.726319 5.380099 5.535146 5.461663
1089 1090 1091 1092 1093 1094 1095 1096
5.452952 5.481020 5.519308 5.589865 5.500359 5.639685 5.547345 5.520370
1097 1098 1099 1100 1101 1102 1103 1104
5.572152 5.467393 5.398354 5.728184 5.624594 5.533000 5.561445 5.619387
1105 1106 1107 1108 1109 1110 1111 1112
5.319865 5.296596 5.429408 5.513627 5.542534 5.470546 5.572507 5.550928
1113 1114 1115 1116 1117 1118 1119 1120
5.590103 5.543470 5.517712 5.545206 5.444308 5.454132 5.690574 5.584527
1121 1122 1123 1124 1125 1126 1127 1128
5.676603 5.435543 5.448207 5.488629 5.442223 5.382852 5.422223 5.493547
1129 1130 1131 1132 1133 1134 1135 1136
5.330401 5.443034 5.713248 5.531347 5.633103 5.468422 5.647227 5.512218
1137 1138 1139 1140 1141 1142 1143 1144
5.406790 5.424435 5.477026 5.675948 5.541237 5.564065 5.441092 5.529721
1145 1146 1147 1148 1149 1150 1151 1152
5.416351 5.588544 5.296492 5.609741 5.443600 5.521784 5.414645 5.617000
1153 1154 1155 1156 1157 1158 1159 1160
5.451909 5.445218 5.463078 5.549167 5.569640 5.328800 5.321895 5.532436
1161 1162 1163 1164 1165 1166 1167 1168
5.544056 5.530876 5.345908 5.403359 5.410530 5.408845 5.613148 5.439818
1169 1170 1171 1172 1173 1174 1175 1176
5.405407 5.604529 5.755539 5.477894 5.478638 5.412771 5.402970 5.455730
1177 1178 1179 1180 1181 1182 1183 1184
5.490070 5.565481 5.530715 5.558035 5.818908 5.688307 5.471722 5.541132
1185 1186 1187 1188 1189 1190 1191 1192
5.564270 5.555449 5.324069 5.467378 5.468080 5.301024 5.757983 5.503301
1193 1194 1195 1196 1197 1198 1199 1200
5.416956 5.552832 5.508869 5.354975 5.474797 5.575304 5.535963 5.500309
1201 1202 1203 1204 1205 1206 1207 1208
5.470634 5.588785 5.423901 5.646753 5.411976 5.389991 5.487602 5.560368
1209 1210 1211 1212 1213 1214 1215 1216
5.464994 5.466463 5.647240 5.362712 5.665291 5.634570 5.525600 5.758197
1217 1218 1219 1220 1221 1222 1223 1224
5.598454 5.425610 5.619056 5.493334 5.427669 5.639046 5.584863 5.610753
1225 1226 1227 1228 1229 1230 1231 1232
5.364348 5.541008 5.533285 5.444877 5.436582 5.609036 5.467070 5.563510
1233 1234 1235 1236 1237 1238 1239 1240
5.571558 5.531549 5.502316 5.380927 5.687828 5.651223 5.482727 5.453442
1241 1242 1243 1244 1245 1246 1247 1248
5.473287 5.411778 5.487343 5.453317 5.448027 5.562089 5.533644 5.438440
1249 1250 1251 1252 1253 1254 1255 1256
5.404232 5.388516 5.447363 5.550978 5.449183 5.449079 5.269945 5.399990
1257 1258 1259 1260 1261 1262 1263 1264
5.375618 5.527386 5.488513 5.388705 5.428897 5.428773 5.524358 5.697497
1265 1266 1267 1268 1269 1270 1271 1272
5.507475 5.512189 5.559281 5.590957 5.394832 5.599012 5.534732 5.470318
1273 1274 1275 1276 1277 1278 1279 1280
5.354575 5.460423 5.435649 5.414497 5.587809 5.548506 5.474478 5.626160
1281 1282 1283 1284 1285 1286 1287 1288
5.505376 5.418613 5.415339 5.452339 5.679625 5.584905 5.397308 5.563105
1289 1290 1291 1292 1293 1294 1295 1296
5.570663 5.467038 5.543252 5.407516 5.550708 5.508749 5.335368 5.375859
1297 1298 1299 1300 1301 1302 1303 1304
5.410744 5.515453 5.547918 5.428478 5.397459 5.391403 5.548654 5.498156
1305 1306 1307 1308 1309 1310 1311 1312
5.710090 5.575194 5.491577 5.572553 5.476791 5.477692 5.691882 5.508767
1313 1314 1315 1316 1317 1318 1319 1320
5.456612 5.369883 5.421336 5.541679 5.715607 5.440784 5.448671 5.453308
1321 1322 1323 1324 1325 1326 1327 1328
5.535241 5.484039 5.449408 5.596260 5.385025 5.608728 5.564902 5.385659
1329 1330 1331 1332 1333 1334 1335 1336
5.579918 5.353336 5.514858 5.705993 5.507689 5.453555 5.702102 5.564146
1337 1338 1339 1340 1341 1342 1343 1344
5.480211 5.596392 5.618840 5.589323 5.343654 5.447368 5.315119 5.501148
1345 1346 1347 1348 1349 1350 1351 1352
5.547039 5.343925 5.344731 5.514756 5.489349 5.593869 5.448284 5.360060
1353 1354 1355 1356 1357 1358 1359 1360
5.413188 5.480259 5.472164 5.608391 5.552277 5.497092 5.539784 5.438927
1361 1362 1363 1364 1365 1366 1367 1368
5.480428 5.410214 5.654844 5.547503 5.470038 5.502290 5.540956 5.552577
1369 1370 1371 1372 1373 1374 1375 1376
5.392898 5.489736 5.424400 5.650539 5.648651 5.469240 5.590691 5.550404
1377 1378 1379 1380 1381 1382 1383 1384
5.498742 5.412734 5.429729 5.503912 5.410788 5.528159 5.444029 5.358027
1385 1386 1387 1388 1389 1390 1391 1392
5.537840 5.480377 5.698079 5.506510 5.511667 5.535605 5.421956 5.497982
1393 1394 1395 1396 1397 1398 1399 1400
5.520992 5.577795 5.607782 5.568243 5.438971 5.661669 5.613487 5.539220
1401 1402 1403 1404 1405 1406 1407 1408
5.498278 5.596766 5.724895 5.463742 5.464366 5.471817 5.739080 5.497269
1409 1410 1411 1412 1413 1414 1415 1416
5.464075 5.552109 5.366974 5.596407 5.699051 5.581831 5.389074 5.479422
1417 1418 1419 1420 1421 1422 1423 1424
5.463781 5.414297 5.596894 5.511135 5.621594 5.392527 5.621697 5.506566
1425 1426 1427 1428 1429 1430 1431 1432
5.388910 5.540444 5.562726 5.390923 5.563994 5.547903 5.467259 5.359943
1433 1434 1435 1436 1437 1438 1439 1440
5.452128 5.550044 5.499962 5.515962 5.388762 5.633663 5.614255 5.434332
1441 1442 1443 1444 1445 1446 1447 1448
5.458321 5.569964 5.390502 5.500349 5.727496 5.430838 5.488626 5.536576
1449 1450 1451 1452 1453 1454 1455 1456
5.577132 5.543326 5.447128 5.567133 5.427641 5.647441 5.431912 5.412283
1457 1458 1459 1460 1461 1462 1463 1464
5.490542 5.591826 5.594911 5.596776 5.343699 5.422556 5.440707 5.644660
1465 1466 1467 1468 1469 1470 1471 1472
5.631287 5.542122 5.554522 5.436615 5.457258 5.541963 5.658620 5.536323
1473 1474 1475 1476 1477 1478 1479 1480
5.608339 5.396663 5.572150 5.619785 5.474669 5.356702 5.434385 5.396943
1481 1482 1483 1484 1485 1486 1487 1488
5.580774 5.495771 5.509599 5.419688 5.346655 5.449880 5.501169 5.445164
1489 1490 1491 1492 1493 1494 1495 1496
5.718510 5.456264 5.547815 5.347979 5.578103 5.554775 5.367940 5.574841
1497 1498 1499 1500 1501 1502 1503 1504
5.431594 5.436798 5.554417 5.556509 5.558343 5.440634 5.611635 5.425981
1505 1506 1507 1508 1509 1510 1511 1512
5.568694 5.553725 5.580491 5.572797 5.506475 5.519172 5.713867 5.663450
1513 1514 1515 1516 1517 1518 1519 1520
5.538951 5.483047 5.500919 5.550278 5.364724 5.405486 5.679903 5.586461
1521 1522 1523 1524 1525 1526 1527 1528
5.522001 5.514671 5.818541 5.508524 5.565734 5.452193 5.592979 5.509188
1529 1530 1531 1532 1533 1534 1535 1536
5.556907 5.454832 5.452951 5.609840 5.438484 5.588616 5.404525 5.378793
1537 1538 1539 1540 1541 1542 1543 1544
5.660127 5.343180 5.440579 5.530169 5.635101 5.507154 5.436479 5.494208
1545 1546 1547 1548 1549 1550 1551 1552
5.515738 5.575756 5.451243 5.476354 5.575793 5.416690 5.451406 5.545795
1553 1554 1555 1556 1557 1558 1559 1560
5.597742 5.364881 5.582190 5.578824 5.524423 5.541836 5.546566 5.598876
1561 1562 1563 1564 1565 1566 1567 1568
5.537494 5.557955 5.597524 5.532359 5.389989 5.448381 5.383045 5.563957
1569 1570 1571 1572 1573 1574 1575 1576
5.439054 5.546669 5.580140 5.363553 5.365470 5.681177 5.551283 5.477182
1577 1578 1579 1580 1581 1582 1583 1584
5.593151 5.550113 5.325025 5.374603 5.460589 5.500091 5.362018 5.551329
1585 1586 1587 1588 1589 1590 1591 1592
5.542940 5.409389 5.440507 5.519379 5.522340 5.519411 5.579994 5.408480
1593 1594 1595 1596 1597 1598 1599 1600
5.501748 5.569377 5.507997 5.381969 5.595309 5.347026 5.444100 5.567478
1601 1602 1603 1604 1605 1606 1607 1608
5.540813 5.556066 5.631884 5.591578 5.560948 5.387318 5.403806 5.495208
1609 1610 1611 1612 1613 1614 1615 1616
5.599858 5.638171 5.517038 5.525707 5.428099 5.492359 5.488949 5.517989
1617 1618 1619 1620 1621 1622 1623 1624
5.455557 5.568210 5.564818 5.516930 5.364930 5.572314 5.605014 5.536067
1625 1626 1627 1628 1629 1630 1631 1632
5.485532 5.467593 5.526860 5.614731 5.385915 5.450385 5.527610 5.458988
1633 1634 1635 1636 1637 1638 1639 1640
5.518833 5.600823 5.531731 5.313864 5.476549 5.565370 5.496486 5.506695
1641 1642 1643 1644 1645 1646 1647 1648
5.387007 5.462806 5.500105 5.609409 5.639253 5.467141 5.526360 5.656098
1649 1650 1651 1652 1653 1654 1655 1656
5.668134 5.506529 5.538242 5.407301 5.530160 5.539525 5.587524 5.316037
1657 1658 1659 1660 1661 1662 1663 1664
5.357630 5.527972 5.725762 5.458905 5.538052 5.606369 5.485551 5.510654
1665 1666 1667 1668 1669 1670 1671 1672
5.544568 5.465605 5.578065 5.386218 5.439525 5.524616 5.712680 5.492904
1673 1674 1675 1676 1677 1678 1679 1680
5.593134 5.580662 5.438211 5.510936 5.657860 5.505334 5.449062 5.407341
1681 1682 1683 1684 1685 1686 1687 1688
5.367155 5.424970 5.416020 5.556875 5.435874 5.668817 5.537292 5.358130
1689 1690 1691 1692 1693 1694 1695 1696
5.488743 5.687995 5.573568 5.594152 5.516539 5.490568 5.378995 5.325208
1697 1698 1699 1700 1701 1702 1703 1704
5.435984 5.439217 5.646011 5.632664 5.459576 5.566911 5.619436 5.627392
1705 1706 1707 1708 1709 1710 1711 1712
5.567240 5.456696 5.474683 5.520995 5.611800 5.563671 5.769686 5.609844
1713 1714 1715 1716 1717 1718 1719 1720
5.495096 5.470069 5.449632 5.524962 5.481858 5.408870 5.417617 5.619454
1721 1722 1723 1724 1725 1726 1727 1728
5.568144 5.426534 5.666517 5.525878 5.581377 5.522814 5.502720 5.508701
1729 1730 1731 1732 1733 1734 1735 1736
5.538617 5.506151 5.654896 5.402683 5.559841 5.381731 5.395395 5.659573
1737 1738 1739 1740 1741 1742 1743 1744
5.437786 5.613566 5.345701 5.530782 5.353154 5.643482 5.517651 5.457007
1745 1746 1747 1748 1749 1750 1751 1752
5.520379 5.461189 5.363218 5.368535 5.611968 5.481000 5.339177 5.519484
1753 1754 1755 1756 1757 1758 1759 1760
5.602394 5.414284 5.391030 5.491720 5.513186 5.429987 5.458139 5.576388
1761 1762 1763 1764 1765 1766 1767 1768
5.626753 5.526404 5.506101 5.552313 5.405522 5.503155 5.641565 5.468506
1769 1770 1771 1772 1773 1774 1775 1776
5.425034 5.507264 5.560686 5.570392 5.593380 5.614100 5.475397 5.658489
1777 1778 1779 1780 1781 1782 1783 1784
5.339332 5.474190 5.579446 5.562901 5.469743 5.356963 5.554594 5.483523
1785 1786 1787 1788 1789 1790 1791 1792
5.492552 5.582425 5.463837 5.478232 5.848182 5.432412 5.584322 5.373892
1793 1794 1795 1796 1797 1798 1799 1800
5.500186 5.694287 5.477851 5.625769 5.491819 5.554556 5.536354 5.537446
1801 1802 1803 1804 1805 1806 1807 1808
5.390814 5.556841 5.628615 5.496660 5.484099 5.409361 5.608179 5.544962
1809 1810 1811 1812 1813 1814 1815 1816
5.630071 5.517016 5.561880 5.461858 5.413213 5.539036 5.504100 5.418598
1817 1818 1819 1820 1821 1822 1823 1824
5.403153 5.413476 5.525558 5.336028 5.534272 5.426179 5.404965 5.492088
1825 1826 1827 1828 1829 1830 1831 1832
5.566054 5.370963 5.513934 5.573955 5.672869 5.396501 5.439630 5.591336
1833 1834 1835 1836 1837 1838 1839 1840
5.532003 5.468988 5.380770 5.502984 5.463527 5.411831 5.493732 5.534467
1841 1842 1843 1844 1845 1846 1847 1848
5.530726 5.446366 5.517352 5.632514 5.458638 5.455190 5.486947 5.504354
1849 1850 1851 1852 1853 1854 1855 1856
5.544835 5.358152 5.507380 5.515664 5.366625 5.659160 5.322790 5.493538
1857 1858 1859 1860 1861 1862 1863 1864
5.361708 5.406431 5.489873 5.373948 5.628273 5.544194 5.385358 5.591899
1865 1866 1867 1868 1869 1870 1871 1872
5.514576 5.616978 5.450833 5.477503 5.579950 5.439104 5.883458 5.363086
1873 1874 1875 1876 1877 1878 1879 1880
5.389378 5.431360 5.442830 5.541550 5.490319 5.401353 5.410767 5.487949
1881 1882 1883 1884 1885 1886 1887 1888
5.486280 5.502682 5.451976 5.600853 5.300039 5.558540 5.507572 5.501227
1889 1890 1891 1892 1893 1894 1895 1896
5.470106 5.710133 5.490198 5.401135 5.447024 5.402171 5.523381 5.483799
1897 1898 1899 1900 1901 1902 1903 1904
5.457890 5.487586 5.487374 5.640377 5.473893 5.472819 5.449995 5.376668
1905 1906 1907 1908 1909 1910 1911 1912
5.523337 5.270687 5.586838 5.547334 5.442887 5.652580 5.354217 5.329296
1913 1914 1915 1916 1917 1918 1919 1920
5.351904 5.534150 5.610758 5.507621 5.487083 5.505129 5.475171 5.333495
1921 1922 1923 1924 1925 1926 1927 1928
5.485343 5.556259 5.586761 5.744202 5.577504 5.449744 5.489975 5.559149
1929 1930 1931 1932 1933 1934 1935 1936
5.468685 5.412251 5.455896 5.470912 5.600890 5.674600 5.586394 5.533826
1937 1938 1939 1940 1941 1942 1943 1944
5.434070 5.469440 5.446207 5.468951 5.724469 5.342969 5.578684 5.451588
1945 1946 1947 1948 1949 1950 1951 1952
5.516177 5.324112 5.523128 5.648062 5.556588 5.442436 5.554096 5.674939
1953 1954 1955 1956 1957 1958 1959 1960
5.579211 5.469075 5.448378 5.448457 5.825683 5.481194 5.487446 5.579246
1961 1962 1963 1964 1965 1966 1967 1968
5.537658 5.461970 5.507949 5.522529 5.427589 5.462919 5.595882 5.486064
1969 1970 1971 1972 1973 1974 1975 1976
5.612222 5.386173 5.578178 5.459163 5.282611 5.587370 5.422495 5.426448
1977 1978 1979 1980 1981 1982 1983 1984
5.433253 5.506128 5.444695 5.460399 5.599220 5.474569 5.546811 5.661007
1985 1986 1987 1988 1989 1990 1991 1992
5.512127 5.436284 5.569110 5.525495 5.528601 5.561027 5.303885 5.315000
1993 1994 1995 1996 1997 1998 1999 2000
5.398604 5.625033 5.595360 5.781946 5.548164 5.419101 5.410601 5.534168
2001 2002 2003 2004 2005 2006 2007 2008
5.441641 5.461710 5.577042 5.376131 5.461070 5.519164 5.486712 5.605238
2009 2010 2011 2012 2013 2014 2015 2016
5.484965 5.584446 5.456235 5.602059 5.529277 5.467533 5.504942 5.432292
2017 2018 2019 2020 2021 2022 2023 2024
5.606888 5.412889 5.531999 5.445246 5.466062 5.511600 5.663619 5.870392
2025 2026 2027 2028 2029 2030 2031 2032
5.457014 5.349670 5.509013 5.370886 5.464577 5.567535 5.450421 5.652630
2033 2034 2035 2036 2037 2038 2039 2040
5.464053 5.565365 5.557237 5.610757 5.561141 5.439209 5.477637 5.498663
2041 2042 2043 2044 2045 2046 2047 2048
5.598702 5.543318 5.531282 5.574988 5.614195 5.620474 5.464168 5.491257
2049 2050 2051 2052 2053 2054 2055 2056
5.453425 5.464462 5.277701 5.542778 5.518756 5.516824 5.465565 5.502295
2057 2058 2059 2060 2061 2062 2063 2064
5.516898 5.445648 5.634901 5.511507 5.582061 5.517978 5.474503 5.622949
2065 2066 2067 2068 2069 2070 2071 2072
5.403381 5.683929 5.570928 5.671351 5.484966 5.605138 5.467015 5.688608
2073 2074 2075 2076 2077 2078 2079 2080
5.511278 5.412621 5.527183 5.542387 5.429199 5.544516 5.550014 5.465273
2081 2082 2083 2084 2085 2086 2087 2088
5.722954 5.482504 5.548400 5.648938 5.499152 5.484634 5.655337 5.456369
2089 2090 2091 2092 2093 2094 2095 2096
5.517458 5.696089 5.454350 5.395988 5.441042 5.480456 5.404097 5.594628
2097 2098 2099 2100 2101 2102 2103 2104
5.521752 5.512659 5.597345 5.614409 5.481774 5.510912 5.620052 5.455369
2105 2106 2107 2108 2109 2110 2111 2112
5.454954 5.383443 5.513082 5.503968 5.527451 5.446340 5.454707 5.395450
2113 2114 2115 2116 2117 2118 2119 2120
5.565521 5.454352 5.603348 5.608637 5.419325 5.408609 5.523970 5.521303
2121 2122 2123 2124 2125 2126 2127 2128
5.420941 5.459756 5.621172 5.624023 5.424763 5.439903 5.449339 5.464274
2129 2130 2131 2132 2133 2134 2135 2136
5.486977 5.532941 5.488787 5.376778 5.456912 5.422050 5.631854 5.511041
2137 2138 2139 2140 2141 2142 2143 2144
5.579528 5.382651 5.534661 5.487936 5.432507 5.464723 5.714968 5.543644
2145 2146 2147 2148 2149 2150 2151 2152
5.485006 5.601286 5.385612 5.581517 5.331152 5.374947 5.410990 5.391642
2153 2154 2155 2156 2157 2158 2159 2160
5.387471 5.436707 5.440737 5.455107 5.528975 5.528113 5.611580 5.469791
2161 2162 2163 2164 2165 2166 2167 2168
5.496933 5.476162 5.440763 5.552308 5.525319 5.484776 5.548098 5.423217
2169 2170 2171 2172 2173 2174 2175 2176
5.770596 5.523637 5.581813 5.498792 5.641547 5.362448 5.594323 5.490349
2177 2178 2179 2180 2181 2182 2183 2184
5.393152 5.531024 5.441021 5.621985 5.616921 5.365012 5.390542 5.663981
2185 2186 2187 2188 2189 2190 2191 2192
5.524792 5.466177 5.461740 5.472164 5.589796 5.489217 5.485867 5.332476
2193 2194 2195 2196 2197 2198 2199 2200
5.446636 5.419348 5.412750 5.516799 5.432503 5.571749 5.482136 5.512765
2201 2202 2203 2204 2205 2206 2207 2208
5.559007 5.453654 5.299155 5.436959 5.514721 5.523286 5.513065 5.540293
2209 2210 2211 2212 2213 2214 2215 2216
5.580261 5.478119 5.515983 5.463121 5.501953 5.492175 5.587814 5.493761
2217 2218 2219 2220 2221 2222 2223 2224
5.442090 5.739490 5.518637 5.416398 5.569383 5.592653 5.501006 5.536233
2225 2226 2227 2228 2229 2230 2231 2232
5.486548 5.316391 5.556408 5.378196 5.470144 5.534987 5.348167 5.375580
2233 2234 2235 2236 2237 2238 2239 2240
5.634242 5.347041 5.384467 5.609153 5.589375 5.328701 5.623240 5.409990
2241 2242 2243 2244 2245 2246 2247 2248
5.362631 5.524259 5.616289 5.463672 5.497015 5.480187 5.485810 5.564999
2249 2250 2251 2252 2253 2254 2255 2256
5.731322 5.475308 5.600827 5.424780 5.548116 5.476117 5.621473 5.745415
2257 2258 2259 2260 2261 2262 2263 2264
5.544510 5.484186 5.508154 5.356096 5.393338 5.350294 5.455646 5.497413
2265 2266 2267 2268 2269 2270 2271 2272
5.487491 5.433331 5.562236 5.462207 5.470819 5.450871 5.544679 5.389508
2273 2274 2275 2276 2277 2278 2279 2280
5.622780 5.505572 5.559057 5.511696 5.526960 5.489114 5.547975 5.515810
2281 2282 2283 2284 2285 2286 2287 2288
5.411326 5.419000 5.537115 5.480474 5.700350 5.429732 5.421928 5.395043
2289 2290 2291 2292 2293 2294 2295 2296
5.317872 5.478817 5.527418 5.649854 5.418807 5.523449 5.528893 5.447327
2297 2298 2299 2300 2301 2302 2303 2304
5.621522 5.452508 5.442952 5.581458 5.392669 5.677206 5.432688 5.384225
2305 2306 2307 2308 2309 2310 2311 2312
5.554761 5.512884 5.510971 5.536243 5.539730 5.373045 5.441589 5.631631
2313 2314 2315 2316 2317 2318 2319 2320
5.513803 5.590377 5.495468 5.493335 5.380133 5.380825 5.469100 5.346095
2321 2322 2323 2324 2325 2326 2327 2328
5.505622 5.566194 5.513876 5.530787 5.774228 5.434768 5.632202 5.585158
2329 2330 2331 2332 2333 2334 2335 2336
5.452681 5.655894 5.475121 5.476012 5.591250 5.414961 5.523938 5.535144
2337 2338 2339 2340 2341 2342 2343 2344
5.524789 5.698688 5.733450 5.554264 5.605514 5.701599 5.431127 5.715768
2345 2346 2347 2348 2349 2350 2351 2352
5.473800 5.538669 5.431253 5.574424 5.713372 5.291478 5.584451 5.429196
2353 2354 2355 2356 2357 2358 2359 2360
5.514207 5.414482 5.479018 5.547402 5.423707 5.456622 5.515348 5.360135
2361 2362 2363 2364 2365 2366 2367 2368
5.403660 5.516220 5.458447 5.493064 5.643697 5.711875 5.618568 5.389432
2369 2370 2371 2372 2373 2374 2375 2376
5.620659 5.334539 5.369550 5.495699 5.515808 5.477686 5.644390 5.492850
2377 2378 2379 2380 2381 2382 2383 2384
5.401566 5.476895 5.539760 5.267932 5.423383 5.528186 5.578067 5.684839
2385 2386 2387 2388 2389 2390 2391 2392
5.553156 5.670706 5.529446 5.585241 5.637687 5.509103 5.639729 5.440606
2393 2394 2395 2396 2397 2398 2399 2400
5.538195 5.595222 5.472600 5.554063 5.491470 5.691637 5.556261 5.465062
2401 2402 2403 2404 2405 2406 2407 2408
5.587564 5.535273 5.553506 5.552117 5.504837 5.494494 5.526992 5.496100
2409 2410 2411 2412 2413 2414 2415 2416
5.364075 5.462573 5.618755 5.412223 5.581792 5.603194 5.435767 5.478930
2417 2418 2419 2420 2421 2422
5.651334 5.452128 5.537557 5.465770 5.437129 5.424375
Comparing values using plot
plot(Test_dataset$AnxietyAttack,type = "l",lty=1.8,col="blue")
lines(predic,type = "l",col="black")Classification Algorithm
#Clear r environment
rm(list=ls())
#Working directory
setwd("C:/Users/USER/Desktop/JOOUST")
#Load data set
library(readxl)
birth <- read_excel("birth.xlsx")Clean the data set
birth$smoke<-as.factor(birth$smoke)
birth$urineirritability<-as.factor(birth$urineirritability)
birth$Birth_Weight<-as.factor(birth$Birth_Weight)Divide data set
set.seed(2)
ind<-sample(2,nrow(birth),replace = T,prob = c(0.6,0.4))
Train_dataset<-birth[ind==1,]
Test_dataset<-birth[ind==2,]Exploratory data analysis
library(table1)
Attaching package: 'table1'
The following objects are masked from 'package:base':
units, units<-
table1(~smoke+urineirritability+`age(Yrs)`|Birth_Weight,data=birth,Total="Overall")| low weight (N=59) |
Normal Weight (N=130) |
Overall (N=189) |
|
|---|---|---|---|
| smoke | |||
| No | 29 (49.2%) | 86 (66.2%) | 115 (60.8%) |
| Yes | 30 (50.8%) | 44 (33.8%) | 74 (39.2%) |
| urineirritability | |||
| No | 45 (76.3%) | 116 (89.2%) | 161 (85.2%) |
| Yes | 14 (23.7%) | 14 (10.8%) | 28 (14.8%) |
| age(Yrs) | |||
| Mean (SD) | 22.3 (4.51) | 23.7 (5.58) | 23.2 (5.30) |
| Median [Min, Max] | 22.0 [14.0, 34.0] | 23.0 [14.0, 45.0] | 23.0 [14.0, 45.0] |
Implement Model
Model1<-glm(Birth_Weight~.,data =Train_dataset,family = "binomial" )
summary(Model1)
Call:
glm(formula = Birth_Weight ~ ., family = "binomial", data = Train_dataset)
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 0.44383 1.06418 0.417 0.6766
smokeYes -1.07550 0.42892 -2.507 0.0122 *
urineirritabilityYes -1.00561 0.54068 -1.860 0.0629 .
`age(Yrs)` 0.04552 0.04478 1.017 0.3093
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 141.34 on 114 degrees of freedom
Residual deviance: 130.80 on 111 degrees of freedom
AIC: 138.8
Number of Fisher Scoring iterations: 4
Model prediction
pred<-predict(Model1,Train_dataset,type = "response")
pred 1 2 3 4 5 6 7 8
0.5752186 0.5692548 0.3359758 0.8092838 0.6656398 0.6345895 0.7873107 0.7873107
9 10 11 12 13 14 15 16
0.6908171 0.5468033 0.6239698 0.5863022 0.6554325 0.7004551 0.8479366 0.6402204
17 18 19 20 21 22 23 24
0.8479366 0.5354999 0.8537140 0.7716659 0.7716659 0.6132297 0.8294785 0.6450798
25 26 27 28 29 30 31 32
0.7048761 0.7873107 0.8162114 0.8021583 0.7873107 0.8229425 0.8092838 0.8162114
33 34 35 36 37 38 39 40
0.7873107 0.8479366 0.5863022 0.8229425 0.6554325 0.5863022 0.8092838 0.5914251
41 42 43 44 45 46 47 48
0.6855892 0.6023782 0.7635456 0.5241598 0.8294785 0.5692548 0.8162114 0.8092838
49 50 51 52 53 54 55 56
0.8593083 0.7948341 0.8162114 0.8162114 0.8092838 0.8021583 0.5580587 0.3777328
57 58 59 60 61 62 63 64
0.5241598 0.8537140 0.8537140 0.5580587 0.5580587 0.8593083 0.8229425 0.5580587
65 66 67 68 69 70 71 72
0.7948341 0.8294785 0.8092838 0.5468033 0.7635456 0.8699600 0.6656398 0.7192036
73 74 75 76 77 78 79 80
0.8479366 0.7635456 0.7948341 0.8358214 0.8294785 0.8846456 0.5580587 0.9236088
81 82 83 84 85 86 87 88
0.4103280 0.7142572 0.6402204 0.6189921 0.8229425 0.5803805 0.6953184 0.3159758
89 90 91 92 93 94 95 96
0.7635456 0.6239698 0.6132297 0.8021583 0.5863022 0.8294785 0.7873107 0.6345895
97 98 99 100 101 102 103 104
0.2966344 0.3462068 0.6609138 0.3258966 0.7948341 0.5468033 0.8021583 0.6855892
105 106 107 108 109 110 111 112
0.7552282 0.5692548 0.6132297 0.8162114 0.5914251 0.5354999 0.7716659 0.7948341
113 114 115
0.6554325 0.6023782 0.5803805
Model classification
Performing model classification at 50 % the probability.
classify <- function(probability) ifelse(probability < 0.5, "Normal weight","Low weight")
Birthweight <- classify(predict(Model1, Train_dataset))Confusion matrix
After classify at threshold of 50/50 then we compare the predicted classification against the actual classification using the table() function.
The correct predictions are on the diagonal, and the off-diagonal values are where our model predicts incorrectly.
table(Train_dataset$Birth_Weight, Birthweight) Birthweight
Low weight Normal weight
low weight 19 16
Normal Weight 59 21
The first row where the data says that birth weight is low with the first column where the model predicts that the birth weight is also low, and the data agrees, is called the true positive. The element to the right of it, where the model says birth weight is low but the data says it is not, is called the false positives and this is Type 1 error. On the other hand, the second row where the data says that birth weight is low while on the first column where the model predict that birth weight is normal is called False negative which is a type II error. Lastly, the second row where data says that birth weight is normal while on the second column where the model also predict that birth weight is normal is the True negative. The aim is to predict birth low weight.
table(Train_dataset$Birth_Weight, Birthweight,
dnn=c("Data", "Predictions")) Predictions
Data Low weight Normal weight
low weight 19 16
Normal Weight 59 21
Model Accuracy
It measures how many classes it gets right out of the total, so it is the diagonal values of the confusion matrix divided by the total.
confusion_matrix <- table(Train_dataset$Birth_Weight, Birthweight,
dnn=c("Data", "Predictions"))
(accuracy <- sum(diag(confusion_matrix))/sum(confusion_matrix))[1] 0.3478261