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:
objectClass for storing and processing prediction results.
Diagnosticsis the default base class ofPredictions, which is generated by thePredictorclass. 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
-
__add__(rhs: poetic.results.Diagnostics) → poetic.results.Diagnostics¶ Method for
+operator.The
+operator concatenates two Diagnostics objects by concatenating all itspredictionsanddiagnosticsattributes. If one object’sdiagnosticsattribute is notNone, therun_diagnostics()method will be called on the returned object as well.- Returns
A new Diagnostics as a concatenated result.
- Return type
- Raises
TypeError – Error when concatenating non-Diagnostics objects,
-
__ge__(rhs: poetic.results.Diagnostics) → bool¶ Method for
>operator.The
>=operator relies on the mean predictions of each object for comparison, and it is suited for normal or normal-like data.- Returns
- Whether the mean predictions of the left-hand-side is
greator or equal.
- Return type
bool
-
__gt__(rhs: poetic.results.Diagnostics) → bool¶ Method for
>operator.The
>operator relies on the mean predictions of each object for comparison, and it is suited for normal or normal-like data.- Returns
Whether the mean predictions the left-hand-side is greator.
- Return type
bool
-
__iadd__(rhs: poetic.results.Diagnostics) → poetic.results.Diagnostics¶ Method for
+=operator.The
+=operator concatenates a new Diagnostics objects to the left-hand-side by concatenatingpredictionsandsentencesattributes. If either object’sdiagnosticsattribute is notNone, therun_diagnostics()method will be called on the original object.- Returns
The concatenated Diagnostics object.
- Return type
- Raises
TypeError – Error when concatenating non-Diagnostics objects,
-
__le__(rhs: poetic.results.Diagnostics) → bool¶ Method for
>operator.The
<=operator relies on the mean predictions of each object for comparison, and it is suited for normal or normal-like data.- Returns
- Whether the mean predictions the left-hand-side is smaller
or equal.
- Return type
bool
-
__lt__(rhs: poetic.results.Diagnostics) → bool¶ Method for
<operator.The
<operator relies on the mean predictions of each object for comparison, and it is suited for normal or normal-like data.- Returns
Whether the mean predictions the left-hand-side is smaller.
- Return type
bool
-
__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(numeric_input: Union[numpy.ndarray, List[float]] = None, **kwargs) → 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
numeric_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.