-
Notifications
You must be signed in to change notification settings - Fork 0
Fix package structure, update badges, and resolve gitignore blocking source code #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
52c192e
5866646
6d6b48f
8ebc0d7
5d9a01a
347f521
b7a9008
ae28c3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| """ | ||
| ===================================================================== | ||
| File : BaseCapsule.py | ||
| ===================================================================== | ||
| version : 1.0.0 | ||
| release : 15/06/2025 | ||
| author : Phoenix Project | ||
| contact : contact@phoenixproject.onmicrosoft.fr | ||
EthanThePhoenix38 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| license : MIT | ||
| ===================================================================== | ||
| Copyright (c) 2025, Phoenix Project | ||
| All rights reserved. | ||
| Description du module BaseCapsule.py | ||
| Base class for all statistical analysis capsules/modules. | ||
| Provides common interface and functionality for data processing. | ||
| tags : module, base, capsule | ||
| ===================================================================== | ||
| """ | ||
|
|
||
| from typing import Any, Dict, Union | ||
|
|
||
| import numpy as np | ||
| import pandas as pd | ||
|
|
||
|
|
||
| class BaseCapsule: | ||
| """ | ||
| Base class for all statistical analysis modules. | ||
| Provides common interface for data validation, configuration, | ||
| and processing workflow. | ||
| Attributes: | ||
| data: Input data being processed | ||
| parameters: Configuration parameters | ||
| result: Analysis results | ||
| """ | ||
|
|
||
| def __init__(self): | ||
| """Initialize BaseCapsule with default attributes.""" | ||
| self.data = None | ||
| self.parameters = {} | ||
| self.result = None | ||
|
|
||
| def configure(self, **kwargs) -> None: | ||
| """ | ||
| Configure the module parameters. | ||
| Args: | ||
| **kwargs: Configuration parameters | ||
| """ | ||
| self.parameters.update(kwargs) | ||
|
|
||
| def validate_data( | ||
| self, data: Union[pd.DataFrame, pd.Series, np.ndarray, list] | ||
| ) -> None: | ||
| """ | ||
| Validate input data. | ||
| Args: | ||
| data: Data to validate | ||
| Raises: | ||
| ValueError: If data is invalid | ||
| """ | ||
| if data is None: | ||
| raise ValueError("Data cannot be None") | ||
|
|
||
| if isinstance(data, (pd.DataFrame, pd.Series)): | ||
| if data.empty: | ||
| raise ValueError("Data cannot be empty") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Merci de corriger comme préconisé
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Corrected as recommended - changed to catch specific exceptions (TypeError, ValueError). Fixed in commit b7a9008. |
||
| elif isinstance(data, (np.ndarray, list)): | ||
| if len(data) == 0: | ||
| raise ValueError("Data cannot be empty") | ||
| else: | ||
| # Try to convert to array-like | ||
| try: | ||
| data_array = np.array(data) | ||
| if data_array.size == 0: | ||
| raise ValueError("Data cannot be empty") | ||
| except Exception as e: | ||
EthanThePhoenix38 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| raise ValueError(f"Invalid data type: {type(data)}. Error: {e}") | ||
|
|
||
| def process( | ||
| self, data: Union[pd.DataFrame, pd.Series, np.ndarray], **kwargs | ||
| ) -> Dict[str, Any]: | ||
| """ | ||
| Process data and perform analysis. | ||
| This method should be overridden by subclasses. | ||
| Args: | ||
| data: Input data to process | ||
| **kwargs: Additional processing parameters | ||
| Returns: | ||
| Dict[str, Any]: Analysis results | ||
| """ | ||
| raise NotImplementedError("Subclasses must implement the process method") | ||
|
|
||
| def get_result(self) -> Any: | ||
| """ | ||
| Get the analysis result. | ||
| Returns: | ||
| Analysis result | ||
| """ | ||
| return self.result | ||
|
|
||
| def reset(self) -> None: | ||
| """Reset the module to initial state.""" | ||
| self.data = None | ||
| self.parameters = {} | ||
| self.result = None | ||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,96 @@ | ||||||||||||
| """ | ||||||||||||
| Correlation analysis module. | ||||||||||||
| Provides the CorrelationAnalysis class for computing correlations between variables. | ||||||||||||
| """ | ||||||||||||
|
|
||||||||||||
| from typing import Any, Dict, Union | ||||||||||||
|
|
||||||||||||
| import numpy as np | ||||||||||||
| import pandas as pd | ||||||||||||
| from scipy import stats | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| class CorrelationAnalysis: | ||||||||||||
| """ | ||||||||||||
| Correlation analysis class. | ||||||||||||
| Computes correlation coefficients between variables with support for | ||||||||||||
| different correlation methods (Pearson, Spearman, Kendall). | ||||||||||||
| """ | ||||||||||||
|
|
||||||||||||
| def __init__(self, method: str = "pearson"): | ||||||||||||
| """ | ||||||||||||
| Initialize CorrelationAnalysis. | ||||||||||||
| Args: | ||||||||||||
| method: Correlation method ('pearson', 'spearman', or 'kendall') | ||||||||||||
| """ | ||||||||||||
|
||||||||||||
| """ | |
| """ | |
| valid_methods = {"pearson", "spearman", "kendall"} | |
| if method not in valid_methods: | |
| raise ValueError(f"Method must be one of {valid_methods}, got '{method}'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added method validation in init as suggested. Invalid methods now fail immediately with a clear error message. Fixed in commit b7a9008.
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,57 @@ | ||||||||
| """ | ||||||||
| Statistics descriptives module. | ||||||||
| Provides the DescriptiveStatistics class for computing descriptive | ||||||||
| statistics on various data types (lists, arrays, Series, DataFrames). | ||||||||
| """ | ||||||||
|
|
||||||||
| from typing import Any, Dict, Union | ||||||||
|
|
||||||||
| import numpy as np | ||||||||
| import pandas as pd | ||||||||
|
|
||||||||
|
|
||||||||
| class DescriptiveStatistics: | ||||||||
| """ | ||||||||
| Class for computing descriptive statistics. | ||||||||
| Handles various data types and provides comprehensive statistical measures | ||||||||
| including central tendency, dispersion, and percentiles. | ||||||||
| """ | ||||||||
|
|
||||||||
| def __init__(self): | ||||||||
| """Initialize DescriptiveStatistics.""" | ||||||||
| pass | ||||||||
|
||||||||
| def __init__(self): | |
| """Initialize DescriptiveStatistics.""" | |
| pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the empty init method. Python will use the default object.init. Fixed in commit b7a9008.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sonarqube a suggéré un changement par
def init(self):
"""Initialize DescriptiveStatistics."""
pass
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| """ | ||
| Linear regression module. | ||
|
|
||
| Provides the LinearRegression class for performing linear regression analysis. | ||
| """ | ||
|
|
||
| from typing import Any, Dict, Union | ||
|
|
||
| import numpy as np | ||
| from sklearn.linear_model import LinearRegression as SKLearnLinearRegression | ||
| from sklearn.metrics import mean_squared_error, r2_score | ||
|
|
||
|
|
||
| class LinearRegression: | ||
| """ | ||
| Linear regression analysis class. | ||
|
|
||
| Provides methods for fitting linear regression models and making predictions. | ||
| """ | ||
|
|
||
| def __init__(self): | ||
| """Initialize LinearRegression.""" | ||
| self.model = SKLearnLinearRegression() | ||
| self.is_fitted = False | ||
|
|
||
| def fit( | ||
| self, X: Union[np.ndarray, list], y: Union[np.ndarray, list] | ||
| ) -> "LinearRegression": | ||
| """ | ||
| Fit the linear regression model. | ||
|
|
||
| Args: | ||
| X: Feature matrix | ||
| y: Target vector | ||
|
|
||
| Returns: | ||
| Self for method chaining | ||
| """ | ||
| X = np.array(X) if not isinstance(X, np.ndarray) else X | ||
| y = np.array(y) if not isinstance(y, np.ndarray) else y | ||
|
|
||
| self.model.fit(X, y) | ||
| self.is_fitted = True | ||
| return self | ||
|
|
||
| def predict(self, X: Union[np.ndarray, list]) -> np.ndarray: | ||
| """ | ||
| Make predictions using the fitted model. | ||
|
|
||
| Args: | ||
| X: Feature matrix | ||
|
|
||
| Returns: | ||
| Predicted values | ||
|
|
||
| Raises: | ||
| RuntimeError: If model hasn't been fitted | ||
| """ | ||
| if not self.is_fitted: | ||
| raise RuntimeError("Model must be fitted before making predictions") | ||
|
|
||
| X = np.array(X) if not isinstance(X, np.ndarray) else X | ||
| return self.model.predict(X) | ||
|
|
||
| def analyze( | ||
| self, X: Union[np.ndarray, list], y: Union[np.ndarray, list] | ||
| ) -> Dict[str, Any]: | ||
| """ | ||
| Perform complete regression analysis. | ||
|
|
||
| Args: | ||
| X: Feature matrix | ||
| y: Target vector | ||
|
|
||
| Returns: | ||
| Dictionary containing regression results and metrics | ||
| """ | ||
| self.fit(X, y) | ||
| predictions = self.predict(X) | ||
|
|
||
| return { | ||
| "coefficients": self.model.coef_, | ||
| "intercept": self.model.intercept_, | ||
| "predictions": predictions, | ||
| "mse": mean_squared_error(y, predictions), | ||
| "r2": r2_score(y, predictions), | ||
| } | ||
|
|
||
| @property | ||
| def coef_(self): | ||
| """Get model coefficients.""" | ||
| return self.model.coef_ if self.is_fitted else None | ||
|
|
||
| @property | ||
| def intercept_(self): | ||
| """Get model intercept.""" | ||
| return self.model.intercept_ if self.is_fitted else None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok