Skip to content

Commit

Permalink
minor corrections in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
firefly-cpp committed Dec 13, 2020
1 parent a8a8fb2 commit 6e8fbc4
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 44 deletions.
6 changes: 3 additions & 3 deletions examples/export_pipeline_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
from niaaml.preprocessing.feature_transform import Normalizer

"""
In this example, we show how to export a pipeline object into a file that can later be loaded back into a Python program as a Pipeline object.
This example presents how to export a pipeline object into a file that can later be loaded back into a Python program as a Pipeline object.
"""

# instantiate a Pipeline object with AdaBoost classifier, SelectKBest feature selection algorithm and Normalizer as feature transformation algorithm
# instantiate a Pipeline object with AdaBoost classifier, SelectKBest feature selection algorithm and Normalizer as a feature transformation algorithm
pipeline = Pipeline(
feature_selection_algorithm=SelectKBest(),
feature_transform_algorithm=Normalizer(),
classifier=AdaBoost()
)

# export the object to a file for later use
pipeline.export('exported_pipeline.ppln')
pipeline.export('exported_pipeline.ppln')
6 changes: 3 additions & 3 deletions examples/export_pipeline_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from niaaml.preprocessing.feature_transform import Normalizer

"""
In this example, we show how to export a pipeline object into a text file in a user-friendly form. Text file cannot be loaded back into a Python program in
a form of a Pipeline object.
This example presents how to export a pipeline object into a text file in a user-friendly form. A text file cannot be loaded back into a Python program in
the form of a Pipeline object.
"""

# instantiate a Pipeline object with AdaBoost classifier, SelectKBest feature selection algorithm and Normalizer as feature transformation algorithm
Expand All @@ -16,4 +16,4 @@
)

# export the object to a file in a user-friendly form
pipeline.export_text('exported_pipeline.txt')
pipeline.export_text('exported_pipeline.txt')
6 changes: 3 additions & 3 deletions examples/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from niaaml.preprocessing.imputation import ImputerFactory

"""
In this example, we show how to use all of the implemented factories to create new object instances using their class names. You may also
import and instantiate objects directly, but it more convenient to use factories in some cases.
This example presents how to use all of the implemented factories to create new object instances using their class names. You may also
import and instantiate objects directly, but it is more convenient to use factories in some cases.
"""

# instantiate all possible factories
Expand Down Expand Up @@ -36,4 +36,4 @@
#get an instance of the SimpleImputer class
imp = i_factory.get_result('SimpleImputer')

# variables mlp, pso, normalizer, precision, ohe and imp contain instances of the classes with the passed names
# variables mlp, pso, normalizer, precision, ohe and imp contain instances of the classes with the passed names
6 changes: 3 additions & 3 deletions examples/feature_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from niaaml.data import CSVDataReader

"""
In this example, we show how to individually use an implemented categorical feature encoder and its methods. In this case we use OneHotEncoder for demonstration, but
This example presents how to use an implemented categorical feature encoder and its methods individually. In this case, we use OneHotEncoder for demonstration, but
you can use any of the implemented encoders in the same way.
"""

Expand All @@ -19,5 +19,5 @@
f = ohe.transform(features[[6]])
print(f)

# if you wish to get array of encoders for all of categorical features in a dataset (and transformed DataFrame of features), you may use the utility method encode_categorical_features
transformed_features, encoders = encode_categorical_features(features, 'OneHotEncoder')
# if you need to get an array of encoders for all of the categorical features in a dataset (and transformed DataFrame of features), you may use the utility method encode_categorical_features
transformed_features, encoders = encode_categorical_features(features, 'OneHotEncoder')
4 changes: 2 additions & 2 deletions examples/feature_imputing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from niaaml.data import CSVDataReader

"""
In this example, we show how to individually use an implemented missing features' imputer and its methods. In this case we use SimpleImputer for demonstration, but
This example presents how to use an implemented missing features' imputer and its methods individually. In this case, we use SimpleImputer for demonstration, but
you can use any of the implemented imputers in the same way.
"""

Expand All @@ -20,4 +20,4 @@
print(f)

# if you wish to get array of imputers for all of the features with missing values in a dataset (and transformed DataFrame of features), you may use the utility method impute_features
transformed_features, imputers = impute_features(features, 'SimpleImputer')
transformed_features, imputers = impute_features(features, 'SimpleImputer')
4 changes: 2 additions & 2 deletions examples/feature_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from sklearn.feature_selection import chi2

"""
In this example, we show how to individually use an implemented feature selection algorithm and its methods. In this case we use SelectKBest for demonstration, but
This example presents how to use an implemented feature selection algorithm and its methods individually. In this case, we use SelectKBest for demonstration, but
you can use any of the implemented feature selection algorithms in the same way.
"""

