Monday 9 April 2018

PCA

wine <- read.csv("C:/Users/hp/Desktop/wine.csv", header=FALSE)
View(wine)
library(arules)

colnames(wine)<-(c("No","Alcohol", "Malic acid","Ash","Alcalinity of ash","Magnesium"," Total phenols","Flavanoids","Nonflavanoid phenols","Proanthocyanins","Color intensity","Hue","OD280/OD315 of diluted wines","Proline"))

View(wine)
wine$No<-NULL
wineColnames<-(c("Alcohol", "Malic acid","Ash","Alcalinity of ash","Magnesium"," Total phenols","Flavanoids","Nonflavanoid phenols","Proanthocyanins","Color intensity","Hue","OD280/OD315 of diluted wines","Proline"))

wineColnames
wine1<-wine
View(wine1)
summary(wine1)
wine_cov<-cov(wine1)
wine_cov
wine_cor<-cor(wine1)
wine_cor
View(wine_cov)
wine_eigen<-eigen(wine_cov)
wine_eigen
wine_pca<-princomp(wine1,cor=FALSE)
install.packages('ggfortify')
library(ggfortify)
autoplot(wine_pca)
names(wine_pca)
loadings(wine_pca)
summary(wine_pca)
# sum of SD
sum(wine_pca$sdev)
# varience
sum((wine_pca$sdev)^2)

eigen(wine_cov)$values
mean(eigen(wine_cov)$values)

plot(wine_pca,type="lines")

#from the analysis we understand that only one component plays imp. role, i.e., alcohol
wine_alcohol<-eigen(wine_cov)$vector[,1]
wine_matrix<-as.matrix(wine1)


wine_final<-wine_matrix%*%(wine_alcohol)
wine_final
summary(wine_final)

plot(wine_final,xlab="Index 1 - 178",ylab="Range" )
title("Plot the PCA with Wine$Alcohol")
View(wine_final)

wine_pcakmean<-kmeans(wine_final[],3)
(wine_pcakmean)
library(fpc)
plotcluster(wine1,wine_pcakmean$cluster)
title("Plot the PCA with Wine After Transformation")
table(wine1,wine_pcakmean$cluster)

wine_kmean<-kmeans(wine1[],3)
wine_kmean
plotcluster(wine1,wine_kmean$cluster)
title("Plot the PCA with Wine Before Transformation")
dim(wine_kmean)


Friday 17 February 2017

Groups


    Group is a non-empty set ogether with a binary operation,*,defined on G ,which satisfies the following axioms.
G satisfies:
                1)Closure property
               2)Associative
               3)Identity
               4)Inverse
             with respect to binary operation *,if(Z4,+4) is a group.
      Examples of groups:
               1)The set of all symmetries of the infinite ornamental pattern in which the arrow heads are                    spaced,uniformly,a unit part along a line is an abelian group,under composition.Let T                          denote a translation to the right by one unit.,the inverse of t,a translation to the left by one                    unit and H a reflection across the horizontal line of the figure.Then every member of the                       group is of the form x1,x2,...xn.where each xi belongs to {T,T^-1,H}.
              2)Let F be any of Q,R,C or Zp(p is a prime).The set GL(2,F) of all 2x2 matrices with non-                      zero determinants and entries from F is a non-Abelian group under matrix multipication.
              3)For a fixed point (a,b) in R^2 ,define T[a,b]:R^2->R^2 by (x,y)->(x+a,y+b).Then
                 T(R^2)={T[a,b]|a,b belongs to R } is a group under function composition.
              4)The set R^n={(a1,a2,....an)|a1,a2....an belongs to R} is a group under component wise                           addition[ie,(a1,a2,...an)+(b1,b2,...bn)=(a1+b1,a2+b2,....an+bn)].
              5)For all integers n>=1 ,the set of complex roots of                                                unity{cos(k.360'/n)+isin(k.360'/n)|k=0,1,2,...n-1}
               6)Klein group
                  It has 4 elements
                     [1,0,0,1],[-1,0,0,-1],[-1,0,0,1],[1,0,0,-1]
                     The binary operation is matrix multiplicatio.This is the smallest group which is not                               cyclic.
               7)Paul's Group:(Quatterian group)
                  There are 8 elements:+1,-1,+1,-1,+j,-j,+R,-R
                   where 1=[1,0,0,1]
                               i=[i,0,0,-i]
                              j=[0,1,-1,0]
                              R=[0,i,i,0]
                                where i is the complex i=(0,1)
                  It is a group under matrix addition and multiplication
                  NB:The elements of the matrix are given in the order [a11,a12,a21,a22]
           8)The set R* of non-zero real numbers is a group under ordinary multiplication.The identity is                1.The inverse of a is 1/a.
           9)SLn(R)={Anxn:A is a nxn matrix with entries from R and det(A)=1}
               Then (SLn(R),*) where * is the matrix multiplication.
               SLn is called the special linear group.
           10)Un (C)={Anxn :A is an nxn matrix such that A*A =I}
                (Un(c),X)  where X is a matrix multiplication,then this is a group.It is called unitary group. where A,* is the complex conj of A A*=[aji^_]if A=[aij]
            11)Set Q+ of positive rationals is a groupunder ordinary multiplication.
            12){1,2,3,4} under multiplication modulo 5
         13)all 3x3 matrices with real entries of the form                               [a11=1,a12=a,a13=b,a21=0,a22=1,a23=c,a31=0,a32=0,a33=1]
           14)G ,a matrix under multiplication operatio,whereG={[a11=a,a12=a,a13=a,a14=a]|a belongs to R,a!=0}

                    

