diff --git a/chemfusekit/__base.py b/chemfusekit/__base.py index e024422..6d3fc8a 100644 --- a/chemfusekit/__base.py +++ b/chemfusekit/__base.py @@ -92,8 +92,15 @@ def __getitem__(self, index): class BaseSettings: """Holds the settings for all objects with settings.""" - def __init__(self, output: GraphMode = GraphMode.NONE): - self.output = output + def __init__(self, output: str = 'none'): + if output == 'none': + self.output = GraphMode.NONE + elif output == 'graphical': + self.output = GraphMode.GRAPHIC + elif output == 'text': + self.output = GraphMode.TEXT + else: + raise ValueError("The output mode should be 'none', 'graphical' or 'text'.") class BaseActionClass(ABC): @@ -145,9 +152,9 @@ def export_model(self, export_path: str): class BaseClassifierSettings(BaseSettings): """Holds the settings for the BaseClassifier object.""" - def __init__(self, output: GraphMode = GraphMode.NONE, test_split: bool = False): + def __init__(self, output: str = 'none', test_split: bool = False): super().__init__(output) - if test_split is True and output is GraphMode.NONE: + if test_split is True and self.output is GraphMode.NONE: raise Warning( "You selected test_split but it won't run because you disabled the output." ) diff --git a/chemfusekit/df.py b/chemfusekit/df.py index fb1ae04..89d58bc 100644 --- a/chemfusekit/df.py +++ b/chemfusekit/df.py @@ -7,7 +7,8 @@ import matplotlib.pyplot as plt -from .__base import GraphMode, BaseDataModel, BaseSettings +from .__base import BaseDataModel, BaseSettings +from .__utils import GraphMode from .pca import PCASettings, PCA from .plsda import PLSDASettings, PLSDA @@ -37,7 +38,7 @@ def __init__(self, x_data: pd.DataFrame, x_train: pd.DataFrame, y: np.ndarray, class DFSettings(BaseSettings): """Holds the settings for the DF object.""" - def __init__(self, output: GraphMode = GraphMode.NONE, method: str = 'concat'): + def __init__(self, output: str = 'none', method: str = 'concat'): super().__init__(output) if method not in ['concat', 'outer']: raise ValueError("DF: invalid method: must be 'concat' or 'outer'") diff --git a/chemfusekit/knn.py b/chemfusekit/knn.py index b74deaa..3a7cdf7 100644 --- a/chemfusekit/knn.py +++ b/chemfusekit/knn.py @@ -11,7 +11,7 @@ class KNNSettings(BaseClassifierSettings): """Holds the settings for the kNN object.""" def __init__(self, n_neighbors: int = 15, metric: str | Callable = 'euclidean', weights: str | Callable = 'uniform', - algorithm: str = 'auto', output: GraphMode = GraphMode.NONE, test_split: bool = False): + algorithm: str = 'auto', output: str = 'none', test_split: bool = False): super().__init__(output, test_split) @@ -68,7 +68,7 @@ def train(self): self.settings.output ) - if self.settings.test_split and self.settings.output: + if self.settings.test_split and self.settings.output is not GraphMode.NONE: knn_split = KNeighborsClassifier( n_neighbors=self.settings.n_neighbors, metric=self.settings.metric, diff --git a/chemfusekit/lda.py b/chemfusekit/lda.py index 87f8a73..ff7f112 100644 --- a/chemfusekit/lda.py +++ b/chemfusekit/lda.py @@ -9,8 +9,8 @@ from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LD from sklearn.model_selection import cross_val_score -from chemfusekit.__utils import graph_output, run_split_test -from chemfusekit.__utils import print_confusion_matrix, print_table, GraphMode +from chemfusekit.__utils import graph_output, run_split_test, GraphMode +from chemfusekit.__utils import print_confusion_matrix, print_table from .__base import BaseDataModel, BaseClassifier, BaseClassifierSettings, BaseReducer, ReducerDataModel @@ -25,7 +25,7 @@ def __init__(self, x_data: pd.DataFrame, x_train: pd.DataFrame, y: np.ndarray, c class LDASettings(BaseClassifierSettings): """Holds the settings for the LDA object.""" - def __init__(self, components: int | None = None, output: GraphMode = GraphMode.NONE, test_split: bool = False): + def __init__(self, components: int | None = None, output: str = 'none', test_split: bool = False): super().__init__(output, test_split) if components is not None and components <= 2: raise ValueError("Invalid component number: must be a > 1 integer.") diff --git a/chemfusekit/lr.py b/chemfusekit/lr.py index c28b345..d11dc30 100644 --- a/chemfusekit/lr.py +++ b/chemfusekit/lr.py @@ -5,13 +5,13 @@ import pandas as pd from sklearn.linear_model import LogisticRegression -from chemfusekit.__utils import run_split_test, print_confusion_matrix, print_table, GraphMode +from chemfusekit.__utils import run_split_test, print_confusion_matrix, print_table from .__base import BaseClassifierSettings, BaseDataModel, BaseClassifier, ReducerDataModel class LRSettings(BaseClassifierSettings): """Holds the settings for the LR object.""" - def __init__(self, algorithm: str = 'liblinear', output: GraphMode = GraphMode.NONE, test_split: bool = False): + def __init__(self, algorithm: str = 'liblinear', output: str = 'none', test_split: bool = False): super().__init__(output, test_split) if algorithm not in [ 'lbfgs', diff --git a/chemfusekit/pca.py b/chemfusekit/pca.py index ea0aefb..6f563f0 100644 --- a/chemfusekit/pca.py +++ b/chemfusekit/pca.py @@ -18,9 +18,8 @@ class PCASettings(BaseSettings): """Holds the settings for the PCA object.""" - def __init__(self, target_variance: float = 0.95, - confidence_level: float = 0.05, - initial_components: int = 10, output: GraphMode = GraphMode.NONE): + def __init__(self, target_variance: float = 0.95, confidence_level: float = 0.05, initial_components: int = 10, + output: str = 'none'): super().__init__(output) if target_variance < 0: raise ValueError("Target variance should be positive or null.") diff --git a/chemfusekit/plsda.py b/chemfusekit/plsda.py index 2eb05a8..fe92676 100644 --- a/chemfusekit/plsda.py +++ b/chemfusekit/plsda.py @@ -8,14 +8,14 @@ from sklearn.cross_decomposition import PLSRegression as PLSR from sklearn.model_selection import cross_val_score -from chemfusekit.__utils import GraphMode, print_table, print_confusion_matrix, run_split_test +from chemfusekit.__utils import print_table, print_confusion_matrix, run_split_test, GraphMode from .__base import BaseClassifierSettings, BaseDataModel, BaseClassifier, BaseReducer, ReducerDataModel class PLSDASettings(BaseClassifierSettings): """Holds the settings for the PLSDA object.""" - def __init__(self, components: int | None = None, output: GraphMode = GraphMode.NONE, test_split: bool = False): + def __init__(self, components: int | None = None, output: str = 'none', test_split: bool = False): super().__init__(output, test_split) if components is not None and components < 1: raise ValueError("Invalid n_components number: should be a positive integer.") @@ -136,7 +136,7 @@ def train(self): if self.settings.output and self.settings.test_split: x = self.data.x_data y = self.data.x_train.Substance.astype('category').cat.codes - run_split_test(x, y, PLSR(self.settings.components), mode=self.settings.output) + run_split_test(x, y, PLSR(self.components), mode=self.settings.output) def _select_feature_number(self, x, y): # Auto-select the number of components diff --git a/chemfusekit/svm.py b/chemfusekit/svm.py index 6114eec..aaf4836 100644 --- a/chemfusekit/svm.py +++ b/chemfusekit/svm.py @@ -3,13 +3,13 @@ from sklearn.svm import SVC -from chemfusekit.__utils import GraphMode, run_split_test, print_confusion_matrix +from chemfusekit.__utils import run_split_test, print_confusion_matrix from .__base import BaseClassifierSettings, BaseClassifier, BaseDataModel class SVMSettings(BaseClassifierSettings): """Holds the settings for the SVM object.""" - def __init__(self, kernel: str = 'linear', output: GraphMode = GraphMode.NONE, test_split: bool = False): + def __init__(self, kernel: str = 'linear', output: str = 'none', test_split: bool = False): super().__init__(output, test_split) if kernel not in ['linear', 'poly', 'gaussian', 'sigmoid']: raise ValueError("Invalid type: must be linear, poly, gaussian or sigmoid") diff --git a/docs/docs/base/basesettings.md b/docs/docs/base/basesettings.md index 76b28b0..aea815f 100644 --- a/docs/docs/base/basesettings.md +++ b/docs/docs/base/basesettings.md @@ -10,11 +10,11 @@ Holds the settings for all classifier object. It's not meant for direct usage, o ## Syntax ```python -BaseSettings(output: GraphMode, test_split: false) +BaseSettings(output: str, test_split: false) ``` ## Fields and constructor parameters -- `output`: toggles graph output mode. Defaults to [`GraphMode.NONE`](../utils/graphmode.md). +- `output`: toggles graph output. Defaults to [`none`] (other options: 'graphical', 'text'). Gets implicitly converted to a [`GraphMode` enum](../utils/graphmode.md). - `test_split`: toggles the training split test phase. Defaults to `False`. Requires `output` to be set to `True` to work. The constructor raises: diff --git a/docs/docs/base/reducerdatamodel.md b/docs/docs/base/reducerdatamodel.md index 09df8c5..2fe49b9 100644 --- a/docs/docs/base/reducerdatamodel.md +++ b/docs/docs/base/reducerdatamodel.md @@ -5,9 +5,9 @@ sidebar-position: 6 # ReducerDataModel class -This class models the output data for all dimensionality reduction operations (currently, the [`LDA`](../lda/lda), the [`PLSDA`](../plsda/plsda.md) and the [`PCA`](../pca/pca.md) operations). +This class models the output data for all dimensionality reduction operations (currently, the [`LDA`](../lda/lda.md), the [`PLSDA`](../plsda/plsda.md) and the [`PCA`](../pca/pca.md) operations). -It inherits from [`BaseDataModel`](../base/basedatamodel.md). +It inherits from [`BaseDataModel`](./basedatamodel.md). ## Syntax diff --git a/docs/docs/complete-workflow.md b/docs/docs/complete-workflow.md index f607520..d8a9f38 100644 --- a/docs/docs/complete-workflow.md +++ b/docs/docs/complete-workflow.md @@ -5,25 +5,25 @@ sidebar-position: 7 # Complete workflow Here's a sequence diagram to represent an example workflow, from the raw data -tables to classification, including data fusion, PCA and training. +tables to classification, including data fusion, dimensionality reduction and training. ```plantuml actor User -participant LLDF -participant PCA +participant DF +participant Reducer participant Classifier -User -> LLDF : Upload training tables -User -> LLDF : Set parameters +User -> DF : Upload training tables +User -> DF : Set parameters User -> Classifier : (optional) Upload model -LLDF -> PCA : Pass preprocessed / fused tables -LLDF --> User : Download fused tables -LLDF -> Classifier : Pass preprocessed / fused tables \nRun classification -PCA -> Classifier : (optional) Set number of components +DF -> Reducer : Pass preprocessed / fused tables +DF --> User : Download fused tables +DF -> Classifier : Pass preprocessed / fused tables \nRun classification +Reducer -> Classifier : (optional) Set number of components Classifier --> User : classification results, graphs -PCA --> User : classification results, graphs +Reducer --> User : classification results, graphs Classifier --> User : (optional) download trained model User -> Classifier : pass data to classify diff --git a/docs/docs/df/dfsettings.md b/docs/docs/df/dfsettings.md index a82f1f2..e6c20aa 100644 --- a/docs/docs/df/dfsettings.md +++ b/docs/docs/df/dfsettings.md @@ -2,18 +2,18 @@ sidebar_position: 2 --- -# LLDFSettings class +# DFSettings class Holds the settings for the [`DF`](./df-class.md) object. ## Syntax ```python -DFSettings(output: GraphMode, method: str) +DFSettings(output: str, method: str) ``` ## Fields and constructor parameters -- `output`: toggles graph output. Defaults to [`GraphMode.NONE`](../utils/graphmode.md). +- `output`: toggles graph output. Defaults to [`none`] (other options: 'graphical', 'text'). Gets implicitly converted to a [`GraphMode` enum](../utils/graphmode.md). - `method`: a choice between `concat` (concatenation-based data fusion) and `outer` (outer matrix multiplication-based data fusion) The constructor raises a `ValueError("DF: invalid method: must be 'concat' or 'outer'")` if an invalid parameter is provided to the `method` field. @@ -24,5 +24,5 @@ The constructor raises a `ValueError("DF: invalid method: must be 'concat' or 'o from chemfusekit.df import DFSettings # Initialize the settings for low-level data fusion -df_settings = DFSettings(output=GraphMode.TEXT) +df_settings = DFSettings(output='text') ``` \ No newline at end of file diff --git a/docs/docs/knn/knn.md b/docs/docs/knn/knn.md index 01dafcf..556c992 100644 --- a/docs/docs/knn/knn.md +++ b/docs/docs/knn/knn.md @@ -20,9 +20,9 @@ KNN(settings: KNNSettings, data: LLDFModel) ## Fields -- `settings`: object of type [`KNNSettings`](/tesi/docs/knn/knnsettings). Contains the settings for +- `settings`: object of type [`KNNSettings`](./knnsettings.md). Contains the settings for the `KNN` object. -- `data`: onject of type ['DFModel`](/tesi/docs/df/dfmodel). Contains the +- `data`: onject of type ['DFModel`](../df/dfmodel.md). Contains the artifacts from the data fusion process. - `model`: a `KNeighborsClassifier` model from `scikit-learn`. Defaults to `None`. diff --git a/docs/docs/knn/knnsettings.md b/docs/docs/knn/knnsettings.md index 81f9486..806d216 100644 --- a/docs/docs/knn/knnsettings.md +++ b/docs/docs/knn/knnsettings.md @@ -16,7 +16,7 @@ KNNSettings( metric: str | Callable, weights: str | Callable, algorithm: str, - output: GraphMode, + output: str, test_split: false ) ``` @@ -38,7 +38,7 @@ KNNSettings( - `kd_tree` - `brute` or be a callable object. -- `output`: toggles graph output mode. Defaults to [`GraphMode.NONE`](../utils/graphmode.md). +- `output`: toggles graph output. Defaults to [`none`] (other options: 'graphical', 'text'). Gets implicitly converted to a [`GraphMode` enum](../utils/graphmode.md). - `test_split`: toggles the training split test phase. Defaults to `False`. Requires `output` to be set to `True` to work. The constructor raises: @@ -51,14 +51,14 @@ The constructor raises: ## Example ```python -from chemfusekit.knn import KNNSettings, GraphMode +from chemfusekit.knn import KNNSettings settings = KNNSettings( n_neighbors=20, # pick 20 neighbors - metric='minkowski', # choose the metric - weights='distance', # choose the weight metric + metric='minkowski', # choose the metric + weights='distance', # choose the weight metric algorithm='auto', # the best algorithm gets chosen automatically - output=GraphMode.GRAPHIC, # graph output is enabled - test_split=True # the model will be split-tested at the end of the training + output='graphical', # graph output is enabled + test_split=True # the model will be split-tested at the end of the training ) ``` \ No newline at end of file diff --git a/docs/docs/lda/ldasettings.md b/docs/docs/lda/ldasettings.md index c9c850e..db7d26b 100644 --- a/docs/docs/lda/ldasettings.md +++ b/docs/docs/lda/ldasettings.md @@ -11,13 +11,13 @@ Inherits from [`BaseSettings`](../base/basesettings.md). ## Syntax ```python -LDASettings(components: int, output: GraphMode, split_test: bool) +LDASettings(components: int, output: str, split_test: bool) ``` ## Fields and constructor parameters - `components`: the amount of components to be used in the LDA model. Defaults to 3. -- `output`: toggles graph output. Defaults to [`GraphMode.NONE`](../utils/graphmode.md). +- `output`: toggles graph output. Defaults to [`none`] (other options: 'graphical', 'text'). Gets implicitly converted to a [`GraphMode` enum](../utils/graphmode.md). - `test_split`: toggles split testing. Defaults to `False`. @@ -29,11 +29,11 @@ The constructor raises: ## Example ```python -from chemfusekit.lda import LDASettings, GraphMode +from chemfusekit.lda import LDASettings settings = LDASettings( components=(pca.components - 1), # one less component than the number determined by PCA - output=GraphMode.GRAPHIC, # graphs will be printed - test_split=True # split testing is enabled + output='graphical', # graphs will be printed + test_split=True # split testing is enabled ) ``` \ No newline at end of file diff --git a/docs/docs/lr/lrsettings.md b/docs/docs/lr/lrsettings.md index 847c002..7508a26 100644 --- a/docs/docs/lr/lrsettings.md +++ b/docs/docs/lr/lrsettings.md @@ -11,7 +11,7 @@ Inherits from [`BaseSettings`](../base/basesettings.md). ## Syntax ```python -LRSettings(algorithm: str, output: GraphMode, test_split: bool) +LRSettings(algorithm: str, output: str, test_split: bool) ``` ## Fields and constructor parameters @@ -23,7 +23,7 @@ LRSettings(algorithm: str, output: GraphMode, test_split: bool) - `newton-cholesky` - `sag` - `saga` -- `output`: toggles graph output. Defaults to [`GraphMode.NONE`](../utils/graphmode.md). +- `output`: toggles graph output. Defaults to [`none`] (other options: 'graphical', 'text'). Gets implicitly converted to a [`GraphMode` enum](../utils/graphmode.md). - `test_split`: toggles split testing. Defaults to `False`. The constructor raises: @@ -34,11 +34,11 @@ The constructor raises: ## Example ```python -from chemfusekit.lr import LRSettings, GraphMode +from chemfusekit.lr import LRSettings settings = LRSettings( algorithm='newton-cg', - output=GraphMode.GRAPHIC, # graphs will be printed - test_split=True # split testing is enabled + output='graphical', # graphs will be printed + test_split=True # split testing is enabled ) ``` \ No newline at end of file diff --git a/docs/docs/pca/pca.md b/docs/docs/pca/pca.md index b3d427e..4618fd1 100644 --- a/docs/docs/pca/pca.md +++ b/docs/docs/pca/pca.md @@ -21,7 +21,7 @@ PCA(settings: PCASettings, data: BaseDataModel) ## Fields -- `data`: object of type [`BaseDataModel`](../base/basedatamodel.md.md). Contains the data to be analyzed. +- `data`: object of type [`BaseDataModel`](../base/basedatamodel.md). Contains the data to be analyzed. - `components`: Number of components for the PCA analysis. Defaults to 0. - `model`: A `PCA` model from `scikit-learn`. Defaults to `None`. - `settings`: object of type [`PCASettings`](./pcasettings.md). Contains the settings for diff --git a/docs/docs/pca/pcasettings.md b/docs/docs/pca/pcasettings.md index ca533ea..72d8a38 100644 --- a/docs/docs/pca/pcasettings.md +++ b/docs/docs/pca/pcasettings.md @@ -13,7 +13,7 @@ PCASettings( target_variance: float, confidence_level: float, initial_components: int, - output: GraphMode + output: str ) ``` @@ -24,18 +24,18 @@ PCASettings( - `confidence_level`: the confidence level for statistical tests. Defaults to 0.05. - `initial_components`: the minimum amount of components to be used in the PCA model. Defaults to 10. -- `output`: toggles graph output. Defaults to [`GraphMode.NONE`](../utils/graphmode.md). +- `output`: toggles graph output. Defaults to [`none`] (other options: 'graphical', 'text'). Gets implicitly converted to a [`GraphMode` enum](../utils/graphmode.md). ## Example ```python -from chemfusekit.pca import PCASettings, GraphMode +from chemfusekit.pca import PCASettings # Initialize the settings for Principal Component Analysis pca_settings = PCASettings( target_variance=0.99, confidence_level=0.05, initial_components=10, - output=GraphMode.GRAPHIC # graphs will be printed + output='graphical' # graphs will be printed ) ``` \ No newline at end of file diff --git a/docs/docs/plsda/plsda.md b/docs/docs/plsda/plsda.md index ca2655d..376317d 100644 --- a/docs/docs/plsda/plsda.md +++ b/docs/docs/plsda/plsda.md @@ -24,7 +24,7 @@ PLSDA(settings: PLSDASettings, data: BaseDataModel) - `settings`: object of type [`PLSDASettings`](./plsdasettings.md). Contains the settings for the `PLSDA` object. -- `data`: object of type [`BaseDataModel`](../base/basedatamodel.md.md). Contains the data to be analyzed. +- `data`: object of type [`BaseDataModel`](../base/basedatamodel.md). Contains the data to be analyzed. - `model`: a `PLSRegression` model from `scikit-learn`. Defaults to `None`. ## Methods diff --git a/docs/docs/plsda/plsdasettings.md b/docs/docs/plsda/plsdasettings.md index 7b547a7..5120699 100644 --- a/docs/docs/plsda/plsdasettings.md +++ b/docs/docs/plsda/plsdasettings.md @@ -11,13 +11,13 @@ Inherits from [`BaseSettings`](../base/basesettings.md). ## Syntax ```python -PLSDASettings(n_components: int, output: GraphMode, test_split: bool) +PLSDASettings(n_components: int, output: str, test_split: bool) ``` ## Fields and constructor parameters - `n_components`: number of components for the PLSDA analysis. Defaults to 3. -- `output`: toggles graph output. Defaults to [`GraphMode.NONE`](../utils/graphmode.md). +- `output`: toggles graph output. Defaults to [`none`] (other options: 'graphical', 'text'). Gets implicitly converted to a [`GraphMode` enum](../utils/graphmode.md). - `test_split`: toggles the training split test phase. Defaults to `False`. Requires `output` to not be set to `GraphMode.NONE` to work. The constructor raises: @@ -27,12 +27,12 @@ The constructor raises: ## Example ```python -from chemfusekit.plsda import PLSDASettings, GraphMode +from chemfusekit.plsda import PLSDASettings # Initialize the settings for Partial Least Squares Discriminant Analysis plsda_settings = PLSDASettings( n_components=5, - output=GraphMode.GRAPHIC, # graphs will be printed + output='graphical', # graphs will be printed test_split=False # no split testing ) ``` \ No newline at end of file diff --git a/docs/docs/svm/svmsettings.md b/docs/docs/svm/svmsettings.md index 7ebf852..1c72b57 100644 --- a/docs/docs/svm/svmsettings.md +++ b/docs/docs/svm/svmsettings.md @@ -11,7 +11,7 @@ Inherits from [`BaseSettings`](../base/basesettings.md). ## Syntax ```python -SVMSettings(kernel: str, output: GraphMode, test_split: bool) +SVMSettings(kernel: str, output: str, test_split: bool) ``` ## Fields and constructor parameters @@ -22,7 +22,7 @@ SVMSettings(kernel: str, output: GraphMode, test_split: bool) - `gaussian` - `sigmoid` Defaults to `linear`. -- `output`: toggles graph output. Defaults to [`GraphMode.NONE`](../utils/graphmode.md). +- `output`: toggles graph output. Defaults to [`none`] (other options: 'graphical', 'text'). Gets implicitly converted to a [`GraphMode` enum](../utils/graphmode.md). - `test_split`: toggles split testing. Defaults to `False`. The constructor raises: @@ -32,12 +32,12 @@ The constructor raises: ## Example ```python -from chemfusekit.svm import SVMSettings, GraphMode +from chemfusekit.svm import SVMSettings # Initialize the settings for Support Vector Machine svm_settings = SVMSettings( type='linear', - output=GraphMode.GRAPHIC, # graphs will be printed - test_split=True # split testing is enabled + output='graphical', # graphs will be printed + test_split=True # split testing is enabled ) ``` \ No newline at end of file diff --git a/docs/docs/tutorial.md b/docs/docs/tutorial.md index 163fa6a..3fa0407 100644 --- a/docs/docs/tutorial.md +++ b/docs/docs/tutorial.md @@ -15,19 +15,19 @@ pip install chemfusekit ## First step: data fusion -We will load the `LLDFSettings` with the paths to some Excel datasheets, containing +We will load the `DFSettings` with the paths to some Excel datasheets, containing respectively the data from a QEPAS spectrometer and a GC chromatographer. We will pick normalization as the preprocessing technique for the data. -The `LLDF` class will take these settings and perform low-level data fusion on the +The `DF` class will take these settings and perform low-level data fusion on the two Excel tables we picked. ```python from chemfusekit.df import DFSettings, DF # Initialize the settings for low-level data fusion -lldf_settings = DFSettings( +df_settings = DFSettings( qepas_path='tests/qepas.xlsx', qepas_sheet='Sheet1', rt_path='tests/rt.xlsx', @@ -36,15 +36,15 @@ lldf_settings = DFSettings( ) # Initialize and run low-level data fusion -lldf = DF(lldf_settings) -lldf.lldf() +df = DF(df_settings) +df.train() ``` Optionally, we can export the fused data into a new, single Excel datasheet: ```python # (optional) export the LLDF data to an Excel file -lldf.export_data('output_file.xlsx') +df.export_data('output_file.xlsx') ``` ## Second step: PCA @@ -62,11 +62,11 @@ pca_settings = PCASettings( target_variance=0.99, # the minimum acceptable level of cumulative explained covariance confidence_level=0.05, # the desired level of confidence initial_components=10, # the initial amount of components for the iterative analysis - output=GraphMode.GRAPHIC # graphs will be printed + output='graphical' # graphs will be printed ) # Initialize and run the PCA class -pca = PCA(lldf.fused_data, pca_settings) +pca = PCA(df.fused_data, pca_settings) pca.train() # Print the number of components and the statistics @@ -84,12 +84,12 @@ from chemfusekit.lda import LDASettings, LDA settings = LDASettings( components=(pca.components - 1), # one less component than the number determined by PCA - output=GraphMode.GRAPHIC, # graphs will be printed + output='graphical', # graphs will be printed test_split=True # Split testing is enabled ) # Initialize and run the LDA class -lda = LDA(lldf.fused_data, settings) +lda = LDA(df.fused_data, settings) lda.train() ``` @@ -100,8 +100,7 @@ can identify it correctly. ```python # Let's pick a random sample from the dataset and see if it gets recognized correctly: -x_data_sample = lldf.fused_data.x_train.iloc[119] # should be DMMP -x_data_sample = x_data_sample.iloc[1:].to_frame().transpose() +x_data_sample = lldf.fused_data[119] # should be DMMP # Let's run the prediction: predictions = lda.predict(x_data_sample) diff --git a/examples/knn_notebook.ipynb b/examples/knn_notebook.ipynb index 57a54ce..971e381 100644 --- a/examples/knn_notebook.ipynb +++ b/examples/knn_notebook.ipynb @@ -74,9 +74,9 @@ "metadata": {}, "source": [ "## First step: Low-Level Data Fusion\n", - "- the `LLDF` class is used for data fusion\n", - "- the `LLDF_Settings` class is a helper class for setting up `LLDF`\n", - "- `LLDF` data can then be exported, or used for further processing" + "- the `DF` class is used for data fusion\n", + "- the `DFSettings` class is a helper class for setting up `DF`\n", + "- `DF` data can then be exported, or used for further processing" ] }, { @@ -106,11 +106,11 @@ } ], "source": [ - "from chemfusekit.lldf import LLDFSettings, LLDF, Table, GraphMode\n", + "from chemfusekit.df import DFSettings, DF, Table\n", "\n", "# Initialize the settings for low-level data fusion\n", "# Perform preliminary data fusion\n", - "lldf_settings = LLDFSettings(output=GraphMode.GRAPHIC)\n", + "df_settings = DFSettings(output='graphical')\n", "qepas_table = Table(\n", " file_path=\"qepas.xlsx\",\n", " sheet_name=\"Sheet1\",\n", @@ -125,8 +125,8 @@ "tables = [qepas_table, rt_table]\n", "\n", "# Initialize and run low-level data fusion\n", - "lldf = LLDF(lldf_settings, tables)\n", - "lldf.lldf()" + "df = DF(df_settings, tables)\n", + "df.fuse()" ] }, { @@ -136,7 +136,7 @@ "outputs": [], "source": [ "# (optional) export the LLDF data to an Excel file\n", - "lldf.export_data('output_file.xlsx')" + "df.export_data('output_file.xlsx')" ] }, { @@ -3415,7 +3415,7 @@ } ], "source": [ - "from chemfusekit.knn import KNNSettings, KNN, GraphMode\n", + "from chemfusekit.knn import KNNSettings, KNN\n", "\n", "# Initialize the settings for Principal Component Analysis\n", "knn_settings = KNNSettings(\n", @@ -3423,13 +3423,13 @@ " metric='euclidean',\n", " weights='uniform',\n", " algorithm='auto',\n", - " output=GraphMode.GRAPHIC, # graphs will be printed as pictures\n", + " output='graphical', # graphs will be printed as pictures\n", " test_split=True # Split testing will be carried out\n", ")\n", "\n", "# Initialize and run the PCA class\n", - "knn = KNN(settings=knn_settings, data=lldf.fused_data)\n", - "knn.knn()" + "knn = KNN(settings=knn_settings, data=df.fused_data)\n", + "knn.train()" ] }, { @@ -3456,7 +3456,7 @@ ], "source": [ "# Let's pick a random sample and see if it gets recognized correctly:\n", - "x_data_sample = lldf.fused_data[119] # should be DMMP\n", + "x_data_sample = df.fused_data[119] # should be DMMP\n", "\n", "# Let's run the prediction:\n", "predictions = knn.predict(x_data_sample)\n", diff --git a/examples/pca_lda_notebook.ipynb b/examples/pca_lda_notebook.ipynb index 4016dc2..7d96276 100644 --- a/examples/pca_lda_notebook.ipynb +++ b/examples/pca_lda_notebook.ipynb @@ -74,9 +74,9 @@ "metadata": {}, "source": [ "## First step: Low-Level Data Fusion\n", - "- the `LLDF` class is used for data fusion\n", - "- the `LLDF_Settings` class is a helper class for setting up `LLDF`\n", - "- `LLDF` data can then be exported, or used for further processing" + "- the `DF` class is used for data fusion\n", + "- the `DFSettings` class is a helper class for setting up `DF`\n", + "- `DF` data can then be exported, or used for further processing" ] }, { @@ -106,11 +106,11 @@ } ], "source": [ - "from chemfusekit.lldf import LLDFSettings, LLDF, Table, GraphMode\n", + "from chemfusekit.df import DFSettings, DF, Table\n", "\n", "# Initialize the settings for low-level data fusion\n", "# Perform preliminary data fusion\n", - "lldf_settings = LLDFSettings(output=GraphMode.GRAPHIC)\n", + "df_settings = DFSettings(output='graphical')\n", "qepas_table = Table(\n", " file_path=\"qepas.xlsx\",\n", " sheet_name=\"Sheet1\",\n", @@ -125,8 +125,8 @@ "tables = [qepas_table, rt_table]\n", "\n", "# Initialize and run low-level data fusion\n", - "lldf = LLDF(lldf_settings, tables)\n", - "lldf.lldf()" + "df = DF(df_settings, tables)\n", + "df.fuse()" ] }, { @@ -136,7 +136,7 @@ "outputs": [], "source": [ "# (optional) export the LLDF data to an Excel file\n", - "lldf.export_data('output_file.xlsx')" + "df.export_data('output_file.xlsx')" ] }, { @@ -25582,19 +25582,19 @@ } ], "source": [ - "from chemfusekit.pca import PCASettings, PCA, GraphMode\n", + "from chemfusekit.pca import PCASettings, PCA\n", "\n", "# Initialize the settings for Principal Component Analysis\n", "pca_settings = PCASettings(\n", " target_variance=0.99,\n", " confidence_level=0.05,\n", " initial_components=10,\n", - " output=GraphMode.GRAPHIC # graphs will be printed as pictures\n", + " output='graphical' # graphs will be printed as pictures\n", ")\n", "\n", "# Initialize and run the PCA class\n", - "pca = PCA(pca_settings, lldf.fused_data)\n", - "pca.pca()\n", + "pca = PCA(pca_settings, df.fused_data)\n", + "pca.train()\n", "\n", "# Print the number of components and the statistics\n", "print(f\"\\nNumber of components: {pca.components}\\n\")\n", @@ -47180,16 +47180,16 @@ } ], "source": [ - "from chemfusekit.lda import LDASettings, LDA, GraphMode\n", + "from chemfusekit.lda import LDASettings, LDA\n", "\n", "settings = LDASettings(\n", - " output=GraphMode.GRAPHIC, # Graphs will be printed\n", + " output='graphical', # Graphs will be printed\n", " test_split=True # Run split test\n", ")\n", "\n", "# Initialize and run the LDA class\n", "lda = LDA(settings, pca_data) # components will be determined automatically from the PCA data\n", - "lda.lda()" + "lda.train()" ] }, { @@ -47216,7 +47216,7 @@ ], "source": [ "# Let's pick a random sample and see if it gets recognized correctly:\n", - "x_data_sample = lldf.fused_data[119] # should be DMMP\n", + "x_data_sample = df.fused_data[119] # should be DMMP\n", "\n", "# Let's run the prediction:\n", "predictions = lda.predict(x_data_sample)\n", diff --git a/examples/pca_lr_notebook.ipynb b/examples/pca_lr_notebook.ipynb index 1dbf2e6..2938628 100644 --- a/examples/pca_lr_notebook.ipynb +++ b/examples/pca_lr_notebook.ipynb @@ -74,9 +74,9 @@ "metadata": {}, "source": [ "## First step: Low-Level Data Fusion\n", - "- the `LLDF` class is used for data fusion\n", - "- the `LLDF_Settings` class is a helper class for setting up `LLDF`\n", - "- `LLDF` data can then be exported, or used for further processing" + "- the `DF` class is used for data fusion\n", + "- the `DFSettings` class is a helper class for setting up `DF`\n", + "- `DF` data can then be exported, or used for further processing" ] }, { @@ -106,11 +106,11 @@ } ], "source": [ - "from chemfusekit.lldf import LLDFSettings, LLDF, Table, GraphMode\n", + "from chemfusekit.df import DFSettings, DF, Table\n", "\n", "# Initialize the settings for low-level data fusion\n", "# Perform preliminary data fusion\n", - "lldf_settings = LLDFSettings(output=GraphMode.GRAPHIC)\n", + "df_settings = DFSettings(output='graphical')\n", "qepas_table = Table(\n", " file_path=\"qepas.xlsx\",\n", " sheet_name=\"Sheet1\",\n", @@ -125,8 +125,8 @@ "tables = [qepas_table, rt_table]\n", "\n", "# Initialize and run low-level data fusion\n", - "lldf = LLDF(lldf_settings, tables)\n", - "lldf.lldf()" + "df = DF(df_settings, tables)\n", + "df.fuse()" ] }, { @@ -136,7 +136,7 @@ "outputs": [], "source": [ "# (optional) export the LLDF data to an Excel file\n", - "lldf.export_data('output_file.xlsx')" + "df.export_data('output_file.xlsx')" ] }, { @@ -25582,19 +25582,19 @@ } ], "source": [ - "from chemfusekit.pca import PCASettings, PCA, GraphMode\n", + "from chemfusekit.pca import PCASettings, PCA\n", "\n", "# Initialize the settings for Principal Component Analysis\n", "pca_settings = PCASettings(\n", " target_variance=0.99,\n", " confidence_level=0.05,\n", " initial_components=10,\n", - " output=GraphMode.GRAPHIC # graphs will be printed as pictures\n", + " output='graphical' # graphs will be printed as pictures\n", ")\n", "\n", - "# Initialize and run the PCA class\n", - "pca = PCA(pca_settings, lldf.fused_data)\n", - "pca.pca()\n", + "# Initialize and train the PCA class\n", + "pca = PCA(pca_settings, df.fused_data)\n", + "pca.train()\n", "\n", "# Print the number of components and the statistics\n", "print(f\"\\nNumber of components: {pca.components}\\n\")\n", @@ -50119,20 +50119,20 @@ } ], "source": [ - "from chemfusekit.lr import LRSettings, LR, GraphMode\n", + "from chemfusekit.lr import LRSettings, LR\n", "\n", "settings = LRSettings(\n", " algorithm='liblinear',\n", - " output=GraphMode.GRAPHIC, # graphs will be printed as pictures\n", + " output='graphical', # graphs will be printed as pictures\n", " test_split=True # Run split test\n", ")\n", "\n", - "# Initialize and run the LDA class\n", + "# Initialize and train the LDA class\n", "lr = LR(\n", " settings=settings,\n", " data=pca_data # use the data from PCA\n", ")\n", - "lr.lr()" + "lr.train()" ] }, { @@ -51045,10 +51045,8 @@ } ], "source": [ - "import pandas as pd\n", - "\n", "# Let's pick a random sample and see if it gets recognized correctly:\n", - "reduced_dataset = pca.reduce(lldf.fused_data) # Reduce the dimensionality of the samples\n", + "reduced_dataset = pca.reduce(df.fused_data) # Reduce the dimensionality of the samples\n", "x_data_sample = reduced_dataset[119] # Should be DMMP\n", "\n", "# Let's run the prediction:\n", diff --git a/examples/plsda_notebook.ipynb b/examples/plsda_notebook.ipynb index b1a0b52..3ba4c8f 100644 --- a/examples/plsda_notebook.ipynb +++ b/examples/plsda_notebook.ipynb @@ -74,9 +74,9 @@ "metadata": {}, "source": [ "## First step: Low-Level Data Fusion\n", - "- the `LLDF` class is used for data fusion\n", - "- the `LLDF_Settings` class is a helper class for setting up `LLDF`\n", - "- `LLDF` data can then be exported, or used for further processing" + "- the `DF` class is used for data fusion\n", + "- the `DFSettings` class is a helper class for setting up `DF`\n", + "- `DF` data can then be exported, or used for further processing" ] }, { @@ -106,11 +106,11 @@ } ], "source": [ - "from chemfusekit.lldf import LLDFSettings, LLDF, Table, GraphMode\n", + "from chemfusekit.df import DFSettings, DF, Table\n", "\n", "# Initialize the settings for low-level data fusion\n", "# Perform preliminary data fusion\n", - "lldf_settings = LLDFSettings(output=GraphMode.GRAPHIC)\n", + "df_settings = DFSettings(output='graphical')\n", "qepas_table = Table(\n", " file_path=\"qepas.xlsx\",\n", " sheet_name=\"Sheet1\",\n", @@ -125,8 +125,8 @@ "tables = [qepas_table, rt_table]\n", "\n", "# Initialize and run low-level data fusion\n", - "lldf = LLDF(lldf_settings, tables)\n", - "lldf.lldf()" + "df = DF(df_settings, tables)\n", + "df.fuse()" ] }, { @@ -136,7 +136,7 @@ "outputs": [], "source": [ "# (optional) export the LLDF data to an Excel file\n", - "lldf.export_data('output_file.xlsx')" + "df.export_data('output_file.xlsx')" ] }, { @@ -18166,17 +18166,17 @@ } ], "source": [ - "from chemfusekit.plsda import PLSDASettings, PLSDA, GraphMode\n", + "from chemfusekit.plsda import PLSDASettings, PLSDA\n", "\n", "# Initialize the settings for Principal Component Analysis\n", "plsda_settings = PLSDASettings(\n", " n_components=4, # Number of components\n", - " output=GraphMode.GRAPHIC, # graphs will be printed as pictures\n", + " output='graphical', # graphs will be printed as pictures\n", " test_split=True # Split testing will be carried out\n", ")\n", "\n", "# Initialize and run the PLSDA class\n", - "plsda = PLSDA(settings=plsda_settings, data=lldf.fused_data)\n", + "plsda = PLSDA(settings=plsda_settings, data=df.fused_data)\n", "plsda.plsda()" ] }, @@ -18202,7 +18202,7 @@ ], "source": [ "# Let's pick a random sample and see if it gets recognized correctly:\n", - "x_data_sample = lldf.fused_data[119] # should be DMMP\n", + "x_data_sample = df.fused_data[119] # should be DMMP\n", "\n", "# Let's run the prediction:\n", "predictions = plsda.predict(x_data_sample)\n", diff --git a/examples/svm_notebook.ipynb b/examples/svm_notebook.ipynb index 394f84c..c6ac2b5 100644 --- a/examples/svm_notebook.ipynb +++ b/examples/svm_notebook.ipynb @@ -33,9 +33,9 @@ "metadata": {}, "source": [ "## First step: Low-Level Data Fusion\n", - "- the `LLDF` class is used for data fusion\n", - "- the `LLDF_Settings` class is a helper class for setting up `LLDF`\n", - "- `LLDF` data can then be exported, or used for further processing" + "- the `DF` class is used for data fusion\n", + "- the `DFSettings` class is a helper class for setting up `DF`\n", + "- `DF` data can then be exported, or used for further processing" ] }, { @@ -44,11 +44,11 @@ "metadata": {}, "outputs": [], "source": [ - "from chemfusekit.lldf import LLDFSettings, LLDF, Table, GraphMode\n", + "from chemfusekit.df import DFSettings, DF, Table\n", "\n", "# Initialize the settings for low-level data fusion\n", "# Perform preliminary data fusion\n", - "lldf_settings = LLDFSettings(output=GraphMode.NONE)\n", + "df_settings = DFSettings(output='graphical')\n", "qepas_table = Table(\n", " file_path=\"tests/qepas.xlsx\",\n", " sheet_name=\"Sheet1\",\n", @@ -63,8 +63,8 @@ "tables = [qepas_table, rt_table]\n", "\n", "# Initialize and run low-level data fusion\n", - "lldf = LLDF(lldf_settings, tables)\n", - "lldf.lldf()" + "df = DF(df_settings, tables)\n", + "df.fuse()" ] }, { @@ -74,7 +74,7 @@ "outputs": [], "source": [ "# (optional) export the LLDF data to an Excel file\n", - "lldf.export_data('output_file.xlsx')" + "df.export_data('output_file.xlsx')" ] }, { @@ -2080,18 +2080,18 @@ } ], "source": [ - "from chemfusekit.svm import SVMSettings, SVM, GraphMode\n", + "from chemfusekit.svm import SVMSettings, SVM\n", "\n", "# Initialize the settings for Principal Component Analysis\n", "svm_settings = SVMSettings(\n", " kernel='poly', # Kernel type\n", - " output=GraphMode.GRAPHIC, # graphs will be printed as pictures\n", + " output='graphical', # graphs will be printed as pictures\n", " test_split=True # Split testing will be carried out\n", ")\n", "\n", - "# Initialize and run the SVM class\n", - "svm = SVM(settings=svm_settings, data=lldf.fused_data)\n", - "svm.svm()" + "# Initialize and train the SVM class\n", + "svm = SVM(settings=svm_settings, data=df.fused_data)\n", + "svm.train()" ] }, { @@ -2116,7 +2116,7 @@ ], "source": [ "# Let's pick a random sample and see if it gets recognized correctly:\n", - "x_data_sample = lldf.fused_data.x_train.iloc[119] # should be DMMP\n", + "x_data_sample = df.fused_data.x_train.iloc[119] # should be DMMP\n", "x_data_sample = x_data_sample.iloc[1:].to_frame().transpose()\n", "\n", "# Let's run the prediction:\n", diff --git a/tests/test_df.py b/tests/test_df.py index b21dd9d..9efa379 100644 --- a/tests/test_df.py +++ b/tests/test_df.py @@ -1,6 +1,6 @@ """This module contains the test cases for the LLDF module.""" import unittest -from chemfusekit.df import DFSettings, DF, GraphMode, Table +from chemfusekit.df import DFSettings, DF, Table class TestLLDF(unittest.TestCase): @@ -10,7 +10,7 @@ def test_file_loading(self): """Test case against file loading errors.""" # load a non-existent file on purpose settings = DFSettings( - output=GraphMode.NONE + output='none' ) table1 = Table( @@ -27,7 +27,7 @@ def test_preprocessing_techniques(self): """Test case against wrong preprocessing user input.""" with self.assertRaises(SyntaxError): settings = DFSettings( - output=GraphMode.NONE + output='none' ) table1 = Table( @@ -40,7 +40,7 @@ def test_preprocessing_techniques(self): df.fuse() # Now a correct value: - settings = DFSettings(output=GraphMode.NONE) + settings = DFSettings(output='none') table1 = Table( file_path='tests/qepas.xlsx', sheet_name='Sheet1', @@ -51,7 +51,7 @@ def test_preprocessing_techniques(self): def test_export(self): """Test case against wrong export settings.""" - settings = DFSettings(output=GraphMode.NONE) + settings = DFSettings(output='none') table1 = Table( file_path='tests/qepas.xlsx', sheet_name='Sheet1', @@ -74,7 +74,7 @@ def test_midlevel_data_fusion(self): """Integration test case for mid-level data fusion.""" # PCA - df_settings = DFSettings(output=GraphMode.GRAPHIC) + df_settings = DFSettings(output='graphical') table1 = Table( file_path='tests/qepas.xlsx', sheet_name='Sheet1', @@ -93,7 +93,7 @@ def test_midlevel_data_fusion(self): df.fuse() # PLSDA - df_settings = DFSettings(output=GraphMode.GRAPHIC) + df_settings = DFSettings(output='graphical') table1 = Table( file_path='tests/qepas.xlsx', sheet_name='Sheet1', diff --git a/tests/test_knn.py b/tests/test_knn.py index 2916c89..6a95fe4 100644 --- a/tests/test_knn.py +++ b/tests/test_knn.py @@ -4,7 +4,7 @@ import pandas as pd import numpy as np -from chemfusekit.knn import KNNSettings, KNN, GraphMode +from chemfusekit.knn import KNNSettings, KNN from chemfusekit.df import DFSettings, DF, DFDataModel, Table @@ -61,12 +61,12 @@ def test_knn_settings(self): # output and test_split incompatibilities with self.assertRaises(Warning): - KNNSettings(output=GraphMode.NONE, test_split=True) + KNNSettings(output='none', test_split=True) def test_knn_constructor(self): """Test case against constructor errors.""" # Perform preliminary data fusion - df_settings = DFSettings(output=GraphMode.NONE) + df_settings = DFSettings(output='none') table1 = Table( file_path="tests/qepas.xlsx", sheet_name="Sheet1", @@ -94,7 +94,7 @@ def test_knn_constructor(self): def test_knn(self): """Integration test case for the training function.""" # Perform preliminary data fusion - df_settings = DFSettings(output=GraphMode.NONE) + df_settings = DFSettings(output='none') table1 = Table( file_path="tests/qepas.xlsx", sheet_name="Sheet1", @@ -114,19 +114,19 @@ def test_knn(self): knn.train() # With graph output - knn_settings = KNNSettings(output=GraphMode.GRAPHIC) + knn_settings = KNNSettings(output='graphical') knn = KNN(knn_settings, df.fused_data) knn.train() # With text output - knn_settings = KNNSettings(output=GraphMode.TEXT) + knn_settings = KNNSettings(output='text') knn = KNN(knn_settings, df.fused_data) knn.train() def test_prediction(self): """Test case against prediction parameter issues.""" # Perform preliminary data fusion - df_settings = DFSettings(output=GraphMode.NONE) + df_settings = DFSettings(output='none') table1 = Table( file_path="tests/qepas.xlsx", sheet_name="Sheet1", diff --git a/tests/test_lda.py b/tests/test_lda.py index 828465d..d192cf6 100644 --- a/tests/test_lda.py +++ b/tests/test_lda.py @@ -11,16 +11,16 @@ def test_lda_settings(self): """Test case against settings errors.""" # Check for negative component rejection with self.assertRaises(ValueError): - LDASettings(components=-3, output=GraphMode.TEXT) + LDASettings(components=-3, output='text') # Check if split tests with no output cause warnings: with self.assertRaises(Warning): - LDASettings(output=GraphMode.NONE, test_split=True) + LDASettings(output='none', test_split=True) def test_lda_constructor(self): """Test case against constructor parameter issues.""" # Perform preliminary data fusion - df_settings = DFSettings(output=GraphMode.NONE) + df_settings = DFSettings(output='none') table1 = Table( file_path="tests/qepas.xlsx", sheet_name="Sheet1", @@ -54,7 +54,7 @@ def test_lda_constructor(self): def test_lda(self): """Integration test case.""" # Perform preliminary data fusion - df_settings = DFSettings(output=GraphMode.NONE) + df_settings = DFSettings(output='none') table1 = Table( file_path="tests/qepas.xlsx", sheet_name="Sheet1", @@ -69,22 +69,22 @@ def test_lda(self): df.fuse() # Create an LDA object and train it, with graphical output - lda_settings = LDASettings(output=GraphMode.GRAPHIC) + lda_settings = LDASettings(output='graphical') lda = LDA(lda_settings, df.fused_data) lda.train() # Create an LDA object and train it, with text output - lda_settings = LDASettings(output=GraphMode.TEXT) + lda_settings = LDASettings(output='text') lda = LDA(lda_settings, df.fused_data) lda.train() # Create an LDA object and train it, with no output - lda_settings = LDASettings(output=GraphMode.NONE) + lda_settings = LDASettings(output='none') lda = LDA(lda_settings, df.fused_data) lda.train() # Create an LDA object and train it, with true output and split tests - lda_settings = LDASettings(output=GraphMode.TEXT, test_split=True) + lda_settings = LDASettings(output='text', test_split=True) lda = LDA(lda_settings, df.fused_data) lda.train() @@ -92,7 +92,7 @@ def test_lda_predict(self): """Test case against prediction parameter issues.""" # Perform preliminary data fusion - df_settings = DFSettings(output=GraphMode.NONE) + df_settings = DFSettings(output='none') table1 = Table( file_path="tests/qepas.xlsx", sheet_name="Sheet1", diff --git a/tests/test_lr.py b/tests/test_lr.py index c9024ea..69c56f6 100644 --- a/tests/test_lr.py +++ b/tests/test_lr.py @@ -6,7 +6,7 @@ from chemfusekit.df import DFSettings, DF, Table from chemfusekit.pca import PCASettings, PCA -from chemfusekit.lr import LRSettings, LR, GraphMode +from chemfusekit.lr import LRSettings, LR from chemfusekit.__base import ReducerDataModel @@ -19,7 +19,7 @@ def test_lr_settings(self): with self.assertRaises(ValueError): LRSettings( algorithm='unknown', - output=GraphMode.NONE, + output='none', test_split=False ) @@ -27,7 +27,7 @@ def test_lr_settings(self): with self.assertRaises(TypeError): LRSettings( algorithm=None, - output=GraphMode.NONE, + output='none', test_split=True ) with self.assertRaises(TypeError): @@ -39,18 +39,18 @@ def test_lr_settings(self): with self.assertRaises(TypeError): LRSettings( algorithm='liblinear', - output=GraphMode.NONE, + output='none', test_split=None ) # Check if split tests with no output cause warnings: with self.assertRaises(Warning): - LRSettings(output=GraphMode.NONE, test_split=True) + LRSettings(output='none', test_split=True) # Should not raise any exception when the input is correct LRSettings( algorithm='liblinear', - output=GraphMode.TEXT + output='text' ) def test_lr_constructor(self): @@ -82,7 +82,7 @@ def test_lr_constructor(self): def test_lr(self): """Integration test case for LR training.""" # Perform preliminary data fusion - df_settings = DFSettings(output=GraphMode.NONE) + df_settings = DFSettings(output='none') table1 = Table( file_path="tests/qepas.xlsx", sheet_name="Sheet1", @@ -109,23 +109,23 @@ def test_lr(self): lr.train() # With text output - lr_settings = LRSettings(output=GraphMode.TEXT) + lr_settings = LRSettings(output='text') lr = LR(lr_settings, pca_data) lr.train() # With graph output # With text output - lr_settings = LRSettings(output=GraphMode.GRAPHIC) + lr_settings = LRSettings(output='graphical') lr = LR(lr_settings, pca_data) lr.train() # With text output and split tests - lr_settings = LRSettings(output=GraphMode.TEXT, test_split=True) + lr_settings = LRSettings(output='text', test_split=True) lr = LR(lr_settings, pca_data) lr.train() # With graph output and split tests - lr_settings = LRSettings(output=GraphMode.GRAPHIC, test_split=True) + lr_settings = LRSettings(output='graphical', test_split=True) lr = LR(lr_settings, pca_data) lr.train() diff --git a/tests/test_pca.py b/tests/test_pca.py index aa35e4c..c929e47 100644 --- a/tests/test_pca.py +++ b/tests/test_pca.py @@ -1,7 +1,7 @@ """This module contains the test cases for the PCA module.""" import unittest import copy -from chemfusekit.pca import PCASettings, PCA, GraphMode +from chemfusekit.pca import PCASettings, PCA from chemfusekit.df import DFSettings, DF, Table from chemfusekit.lr import LRSettings, LR @@ -28,14 +28,14 @@ def test_pca_settings(self): target_variance=0.98, confidence_level=0.9, initial_components=8, - output=GraphMode.GRAPHIC + output='graphical' ) def test_pca_constructor(self): """Test case against constructor parameter issues.""" # Perform preliminary data fusion - df_settings = DFSettings(output=GraphMode.NONE) + df_settings = DFSettings(output='none') table1 = Table( file_path="tests/qepas.xlsx", sheet_name="Sheet1", @@ -72,7 +72,7 @@ def test_pca(self): whether the output is set to true or false """ # Perform preliminary data fusion - df_settings = DFSettings(output=GraphMode.NONE) + df_settings = DFSettings(output='none') table1 = Table( file_path="tests/qepas.xlsx", sheet_name="Sheet1", @@ -87,7 +87,7 @@ def test_pca(self): df.fuse() # Set up and execute PCA (graph output) - pca_settings = PCASettings(output=GraphMode.GRAPHIC) + pca_settings = PCASettings(output='graphical') pca = PCA(pca_settings, df.fused_data) pca.train() @@ -96,7 +96,7 @@ def test_pca(self): result_true_array_scores = copy.deepcopy(pca.array_scores) # Set up and execute PCA (again) - pca_settings = PCASettings(output=GraphMode.NONE) + pca_settings = PCASettings(output='none') pca = PCA(pca_settings, df.fused_data) pca.train() @@ -108,7 +108,7 @@ def test_pca(self): self.assertEqual(result_true_array_scores, result_false_array_scores) # Set up and execute PCA (text output) - pca_settings = PCASettings(output=GraphMode.GRAPHIC) + pca_settings = PCASettings(output='graphical') pca = PCA(pca_settings, df.fused_data) pca.train() @@ -117,7 +117,7 @@ def test_pca(self): result_true_array_scores = copy.deepcopy(pca.array_scores) # Set up and execute PCA (again) - pca_settings = PCASettings(output=GraphMode.NONE) + pca_settings = PCASettings(output='none') pca = PCA(pca_settings, df.fused_data) pca.train() @@ -132,7 +132,7 @@ def test_pca_integration_lr(self): """Integration test for PCA+LR""" # Perform preliminary data fusion - df_settings = DFSettings(output=GraphMode.NONE) + df_settings = DFSettings(output='none') table1 = Table( file_path="tests/qepas.xlsx", sheet_name="Sheet1", @@ -159,7 +159,7 @@ def test_pca_integration_lr(self): def test_pca_import_export(self): """Test case for the import and export of PCA models.""" # Perform preliminary data fusion - df_settings = DFSettings(output=GraphMode.NONE) + df_settings = DFSettings(output='none') table1 = Table( file_path="tests/qepas.xlsx", sheet_name="Sheet1", @@ -198,7 +198,7 @@ def test_pca_import_export(self): def test_pca_reduce(self): """Test case for data dimensionality reduction.""" # Perform preliminary data fusion - df_settings = DFSettings(output=GraphMode.NONE) + df_settings = DFSettings(output='none') table1 = Table( file_path="tests/qepas.xlsx", sheet_name="Sheet1", diff --git a/tests/test_plsda.py b/tests/test_plsda.py index 1cfd525..ec34537 100644 --- a/tests/test_plsda.py +++ b/tests/test_plsda.py @@ -31,12 +31,12 @@ def test_plsda_settings(self): # output and test_split incompatibilities with self.assertRaises(Warning): - PLSDASettings(output=GraphMode.NONE, test_split=True) + PLSDASettings(output='none', test_split=True) def test_plsda_constructor(self): """Test case against constructor errors.""" # Perform preliminary data fusion - df_settings = DFSettings(output=GraphMode.NONE) + df_settings = DFSettings(output='none') table1 = Table( file_path="tests/qepas.xlsx", sheet_name="Sheet1", @@ -64,7 +64,7 @@ def test_plsda_constructor(self): def test_plsda(self): """Integration test case for the training function.""" # Perform preliminary data fusion - df_settings = DFSettings(output=GraphMode.NONE) + df_settings = DFSettings(output='none') table1 = Table( file_path="tests/qepas.xlsx", sheet_name="Sheet1", @@ -84,29 +84,29 @@ def test_plsda(self): plsda.train() # Set up and run PLSDA with text output - plsda_settings = PLSDASettings(output=GraphMode.TEXT) + plsda_settings = PLSDASettings(output='text') plsda = PLSDA(plsda_settings, df.fused_data) plsda.train() # Set up and run PLSDA with graphical output - plsda_settings = PLSDASettings(output=GraphMode.GRAPHIC) + plsda_settings = PLSDASettings(output='graphical') plsda = PLSDA(plsda_settings, df.fused_data) plsda.train() # Run with text output and split testing - plsda_settings = PLSDASettings(output=GraphMode.TEXT, test_split=True) + plsda_settings = PLSDASettings(output='text', test_split=True) plsda = PLSDA(plsda_settings, df.fused_data) plsda.train() # Run with graphical output and split testing - plsda_settings = PLSDASettings(output=GraphMode.GRAPHIC, test_split=True) + plsda_settings = PLSDASettings(output='graphical', test_split=True) plsda = PLSDA(plsda_settings, df.fused_data) plsda.train() def test_prediction(self): """Test case against prediction parameter issues.""" # Perform preliminary data fusion - df_settings = DFSettings(output=GraphMode.NONE) + df_settings = DFSettings(output='none') table1 = Table( file_path="tests/qepas.xlsx", sheet_name="Sheet1", diff --git a/tests/test_svm.py b/tests/test_svm.py index f1d9b5d..5e57f69 100644 --- a/tests/test_svm.py +++ b/tests/test_svm.py @@ -1,6 +1,6 @@ """This module contains the test cases for the SVM module.""" import unittest -from chemfusekit.svm import SVMSettings, SVM, GraphMode +from chemfusekit.svm import SVMSettings, SVM from chemfusekit.df import DFSettings, DF, Table @@ -11,29 +11,29 @@ def test_svm_settings(self): """Test case against settings errors.""" # Test against null type with self.assertRaises(TypeError): - SVMSettings(None, GraphMode.NONE, False) + SVMSettings(None, 'none', False) # Test against null output selector with self.assertRaises(TypeError): SVMSettings('linear', None, False) # Test against null test_split selector with self.assertRaises(TypeError): - SVMSettings('linear', GraphMode.NONE, None) + SVMSettings('linear', 'none', None) # Test against non-existent kernels with self.assertRaises(ValueError): - SVMSettings('non-existent', GraphMode.NONE, False) + SVMSettings('non-existent', 'none', False) # Check if split tests with no output cause warnings: with self.assertRaises(Warning): - SVMSettings(output=GraphMode.NONE, test_split=True) + SVMSettings(output='none', test_split=True) # Now call with proper values: - SVMSettings(kernel='gaussian', output=GraphMode.GRAPHIC, test_split=False) + SVMSettings(kernel='gaussian', output='graphical', test_split=False) def test_svm_constructor(self): """Test case against constructor parameter issues.""" # Perform preliminary data fusion - df_settings = DFSettings(output=GraphMode.NONE) + df_settings = DFSettings(output='none') table1 = Table( file_path="tests/qepas.xlsx", sheet_name="Sheet1", @@ -68,7 +68,7 @@ def test_svm(self): """Integration test case.""" # Perform preliminary data fusion - df_settings = DFSettings(output=GraphMode.NONE) + df_settings = DFSettings(output='none') table1 = Table( file_path="tests/qepas.xlsx", sheet_name="Sheet1", @@ -83,17 +83,17 @@ def test_svm(self): df.fuse() # Create an SVM object and train it, with no output - svm_settings = SVMSettings(output=GraphMode.NONE) + svm_settings = SVMSettings(output='none') svm = SVM(svm_settings, df.fused_data) svm.train() # Create an SVM object and train it, with graphical output - svm_settings = SVMSettings(output=GraphMode.GRAPHIC) + svm_settings = SVMSettings(output='graphical') svm = SVM(svm_settings, df.fused_data) svm.train() # Create an SVM object and train it, with text output - svm_settings = SVMSettings(output=GraphMode.TEXT) + svm_settings = SVMSettings(output='text') svm = SVM(svm_settings, df.fused_data) svm.train() @@ -101,7 +101,7 @@ def test_svm_predict(self): """Test case against prediction parameter issues.""" # Perform preliminary data fusion - df_settings = DFSettings(output=GraphMode.NONE) + df_settings = DFSettings(output='none') table1 = Table( file_path="tests/qepas.xlsx", sheet_name="Sheet1",