Expand All @@ -21,4 +21,4 @@
features_mask = fs.select_features(data_reader.get_x(), data_reader.get_y())

# print feature selection algorithm in a user-friendly form
print(fs.to_string())
print(fs.to_string())
4 changes: 2 additions & 2 deletions examples/feature_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from niaaml.data import CSVDataReader

"""
In this example, we show how to individually use an implemented feature transform algorithm and its methods. In this case we use Normalizer for demonstration, but
This example presents how to individually use an implemented feature transform algorithm and its methods individually. In this case, we use Normalizer for demonstration, but
you can use any of the implemented feature transform algorithms in the same way.
"""

Expand All @@ -23,4 +23,4 @@
transformed_features = ft.transform(data_reader.get_x())

# print feature transform algorithm in a user-friendly form
print(ft.to_string())
print(ft.to_string())
4 changes: 2 additions & 2 deletions examples/fitness.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy

"""
In this example, we show how to individually use an implemented fitness function and its method. In this case we use Precision for demonstration, but
This example presents how to use an implemented fitness function and its method individually. In this case, we use Precision for demonstration, but
you can use any of the implemented fitness functions in the same way.
"""

Expand All @@ -21,4 +21,4 @@
precision = fitness_func.get_fitness(predictions, data_reader.get_y())

# precision will probably be low due to dummy data
print(precision)
print(precision)
4 changes: 2 additions & 2 deletions examples/load_data_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy

"""
In this example, we show how to instantiate BasicDataReader and use its methods. You can use it to contain data in a single variable
This example presents how to instantiate BasicDataReader and use its methods. You can use it to contain data in a single variable
or as an input to an instance of the PipelineOptimizer class.
"""

Expand All @@ -14,4 +14,4 @@

# get x and y arrays and print them
print(data_reader.get_x())
print(data_reader.get_y())
print(data_reader.get_y())
6 changes: 3 additions & 3 deletions examples/load_data_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
from niaaml.data import CSVDataReader

"""
In this example, we show how to instantiate CSVDataReader and use its methods. You can use it to contain data in a single variable
This example presents how to instantiate CSVDataReader and use its methods. You can use it to contain data in a single variable,
or as an input to an instance of the PipelineOptimizer class.
"""

# CSVDataReader get a path to csv file on the input, reads and parses it into the x and y arrays
# CSVDataReader gets a path to csv file on the input, reads and parses it into the x and y arrays
# has_header and contains_classes arguments needs to be set according to the input csv file's structure
data_reader = CSVDataReader(src=os.path.dirname(os.path.abspath(__file__)) + '/example_files/dataset.csv', has_header=False, contains_classes=True)

# get x and y arrays and print them
print(data_reader.get_x())
print(data_reader.get_y())
print(data_reader.get_y())
4 changes: 2 additions & 2 deletions examples/load_pipeline_object_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from niaaml import Pipeline

"""
In this example, we show how to load a saved Pipeline object from a file. You can use all of its methods after it's been successfully loaded.
This example presents how to load a saved Pipeline object from a file. You can use all of its methods after it has been loaded successfully.
"""

# load Pipeline object from a file
pipeline = Pipeline.load(os.path.dirname(os.path.abspath(__file__)) + '/example_files/pipeline.ppln')

# all of the Pipeline's classes methods can be called after a successful load
# all of the Pipeline's classes methods can be called after a successful load
7 changes: 3 additions & 4 deletions examples/optimization_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
import numpy as np

"""
In this example, we show how the OptimizationStats class can be used. Normally, it is used in the background when the Pipeline's optimize method is called.
You may also use it on its own if you find useful.
This example presents how the OptimizationStats class can be used. Normally, it is used in the background when the Pipeline's optimize method is called.
"""

