poetic.results module¶
Module for processing prediction results.
The results module processes the outputs of prediction results from the Predictor of the predictor module. The functionalities provided include statistical summaries, io, and diagnostic reports.
Examples
The results module’s Diagnostics module can be used as part of the prediction workflow. To use its methods with the Predictor class:
import poetic
pred = poetic.Predictor()
result = pred.predict("This is an example.")
result.run_diagnostics() # One-stop function
result.to_file("<PATH>")
To use without the Predictor class:
import poetic
pred = [0.1, 0.2, 0.3]
result = Diagnostics(predictions=pred)
five_number_summary = result.five_number()
All public methods can be used without the run_diagnostics() method, but they depend on the diagnostic attribute, which the run_diagnostic() method generates.
-
class
poetic.results.
Diagnostics
(predictions: List[float], sentences: Optional[List[str]] = None)¶ Bases:
object
Class for storing and processing prediction results.
Diagnostics
is the default base class ofPredictions
, which is generated by thePredictor
class. It can also be used as a standalone class for processing any numeric results and strings stored in lists.- Parameters
predictions (list) – Predictions of poetic scores.
sentences (list, optional) – Sentences associated with the predictions.
-
predictions
¶ Predictions of poetic scores.
- Type
list
-
sentences
¶ Sentences associated with the predictions.
- Type
list
-
diagnostics
¶ A dictionary of diagnostics statistics, including sentence count, five number summary, and the predictions themselves.
- Type
dict
-
__repr__
() → str¶ String representation for
repr()
.This string representation returns a dictionary cast into a string with three attributes of this class: predictions, sentences, and diagnostics.
- Returns
String representation of the object.
- Return type
str
-
__str__
() → str¶ String representation for
str()
.This string representation returns a summary of of the object. It will truncate results if there are more than 15 prediction entries. To get a string representation of all the results in a dictionary cast into string, use repr() method.
- Returns
String representation of the object.
- Return type
str
-
classmethod
five_number
(input: Union[numpy.ndarray, List[float]]) → Dict[str, float]¶ Five number summary.
This methods generates five number summary of a given input. The five number summary includes minimum, mean, median, standard deviation, and maximum. This is a class method.
- Parameters
input (numpy.ndarrau, list) – An array like object.
- Returns
A dictionary of five number results.
- Return type
dict(str, float)
-
generate_report
() → str¶ Generates the diagnostics report in string.
This methods generates a diagnostics report as a string, with Poetic package information, five number summary, and all sentences and their poetic sores.
- Returns
A string with diagnostic report.
- Return type
str
-
run_diagnostics
() → None¶ Run the diagnostics of the predictions.
This methods generate diagnostics of the predictions, which include sentence count, five number summary, and the sentences themselves.
-
to_csv
(path: str) → None¶ Saves predictions and sentences to a csv file.
This methods saves the results to a csv file. For a plain text diagnostics, please use the
to_file()
method.- Parameters
path (str) – An string representing the file path.
-
to_file
(path: str) → None¶ Saves diagnostics and predictions to a file.
This methods saves the results to a csv or generates a diagnostics report along with the predictions. The supplied file path’s file extension is used to determine which file to save. If a csv is explicitly desired,
to_csv()
method can be used. For all file extensions other than csv, a plain text report will be generated.- Parameters
path (str) – An string representing the file path.