Tuesday 6 December 2016

Excercises





Excercise 1.3
1)If 81270 is a multiple of 3 or 7,that means that
81270=a*3 or 81270=b*7
That is,a=81270/3 or b=81270/7
Thus proved that 81270 is  either a multiple of 3 or 7
2)Given
                200000000=375*a
                Therefore 400000000=2*200000000=2*375*a
                Therefore it is proved that  if 20000000 is a multiple of 375,then 400000000 is a multiple of 375

3)200000000 is not a multiple of 375.
Irrelevant of the truth of the above statement ,the  statement that if 20000000 is a multiple of 375 then 40000000 is a multiple of 375 has to be proved...
4)Excercise 1.5.1
Counter example for 6n+1 is prime
Take n=4,thus 6n+1=6*4+1=25 ,which is not prime..
5)Exercie 1.5.2
If n is a multiple of 3 then n is a multiple of 6 true or false
Say a=3*n,where n is any natural number..
Therefore
B=6n,where n is any natural number,
ie,b=2*(3n)
and hence proved that if n is a multiple of 3 then n is a multiple of 6
6)Exercise2.2.1.a
A={2,4,8}
B={m|m is an even number}
A is thus a subset of    B
7)Ex 2.2.1.b
A={3,7,1025} B=(m|m=2n -1 for some number n}
A is not a subset of B as all the elements of A do not satisfy the condition in B
8)2.2.1.c
A={0},B=0
A is not a subset of B
9)A=0,B={0}
A is a subset of B ,as null set is the subset of any given set
10)2.2.2
A={a,b,c}
The subsets are
{a},{b},{c},{a,b},{b,c},{c,a},{a,b,c},0
Exercise 3.5
#Contrapositive statements
1a)If n is a multiple of 3 then n is not a multiple of 7
1b)If n is not a multiple of 4 then n is not a multiple of 12
2)Statement 1a is false and statement  1b is true
3)The converse of 1a and 1b are:
                If n is not a multiple of of 3, then n is a multiple of 7
                If n is a multiple of 4,then n is a multiple of 12
Thus the statement 1a is again false and 1b is true
4)If n+1 is prime, then  n  is not  a prime and n<3
Suppose 29 is not prime,this implies that there exists two numbers r and s such that r and s not equal to 1 and 29.
Contrapositive:If  r and s not equal 1 and 29,then 29 is not prime where 29=r*s
Inverse:If 29  is prime where 29=r*s,then  r and s is 1 and 29
Converse:If r and s is not  1 and 29,then 29 is not prime,where 29=r*s