Вы находитесь на странице: 1из 5

R version 3.4.

4 (2018-03-15) -- "Someone to Lean On"


Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: i386-w64-mingw32/i386 (32-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.


You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

Natural language support but running in an English locale

R is a collaborative project with many contributors.


Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or


'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[Previously saved workspace restored]

> d<-
data.frame(y=sample(0:4,100,repl=T),grades=rnorm(100,6.8,.7),noexp=rnorm(100,6.5,8)
,indexp=sample(1:4,100,repl=T))
> str(d)
'data.frame': 100 obs. of 4 variables:
$ y : int 0 1 4 0 4 4 3 0 4 0 ...
$ grades: num 6.55 7.51 7.77 6.75 8.11 ...
$ noexp : num 9.537 2.933 17.341 -1.503 -0.325 ...
$ indexp: int 3 4 3 1 2 2 1 4 1 1 ...
> glm(y~.,data=d,family="poisson")->ft
> summary(ft)

Call:
glm(formula = y ~ ., family = "poisson", data = d)

Deviance Residuals:
Min 1Q Median 3Q Max
-2.17916 -0.94754 0.05731 0.79481 1.44562

C
Estimate Std. Error z value Pr(>|z|)
(Intercept) -0.131601 0.707279 -0.186 0.852
grades 0.141620 0.102116 1.387 0.165
noexp -0.007932 0.008827 -0.899 0.369
indexp -0.024847 0.062711 -0.396 0.692

(Dispersion parameter for poisson family taken to be 1)

Null deviance: 146.25 on 99 degrees of freedom


Residual deviance: 143.64 on 96 degrees of freedom
AIC: 366.47

Number of Fisher Scoring iterations: 5

> predict(ft,d[1:5,1])
Error in eval(predvars, data, env) :
numeric 'envir' arg not of length one
> predict(ft,d[1:5,])
1 2 3 4 5
0.6455989 0.8095070 0.7571158 0.8111021 0.9703533
> predict(ft,d)
1 2 3 4 5 6 7 8
9 10 11 12 13 14 15 16
0.6455989 0.8095070 0.7571158 0.8111021 0.9703533 0.6326766 0.5674705 0.6630210
0.6006053 0.8620827 0.6922021 0.5451010 0.6835160 0.7664673 0.6375554 0.6518951
17 18 19 20 21 22 23 24
25 26 27 28 29 30 31 32
0.8032829 0.6231338 0.6415757 0.7821835 0.6876380 0.7446114 0.6288615 0.7244730
0.4959428 0.7517173 0.9874529 0.6605227 0.6181330 0.7798367 0.6293145 0.6556393
33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48
0.5506395 0.8163469 0.8040221 0.6317263 0.6520766 0.6251349 0.7526075 0.7547991
0.6154654 0.7359564 0.8109337 0.7309496 0.7713180 0.7273366 0.8818711 0.6619023
49 50 51 52 53 54 55 56
57 58 59 60 61 62 63 64
0.6085953 0.7189427 0.6975061 0.5952539 0.6133200 0.7321620 0.7451495 0.5855436
0.8763970 0.6526252 0.8044276 0.9945859 0.9929122 0.6017345 0.5471325 0.7928521
65 66 67 68 69 70 71 72
73 74 75 76 77 78 79 80
0.8462827 0.6025074 0.8131178 0.8647350 0.7026335 0.5565486 0.7368269 0.5648751
0.6815276 0.6573066 0.6861044 0.7340783 0.6488763 0.7609756 0.9677001 0.7283167
81 82 83 84 85 86 87 88
89 90 91 92 93 94 95 96
0.7648074 0.5790664 0.8255984 0.7942593 0.6142892 0.6092292 0.7539577 0.7224386
0.8917420 0.7108286 0.6304925 0.6668956 0.6244174 0.6109618 0.7802030 0.6940811
97 98 99 100
0.5230105 0.6624553 0.4348199 0.6281428
> exp(.2905)
[1] 1.337096
> predict(ft,d[1:5,])
1 2 3 4 5
0.6455989 0.8095070 0.7571158 0.8111021 0.9703533
> predict(ft,d[1:5,]),type="resp"
Error: unexpected ',' in "predict(ft,d[1:5,]),"
> predict(ft,d[1:5,]),type="resp")
Error: unexpected ',' in "predict(ft,d[1:5,]),"
> predict(ft,d[1:5,],type="resp")
1 2 3 4 5
1.907129 2.246800 2.132118 2.250387 2.638877
> exp(predict(ft,d[1:5,]))
1 2 3 4 5
1.907129 2.246800 2.132118 2.250387 2.638877
> exp(-2.53206)
[1] 0.07949509
> utils:::menuInstallPkgs()
--- Please select a CRAN mirror for use in this session ---
trying URL 'https://cloud.r-project.org/bin/windows/contrib/3.4/cluster_2.0.7-
1.zip'
Content type 'application/zip' length 577797 bytes (564 KB)
downloaded 564 KB

