factor_analyzer.confirmatory_factor_analyzer.ModelSpecificationParser()
Generate the model specification for CFA.
This class includes two static methods to generate a :class:ModelSpecification object from either a dictionary or a numpy array.
Methods
parse_model_specification_from_array
factor_analyzer.confirmatory_factor_analyzer.ModelSpecificationParser.parse_model_specification_from_array(
X,
specification= None ,
)
Generate the model specification from a numpy array.
The columns should correspond to the factors, and the rows should correspond to the variables. If this method is used to create the :class:ModelSpecification object, then no factor names and variable names will be added as properties to that object.
Parameters
X
array - like
The data set that will be used for CFA.
required
specification
array - like
An array with the loading details. If None, the matrix will be created assuming all variables load on all factors. Defaults to None.
None
Raises
ValueError
If specification is not in the expected format.
Examples
import pandas as pd
import numpy as np
import os
from spotoptim.factor_analyzer import (ConfirmatoryFactorAnalyzer,
ModelSpecificationParser)
from spotoptim.utils import get_internal_datasets_folder
X = pd.read_csv(os.path.join(get_internal_datasets_folder(), 'test11.csv' ))
model_array = np.array([[1 , 1 , 1 , 1 , 0 , 0 , 0 , 0 ], [0 , 0 , 0 , 0 , 1 , 1 , 1 , 1 ]])
model_spec = ModelSpecificationParser.parse_model_specification_from_array(X,
model_array)
parse_model_specification_from_dict
factor_analyzer.confirmatory_factor_analyzer.ModelSpecificationParser.parse_model_specification_from_dict(
X,
specification= None ,
)
Generate the model specification from a dictionary.
The keys in the dictionary should be the factor names, and the values should be the feature names. If this method is used to create the :class:ModelSpecification object, then factor names and variable names will be added as properties to that object.
Parameters
X
array - like
The data set that will be used for CFA.
required
specification
dict
A dictionary with the loading details. If None, the matrix will be created assuming all variables load on all factors. Defaults to None.
None
Raises
ValueError
If specification is not in the expected format.
Examples
import pandas as pd
import os
from spotoptim.factor_analyzer import (ConfirmatoryFactorAnalyzer,
ModelSpecificationParser)
from spotoptim.utils import get_internal_datasets_folder
X = pd.read_csv(os.path.join(get_internal_datasets_folder(), 'test11.csv' ))
model_dict = {"F1" : ["V1" , "V2" , "V3" , "V4" ],
"F2" : ["V5" , "V6" , "V7" , "V8" ]}
model_spec = ModelSpecificationParser.parse_model_specification_from_dict(X, model_dict)