# dummy array with expected results of classification process
# dummy array with expected results of the classification process
y = np.array(['Class 1', 'Class 1', 'Class 1', 'Class 2', 'Class 1', 'Class 2',
'Class 2', 'Class 2', 'Class 2', 'Class 1', 'Class 1', 'Class 2',
'Class 1', 'Class 2', 'Class 1', 'Class 1', 'Class 1', 'Class 1',
Expand All @@ -22,4 +21,4 @@
stats = OptimizationStats(predicted, y)

# print user-friendly text representation
print(stats.to_string())
print(stats.to_string())
4 changes: 2 additions & 2 deletions examples/optimize_run_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pandas

"""
In this example, we show how to individually use the Pipeline class. You may use this if you want to test out a specific classification pipeline.
This example presents how to use the Pipeline class individually. You may use this if you want to test out a specific classification pipeline.
"""

# prepare data reader using csv file
Expand All @@ -28,4 +28,4 @@
# you could run the pipeline before the optimization process, but get wrong predictions as nothing in the pipeline is fit for the given dataset
predicted = pipeline.run(pandas.DataFrame(numpy.random.uniform(low=0.0, high=15.0, size=(30, data_reader.get_x().shape[1]))))

# pipeline variable contains Pipeline object that can be used for further classification, exported as an object (that can be later loaded and used) or exported as text file
# pipeline variable contains Pipeline object that can be used for further classification, exported as an object (that can be later loaded and used) or exported as text file
6 changes: 3 additions & 3 deletions examples/optimize_run_pipeline_categorical_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import pandas

"""
In this example, we show how to individually use the Pipeline class. You may use this if you want to test out a specific classification pipeline.
We will use a dataset that contains categorical and numerical features.
This example presents how to use the Pipeline class individually. You may use this if you want to test out a specific classification pipeline.
We use a dataset that contains categorical and numerical features.
"""

# prepare data reader using csv file
Expand All @@ -37,4 +37,4 @@
# you could run the pipeline before the optimization process, but get wrong predictions as nothing in the pipeline is fit for the given dataset
predicted = pipeline.run(pandas.DataFrame([[10.32440339, 3.195964543, 1.215275549, 3.741461311, 11.6736581, 6.435247906, 'a']]))

# pipeline variable contains Pipeline object that can be used for further classification, exported as an object (that can be later loaded and used) or exported as text file
# pipeline variable contains a Pipeline object that can be used for further classification, exported as an object (that can later be loaded and used) or exported as a text file
6 changes: 3 additions & 3 deletions examples/optimize_run_pipeline_missing_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import pandas

"""
In this example, we show how to individually use the Pipeline class. You may use this if you want to test out a specific classification pipeline.
We will use a dataset that contains categorical and numerical features with missing values.
This example presents how to use the Pipeline class individually. You may use this if you want to test out a specific classification pipeline.
We use a dataset that contains categorical and numerical features with missing values.
"""

# prepare data reader using csv file
Expand Down Expand Up @@ -44,4 +44,4 @@
# you could run the pipeline before the optimization process, but get wrong predictions as nothing in the pipeline is fit for the given dataset
predicted = pipeline.run(pandas.DataFrame([[10.32440339, 3.195964543, 1.215275549, 3.741461311, 11.6736581, 6.435247906, 'a']]))

# pipeline variable contains Pipeline object that can be used for further classification, exported as an object (that can be later loaded and used) or exported as text file
# pipeline variable contains a Pipeline object that can be used for further classification, exported as an object (that can later be loaded and used) or exported as text file
6 changes: 3 additions & 3 deletions examples/run_pipeline_optimizer_array_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import numpy

"""
In this example, we show how to use the PipelineOptimizer class. This example is using an instance of BasicDataReader.
The instantiated PipelineOptimizer will try and assemble the best pipeline with the components that are specified in its constructor.
This example presents how to use the PipelineOptimizer class. This example is using an instance of BasicDataReader.
The instantiated PipelineOptimizer try to compose the best pipeline with the components that are specified in its constructor.
"""

# prepare data reader using features and classes from arrays
Expand All @@ -28,4 +28,4 @@
# the chosen fitness function and optimization algorithm are Accuracy and Particle Swarm Algorithm
pipeline = pipeline_optimizer.run('Accuracy', 20, 20, 400, 400, 'ParticleSwarmAlgorithm', 'ParticleSwarmAlgorithm')

# pipeline variable contains Pipeline object that can be used for further classification, exported as an object (that can be later loaded and used) or exported as text file
# pipeline variable contains Pipeline object that can be used for further classification, exported as an object (that can be later loaded and used) or exported as text file
4 changes: 2 additions & 2 deletions examples/run_pipeline_optimizer_csv_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from niaaml.data import CSVDataReader

"""
In this example, we show how to use the PipelineOptimizer class. This example is using an instance of CSVDataReader.
This example presents how to use the PipelineOptimizer class. This example is using an instance of CSVDataReader.
The instantiated PipelineOptimizer will try and assemble the best pipeline with the components that are specified in its constructor.
"""

Expand All @@ -24,4 +24,4 @@
# the chosen fitness function and optimization algorithm are Accuracy and Particle Swarm Algorithm
pipeline = pipeline_optimizer.run('Accuracy', 20, 20, 400, 400, 'ParticleSwarmAlgorithm', 'ParticleSwarmAlgorithm')

# pipeline variable contains Pipeline object that can be used for further classification, exported as an object (that can be later loaded and used) or exported as text file
# pipeline variable contains Pipeline object that can be used for further classification, exported as an object (that can be later loaded and used) or exported as text file

0 comments on commit 6e8fbc4

Please sign in to comment.