🔍 Code Extractor

class AnalysisConfiguration

Maturity: 46

A dataclass that encapsulates configuration parameters for statistical analysis operations, including analysis type, variables, and statistical thresholds.

File:
/tf/active/vicechatdev/vice_ai/models.py
Lines:
1749 - 1780
Complexity:
simple

Purpose

AnalysisConfiguration serves as a structured container for defining statistical analysis parameters. It manages the configuration of analysis type (via AnalysisType enum), target/grouping/control variables, significance and confidence levels, and custom parameters. The class provides serialization/deserialization capabilities through to_dict() and from_dict() methods, making it suitable for persistence and data exchange. It automatically initializes None values to appropriate empty collections in __post_init__.

Source Code

class AnalysisConfiguration:
    """Configuration for statistical analysis"""
    analysis_type: AnalysisType
    target_variables: List[str] = None
    grouping_variables: List[str] = None
    control_variables: List[str] = None
    significance_level: float = 0.05
    confidence_level: float = 0.95
    custom_parameters: Dict[str, Any] = None
    
    def __post_init__(self):
        if self.target_variables is None:
            self.target_variables = []
        if self.grouping_variables is None:
            self.grouping_variables = []
        if self.control_variables is None:
            self.control_variables = []
        if self.custom_parameters is None:
            self.custom_parameters = {}
    
    def to_dict(self) -> Dict[str, Any]:
        """Convert to dictionary with enum values as strings"""
        result = asdict(self)
        result['analysis_type'] = self.analysis_type.value
        return result
    
    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> 'AnalysisConfiguration':
        """Create instance from dictionary"""
        if isinstance(data.get('analysis_type'), str):
            data['analysis_type'] = AnalysisType(data['analysis_type'])
        return cls(**data)

Parameters

Name Type Default Kind
bases - -

Parameter Details

analysis_type: An AnalysisType enum value specifying the type of statistical analysis to perform (e.g., regression, t-test, ANOVA). This is a required parameter with no default value.

target_variables: List of strings representing the dependent/outcome variables to analyze. Defaults to None and is initialized to an empty list in __post_init__.

grouping_variables: List of strings representing categorical variables used to group data for analysis. Defaults to None and is initialized to an empty list in __post_init__.

control_variables: List of strings representing variables to control for in the analysis (covariates). Defaults to None and is initialized to an empty list in __post_init__.

significance_level: Float value representing the alpha level for statistical significance testing. Defaults to 0.05 (5% significance level).

confidence_level: Float value representing the confidence level for interval estimation. Defaults to 0.95 (95% confidence).

custom_parameters: Dictionary for storing additional analysis-specific parameters not covered by standard attributes. Defaults to None and is initialized to an empty dictionary in __post_init__.

Return Value

Instantiation returns an AnalysisConfiguration object with all specified parameters. The to_dict() method returns a dictionary representation with the analysis_type enum converted to its string value. The from_dict() class method returns a new AnalysisConfiguration instance constructed from a dictionary.

Class Interface

Methods

__post_init__(self) -> None

Purpose: Automatically called after dataclass __init__ to initialize None values to appropriate empty collections

Returns: None - modifies instance attributes in place

to_dict(self) -> Dict[str, Any]

Purpose: Converts the configuration object to a dictionary with enum values serialized as strings for JSON compatibility

Returns: Dictionary representation of the configuration with analysis_type converted to its string value

from_dict(cls, data: Dict[str, Any]) -> 'AnalysisConfiguration'

Purpose: Class method that creates an AnalysisConfiguration instance from a dictionary, converting string analysis_type back to enum

Parameters:

  • data: Dictionary containing configuration data with keys matching class attributes. The 'analysis_type' can be either a string or AnalysisType enum

Returns: New AnalysisConfiguration instance constructed from the provided dictionary

Attributes

Name Type Description Scope
analysis_type AnalysisType Enum value specifying the type of statistical analysis to perform instance
target_variables List[str] List of dependent/outcome variable names to analyze instance
grouping_variables List[str] List of categorical variable names used for grouping data instance
control_variables List[str] List of covariate variable names to control for in analysis instance
significance_level float Alpha level for statistical significance testing (default: 0.05) instance
confidence_level float Confidence level for interval estimation (default: 0.95) instance
custom_parameters Dict[str, Any] Dictionary for storing additional analysis-specific parameters instance

Dependencies

  • dataclasses
  • typing
  • enum

Required Imports

from dataclasses import dataclass, asdict
from typing import List, Dict, Any
from enum import Enum

Usage Example

from dataclasses import dataclass
from typing import List, Dict, Any
from enum import Enum

# Define the AnalysisType enum (required dependency)
class AnalysisType(Enum):
    REGRESSION = 'regression'
    TTEST = 't_test'
    ANOVA = 'anova'

# Create an analysis configuration
config = AnalysisConfiguration(
    analysis_type=AnalysisType.REGRESSION,
    target_variables=['sales', 'revenue'],
    grouping_variables=['region', 'category'],
    control_variables=['age', 'income'],
    significance_level=0.05,
    confidence_level=0.95,
    custom_parameters={'method': 'ols', 'robust': True}
)

# Convert to dictionary for serialization
config_dict = config.to_dict()
print(config_dict)
# Output: {'analysis_type': 'regression', 'target_variables': ['sales', 'revenue'], ...}

# Recreate from dictionary
restored_config = AnalysisConfiguration.from_dict(config_dict)
print(restored_config.analysis_type)  # AnalysisType.REGRESSION

Best Practices

  • Always provide a valid AnalysisType enum value when instantiating, as it is the only required parameter
  • Use __post_init__ automatic initialization by passing None for list/dict parameters rather than mutable default values
  • When serializing to JSON or other formats, use to_dict() to ensure enum values are properly converted to strings
  • When deserializing, use from_dict() class method to ensure proper enum reconstruction from string values
  • Keep significance_level and confidence_level values between 0 and 1 (they represent probabilities)
  • Use custom_parameters dictionary for analysis-specific settings that don't fit standard attributes
  • The class is immutable after creation unless explicitly modified, making it safe for concurrent access
  • Ensure AnalysisType enum is defined before using this class

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class AnalysisResult_v1 63.8% similar

    A dataclass that encapsulates the results from statistical analysis operations, including metadata, file paths, and timestamps.

    From: /tf/active/vicechatdev/vice_ai/models.py
  • class AnalysisResult_v1 63.4% similar

    A dataclass that encapsulates results from statistical analysis operations, providing structured storage and serialization capabilities for analysis outputs.

    From: /tf/active/vicechatdev/vice_ai/models.py
  • class AnalysisType 63.4% similar

    An enumeration class that defines standardized types of statistical analyses available in the system.

    From: /tf/active/vicechatdev/vice_ai/models.py
  • class AnalysisResult 62.5% similar

    A dataclass that encapsulates the results from statistical analysis operations, including metadata, file paths, and timestamps.

    From: /tf/active/vicechatdev/vice_ai/smartstat_models.py
  • class DataAnalysisSession_v1 62.5% similar

    A dataclass representing a statistical analysis session that is linked to specific document sections, managing analysis state, messages, plots, and configuration.

    From: /tf/active/vicechatdev/vice_ai/models.py
← Back to Browse