package �cluster� successfully unpacked and MD5 sums checked

The downloaded binary packages are in


C:\Users\153608\AppData\Local\Temp\RtmpoJAKQu\downloaded_packages
> utils:::menuInstallPkgs()
trying URL 'https://cloud.r-project.org/bin/windows/contrib/3.4/rpart_4.1-13.zip'
Content type 'application/zip' length 950406 bytes (928 KB)
downloaded 928 KB

trying URL 'https://cloud.r-


project.org/bin/windows/contrib/3.4/rpart.plot_2.1.2.zip'
Content type 'application/zip' length 719035 bytes (702 KB)
downloaded 702 KB

package �rpart� successfully unpacked and MD5 sums checked


package �rpart.plot� successfully unpacked and MD5 sums checked

The downloaded binary packages are in


C:\Users\153608\AppData\Local\Temp\RtmpoJAKQu\downloaded_packages
> utils:::menuInstallPkgs()
trying URL 'https://cloud.r-project.org/bin/windows/contrib/3.4/randomForest_4.6-
14.zip'
Content type 'application/zip' length 180828 bytes (176 KB)
downloaded 176 KB

package �randomForest� successfully unpacked and MD5 sums checked

The downloaded binary packages are in


C:\Users\153608\AppData\Local\Temp\RtmpoJAKQu\downloaded_packages
> d<-data.csv("G:/bank.csv",header=T)
Error in data.csv("G:/bank.csv", header = T) :
could not find function "data.csv"
> d<-data.frame(x1=rnorm(1000).x2=runif(1000,30,90),x3=rnorm(1000,4500,120))
Error: unexpected symbol in "d<-data.frame(x1=rnorm(1000).x2"
> d<-data.frame(x1=rnorm(1000),x2=runif(1000,30,90),x3=rnorm(1000,4500,120))
> str(d)
'data.frame': 1000 obs. of 3 variables:
$ x1: num -0.552 2.465 0.557 -0.712 -1.438 ...
$ x2: num 43.8 68.6 62.5 85.8 62.2 ...
$ x3: num 4701 4631 4408 4578 4354 ...
> kmeans(d[,1:3],4)->cl
> names(cl)
[1] "cluster" "centers" "totss" "withinss" "tot.withinss"
"betweenss" "size" "iter" "ifault"
> cl$size
[1] 186 355 145 314
> cl
K-means clustering with 4 clusters of sizes 186, 355, 145, 314

Cluster means:
x1 x2 x3
1 0.12551177 57.74137 4333.027
2 -0.01502202 61.59609 4461.435
3 -0.02979339 58.00981 4686.356
4 -0.02743540 58.00128 4559.285

Clustering vector:
[1] 3 3 2 4 1 2 3 3 2 1 1 4 2 4 2 4 2 2 1 4 4 2 4 4 2 4 1 4 4 2 4 3 1 3 3 4 4 3
3 4 3 4 2 3 2 4 3 2 2 3 1 2 4 4 3 4 4 2 1 4 3 4 4 4 2 4 4 4 2 2 4 1 1 4 2 2 2 2 3 1
[81] 4 2 2 3 1 3 4 4 3 2 4 4 4 2 2 4 2 3 4 2 2 2 4 2 2 3 2 4 3 1 3 2 4 1 3 1 3 4
3 4 2 2 3 1 2 2 2 2 4 1 1 2 2 2 2 4 2 2 4 2 3 4 3 3 1 2 2 2 4 2 4 4 4 2 2 4 3 4 4 1
[161] 1 1 1 1 2 2 2 4 4 2 3 4 2 4 2 1 2 2 4 4 4 4 3 1 4 3 1 1 3 2 3 4 4 1 4 2 3 3
1 1 2 3 2 4 2 4 3 2 2 2 4 3 4 3 2 4 4 4 4 4 1 4 2 1 2 1 2 2 4 1 4 2 2 4 1 1 1 2 4 2
[241] 4 2 2 1 4 1 4 1 1 2 2 2 4 4 2 4 3 4 1 2 4 2 3 2 3 4 1 1 4 2 4 4 4 4 3 4 4 4
3 1 4 4 1 2 3 4 3 2 4 1 2 1 4 3 2 1 2 2 2 1 4 3 4 3 2 1 2 2 4 2 1 1 2 1 2 2 2 2 1 4
[321] 3 4 2 4 1 3 2 2 2 3 4 2 1 1 4 2 1 2 1 1 2 2 3 4 1 1 4 4 2 3 1 4 2 4 1 4 4 4
4 2 2 4 3 2 1 4 1 2 2 4 2 2 4 2 3 3 4 2 4 2 2 1 3 1 3 1 2 1 2 2 2 1 4 3 3 2 4 3 4 4
[401] 1 2 2 2 1 4 3 3 4 2 4 2 2 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1 2 3 3 4
1 4 3 4 2 3 3 2 4 2 2 4 1 2 4 2 2 3 1 4 2 1 2 1 1 4 4 4 2 3 3 1 4 4 1 2 4 1 2 1 4 2
[961] 1 3 2 4 4 2 3 4 4 3 1 4 4 3 4 2 2 3 3 2 1 4 4 2 3 1 2 1 2 3 4 4 1 1 2 4 1 3
2 4

