hi guys welcome to the next tutorial and
now we are moving into factor analysis
factor analysis is the regression method
you apply to discover root causes or
hidden factors that are present in the
data set but not observable for example
imagine you are marketing data
scientists and you must identify
actionable customer segments for use in
strategic marketing planning you have
got response data from our customer
survey you can apply factor analysis is
a simple way to group respondents into
meaningful customer segments based on
similarities in how response tends
answered a specific subset of survey
questions factor analysis is a method
you use to regress on features in order
to discover factors that you can use as
variables to represent the original data
set these factors are actually synthetic
representations of your dataset with the
extra dimensionality and information
redundancy stripped out factors are also
called latent variables latent variables
are variables that are meaningful but
that are inferred and not directly
observable there are several assumptions
you should know about with vector
analysis the factor analysis model
assumes that you are features are metric
but they are either continuous or
ordinal that you have a correlation
coefficient R greater than 0.3 that you
have more than 100 observations and more
than 5 observations per feature it also
assumes that you are your sample is
homogeneous for those of you that are
new to data analysis and data science
don't worry too much about all these
details you just want to help them in
the back of your mind as you continue
learning and then over time you will
start learning what bees mean and how to
apply them let's talk about factor
analysis you actually access the factor
analysis model from within scikit-learn
scikit-learn is the
learning library in Python it comes from
anaconda installed and again if you want
to see how to install anaconda check out
what you should know video at the start
of this course we are going to use
factor analysis to uncover latent
variables from cyclins built-in data set
called iris remember our latent variable
is just a hidden variable that impacts
how data is behaving and as far as
built-in data sets those are basically
just toy data sets that you can use to
practice machine learning instead of
going through every step and checking to
see that all of the model assumptions
are met I'm just going to tell you they
are we are fine with doing effect
analysis on the iris data set more about
the iris data set the iris dataset
contains four numeric variables that
describe three different species of iris
flowers the for numeric attributes are
sample length sepal width petal length
and metal width in this demonstration
you are going to see how to fit the
factor analysis model to the iris data
set in order to reduce the data sets
dimensionality by uncovering the
combination of features that contain the
most information in other words that
contain the most variance in the data
set these will be our factors or latent
variables so let's get started the first
thing we need to do like usual is to
import the libraries we will be using so
in this demonstration you are going to
be using and pi and pandas just like be
helping so I will just copy and paste
those in and then we need to import
cyclotron we can do that by typing
import SQL we also need to import the
factor analysis model from the
decomposition module of a scale and you
do that by writing from s Kalyan dot des
decomposition
port sector analysis also for this
demonstration we need to learn the iris
dataset we do that by writing from SK
learn import data sets now this is going
to import all of the built-in data sets
for SK learn later we are going to load
the iris dataset from those so let's
execute this now we have our libraries
that we need let me show you how to do
vector analysis let's start off by
loading the iris dataset for analysis to
load a built-in data set from
scikit-learn called the load iris
function instead of as a variable we
will call this variable iris so we say R
is equal data sets dot Lord iris this is
its own function now let's create X
variable and set it equal to the iris
data these are the four numerical
variables that make up the iris dataset
we also want to import the eight
variable names we will use these for
putting column headers on our data frame
table later in the demonstration and
they are also included in the built-in
data set so in order to access them we
just write iris dot V names and this
will be the column headers now let's
print out this X data set we will print
out the first ten records in all columns
what you see here is a small preview of
the IRS data we are working with the
next thing we need to do is to initiate
a factor analysis object and find the
latent variables by calling the fit
method on our data set we do this by
writing factor that is going to be our
object equals to vector analysis dot fit
we also need to make a data frame so
that we can look at the latent variables
or the factors that were found to do
this we call the data frame constructor
on the components attribute of our
vector object the components attribute
represents the components or in other
words factors with maximum variance
let's also pass in the argument columns
equal to variable names so that we can
get a good understanding at what we are
looking at in our output data frame here
we go I will just type this up really
quick this is about data frame
constructor we access vector components
this is the component attribute then we
will put columns equal to variable names
all right here we have got a data frame
back it's called the column headings but
what does it mean