From 56b4c038001cbaa808e4f1ae947a62a5285e3b6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=20Pe=C4=8Dnik?= Date: Mon, 7 Dec 2020 20:45:44 +0100 Subject: [PATCH 1/2] feature encoders to_string [ci skip] --- niaaml/pipeline.py | 10 +++++++++- niaaml/preprocessing/encoding/feature_encoder.py | 10 +++++++++- niaaml/preprocessing/encoding/one_hot_encoder.py | 10 +++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/niaaml/pipeline.py b/niaaml/pipeline.py index 2de121c..c25e53c 100644 --- a/niaaml/pipeline.py +++ b/niaaml/pipeline.py @@ -265,7 +265,15 @@ def to_string(self): feature_transform_algorithm_string = '\t' + self.__feature_transform_algorithm.to_string().replace('\n', '\n\t') if self.__feature_transform_algorithm is not None else '\tNone' stats_string = '\t' + self.__best_stats.to_string().replace('\n', '\n\t') if self.__best_stats is not None else '\tStatistics is not available.' features_string = '\t' + str(self.__selected_features_mask) if self.__selected_features_mask is not None else '\tFeature selection result is not available.' - return 'Classifier:\n{classifier}\n\nFeature selection algorithm:\n{fsa}\n\nFeature transform algorithm:\n{fta}\n\nMask of selected features (True if selected, False if not):\n{feat}\n\nStatistics:\n{stats}'.format(classifier=classifier_string, fsa=feature_selection_algorithm_string, fta=feature_transform_algorithm_string, feat=features_string, stats=stats_string) + + encoders_string = '' + if self.__categorical_features_encoders is not None: + encoders_string += 'Categorical features encoders (in order):\n' + for i in range(len(self.__categorical_features_encoders)): + encoders_string += '\t* ' + self.__categorical_features_encoders[i].to_string() + '\n' + encoders_string += '\n' + + return 'Classifier:\n{classifier}\n\nFeature selection algorithm:\n{fsa}\n\nFeature transform algorithm:\n{fta}\n\nMask of selected features (True if selected, False if not):\n{feat}\n\n{enc}Statistics:\n{stats}'.format(classifier=classifier_string, fsa=feature_selection_algorithm_string, fta=feature_transform_algorithm_string, enc=encoders_string, feat=features_string, stats=stats_string) class _PipelineBenchmark(Benchmark): r"""NiaPy Benchmark class implementation. diff --git a/niaaml/preprocessing/encoding/feature_encoder.py b/niaaml/preprocessing/encoding/feature_encoder.py index 294b1b5..1e996c4 100644 --- a/niaaml/preprocessing/encoding/feature_encoder.py +++ b/niaaml/preprocessing/encoding/feature_encoder.py @@ -41,4 +41,12 @@ def transform(self, feature): Returns: pandas.core.frame.DataFrame: A transformed column. """ - return None \ No newline at end of file + return None + + def to_string(self): + r"""User friendly representation of the object. + + Returns: + str: User friendly representation of the object. + """ + return '{name}' \ No newline at end of file diff --git a/niaaml/preprocessing/encoding/one_hot_encoder.py b/niaaml/preprocessing/encoding/one_hot_encoder.py index 51b9b7f..7658373 100644 --- a/niaaml/preprocessing/encoding/one_hot_encoder.py +++ b/niaaml/preprocessing/encoding/one_hot_encoder.py @@ -45,4 +45,12 @@ def transform(self, feature): Returns: pandas.core.frame.DataFrame: A transformed column. """ - return pd.DataFrame(self.__one_hot_encoder.transform(feature).toarray()) \ No newline at end of file + return pd.DataFrame(self.__one_hot_encoder.transform(feature).toarray()) + + def to_string(self): + r"""User friendly representation of the object. + + Returns: + str: User friendly representation of the object. + """ + return FeatureEncoder.to_string(self).format(name=self.Name) \ No newline at end of file From c3dcb2f2acbc8d63e023330d8e0adeb2d4027d3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=20Pe=C4=8Dnik?= Date: Mon, 7 Dec 2020 21:01:29 +0100 Subject: [PATCH 2/2] readme fix and type check added (encoders) [ci skip] --- README.md | 4 ++++ README.rst | 5 +++++ niaaml/preprocessing/encoding/utility.py | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5adb7f9..3a83d13 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,10 @@ In case you would like to try out the latest pre-release version of the framewor pip install niaaml --pre ``` +## Graphical User Interface + +There is a simple graphical user inteface for NiaAML package available [here](https://github.com/lukapecnik/NiaAML-GUI). + ## Components [Click here](COMPONENTS.md) for a list of currently implemented components divided into groups: classifiers, feature selection algorithms and feature transformation algorithms. At the end you can also see a list of currently implemented fitness functions for the optimization process and categorical features' encoders. All of the components are passed into the optimization process using their class names. Let's say we want to choose between Adaptive Boosting, Bagging and Multi Layer Perceptron classifiers, Select K Best and Select Percentile feature selection algorithms and Normalizer as the feature transformation algorithm (may not be selected during the optimization process). diff --git a/README.rst b/README.rst index d654391..d4ee3d5 100644 --- a/README.rst +++ b/README.rst @@ -49,6 +49,11 @@ In case you would like to try out the latest pre-release version of the framewor pip install niaaml --pre +Graphical User Interface +------------------------ + +You can find a simple graphical user interface for NiaAML package `here `_. + Usage ----- diff --git a/niaaml/preprocessing/encoding/utility.py b/niaaml/preprocessing/encoding/utility.py index 1c54f28..643dac3 100644 --- a/niaaml/preprocessing/encoding/utility.py +++ b/niaaml/preprocessing/encoding/utility.py @@ -28,7 +28,7 @@ def encode_categorical_features(features, encoder): to_drop = [] enc_features = pd.DataFrame() for i in range(len(types)): - if types[i] != np.dtype('float64'): + if types[i] != np.dtype('float64') and types[i] != np.dtype('int64'): enc.fit(features[[i]]) tr = enc.transform(features[[i]]) to_drop.append(i)