Within cluster sum of squares by cluster:


[1] 609672.2 458051.3 425284.4 386548.7
(between_SS / total_SS = 86.3 %)

Available components:

[1] "cluster" "centers" "totss" "withinss" "tot.withinss"


"betweenss" "size" "iter" "ifault"
> Viewcl$size
Error: object 'Viewcl' not found
> cl$cluster
[1] 3 3 2 4 1 2 3 3 2 1 1 4 2 4 2 4 2 2 1 4 4 2 4 4 2 4 1 4 4 2 4 3 1 3 3 4 4 3
3 4 3 4 2 3 2 4 3 2 2 3 1 2 4 4 3 4 4 2 1 4 3 4 4 4 2 4 4 4 2 2 4 1 1 4 2 2 2 2 3 1
[81] 4 2 2 3 1 3 4 4 3 2 4 4 4 2 2 4 2 3 4 2 2 2 4 2 2 3 2 4 3 1 3 2 4 1 3 1 3 4
3 4 2 2 3 1 2 2 2 2 4 1 1 2 2 2 2 4 2 2 4 2 3 4 3 3 1 2 2 2 4 2 4 4 4 2 2 4 3 4 4 1
[161] 1 1 1 1 2 2 2 4 4 2 3 4 2 4 2 1 2 2 4 4 4 4 3 1 4 3 1 1 3 2 3 4 4 1 4 2 3 3
1 1 2 3 2 4 2 4 3 2 2 2 4 3 4 3 2 4 4 4 4 4 1 4 2 1 2 1 2 2 4 1 4 2 2 4 1 1 1 2 4 2
[241] 4 2 2 1 4 1 4 1 1 2 2 2 4 4 2 4 3 4 1 2 4 2 3 2 3 4 1 1 4 2 4 4 4 4 3 4 4 4
3 1 4 4 1 2 3 4 3 2 4 1 2 1 4 3 2 1 2 2 2 1 4 3 4 3 2 1 2 2 4 2 1 1 2 1 2 2 2 2 1 4
[321] 3 4 2 4 1 3 2 2 2 3 4 2 1 1 4 2 1 2 1 1 2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 4 2 4 4 1 1 4 2 2 1 1 4 4 2 4 2 1 1 1 4 2 4 2 2 3 4 4 2 2 4 2 3 4 2 4 2 4 3 3
[881] 1 4 2 2 2 4 3 1 3 1 1 2 2 4 2 1 2 4 2 4 2 2 2 4 4 1 4 1 4 3 1 2 1 1 2 3 3 4
1 4 3 4 2 3 3 2 4 2 2 4 1 2 4 2 2 3 1 4 2 1 2 1 1 4 4 4 2 3 3 1 4 4 1 2 4 1 2 1 4 2
[961] 1 3 2 4 4 2 3 4 4 3 1 4 4 3 4 2 2 3 3 2 1 4 4 2 3 1 2 1 2 3 4 4 1 1 2 4 1 3
2 4
> cl$totss
[1] 13734763
> str(d)
'data.frame': 1000 obs. of 3 variables:
$ x1: num -0.552 2.465 0.557 -0.712 -1.438 ...
$ x2: num 43.8 68.6 62.5 85.8 62.2 ...
$ x3: num 4701 4631 4408 4578 4354 ...
>

Вам также может понравиться