The problem lies here.
a = FactorAnalyzer()
either change it to fa = FactorAnalyzer()
otherwise Change this line
fa.analyze(df, 25, rotation=None) to
a.analyze(df, 25, rotation=None)
Also, you may get another error, as df not defined. You need to define the pandas dataframe df before invoking.
Update:
I looked into the list of modules available in the FactorAnalyzer. There is no such module available. Assuming following is the content of bfi.csv file https://raw.githubusercontent.com/vincentarelbundock/Rdatasets/master/csv/psych/bfi.csv
C:\Users\kuvivek\Desktop>python
ActivePython 3.6.6 (ActiveState Software Inc.) based on
Python 3.6.6 (default, Nov 7 2019, 20:16:27) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from factor_analyzer import FactorAnalyzer
>>> import pandas as pd
>>> df=pd.read_csv(r'C:\Users\kuvivek\Desktop\bfi.csv')
>>> fa = FactorAnalyzer()
>>> dir(fa)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_fit_factor_analysis', '_fit_ml_objective', '_fit_principal', '_fit_uls_objective', '_get_factor_variance', '_get_param_names', '_normalize_ml', '_normalize_uls', 'bounds', 'corr_', 'fit', 'fit_transform', 'get_communalities', 'get_eigenvalues', 'get_factor_variance', 'get_params', 'get_uniquenesses', 'impute', 'is_corr_matrix', 'loadings_', 'mean_', 'method', 'n_factors', 'phi_', 'rotation', 'rotation_kwargs', 'rotation_matrix_', 'set_params', 'std_', 'structure_', 'transform', 'use_smc']
You need to use any one of these, as there is no such function analyze available in the FactoryAnalyzer Class. In order to get complete documentation, use the following command as shown below.
>>>
>>> help(fa)
Help on FactorAnalyzer in module factor_analyzer.factor_analyzer object:
class FactorAnalyzer(sklearn.base.BaseEstimator, sklearn.base.TransformerMixin)
| A FactorAnalyzer class, which -
| (1) Fits a factor analysis model using minres, maximum likelihood,
| or principal factor extraction and returns the loading matrix
| (2) Optionally performs a rotation, with method including:
|
| (a) varimax (orthogonal rotation)
| (b) promax (oblique rotation)
| (c) oblimin (oblique rotation)
| (d) oblimax (orthogonal rotation)
| (e) quartimin (oblique rotation)
| (f) quartimax (orthogonal rotation)
| (g) equamax (orthogonal rotation)
|
| Parameters
| ----------
| n_factors : int, optional
| The number of factors to select.
| Defaults to 3.
| rotation : str, optional
| The type of rotation to perform after
| fitting the factor analysis model.
| If set to None, no rotation will be performed,
| nor will any associated Kaiser normalization.
|
| Methods include:
|
-- More --