-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from jdvala/add-rich-text
Add rich based console output
- Loading branch information
Showing
6 changed files
with
131 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,7 @@ dask-worker-space | |
# virtualenv | ||
.venv | ||
venv/ | ||
env/ | ||
ENV/ | ||
|
||
# Spyder project settings | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
scikit-learn==1.0.1 | ||
tqdm==4.62.3 | ||
rich==11.2.0 | ||
pandas==1.3.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
version = "0.1.dev1+dirty" | ||
version = "0.0.2.dev2+dirty" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,70 @@ | ||
import typing as tt | ||
|
||
from rich.console import Console | ||
from rich.table import Table | ||
|
||
|
||
def create_table(results: tt.Dict, label_analysis: tt.Dict = None): | ||
"""Create summary table for all the results. | ||
Example: | ||
Results: | ||
``` | ||
| Model | Accuracy | Balanced Accuracy | Time Taken | | ||
| -------------------: | -------------------: | -------------------: | -------------------: | | ||
| MultinomialNB | 0.641908620301598 | 0.62653122841884 | 0.03511333465576172 | | ||
Label Analysis | ||
┏━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┓ | ||
┃ Classes ┃ Weights ┃ | ||
┡━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━┩ | ||
│ entertainment │ 0.8725490196078431 │ | ||
│ sport │ 1.1528497409326426 │ | ||
│ business │ 1.0671462829736211 │ | ||
│ tech │ 0.8708414872798435 │ | ||
│ politics │ 1.1097256857855362 │ | ||
└───────────────┴────────────────────┘ | ||
Result Analysis | ||
┏━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┓ | ||
┃ Model ┃ Accuracy ┃ Balanced Accuracy ┃ F1 Score ┃ Custom Metric Score ┃ Time Taken ┃ | ||
┡━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━┩ | ||
│ SVC │ 0.23502994011976047 │ 0.2184410069760388 │ 0.10772097568020063 │ NA │ 6.808304071426392 │ | ||
└───────┴─────────────────────┴────────────────────┴─────────────────────┴─────────────────────┴───────────────────┘ | ||
``` | ||
Label Analysis | ||
Args: | ||
results: Dictonary of all the results | ||
label_analysis: Analysis of the labels | ||
""" | ||
result_format = "| {:<30}| {:<20}| {:<20}| {:<20}| {:<20}| {:<20}|" | ||
label_format = "| {:<20}| {:<20} |" | ||
|
||
# Class weights | ||
console = Console() | ||
if label_analysis: | ||
print("\n Label Analysis") | ||
print(label_format.format("Classes", "Weights")) | ||
print("|--------------------:|---------------------:|") | ||
label_table = Table(title="Label Analysis") | ||
label_table.add_column("Classes", justify="left", style="cyan", no_wrap=True) | ||
label_table.add_column("Weights", justify="left", style="magenta", no_wrap=True) | ||
|
||
for name, weight in label_analysis.items(): | ||
print(label_format.format(name, weight)) | ||
|
||
# Result | ||
print("\n Result Analysis") | ||
|
||
print( | ||
result_format.format( | ||
"Model", | ||
"Accuracy", | ||
"Balanced Accuracy", | ||
"F1 Score", | ||
"Custom Metric Score", | ||
"Time Taken", | ||
) | ||
) | ||
print( | ||
result_format.format( | ||
"----------------------------:", | ||
"-------------------:", | ||
"-------------------:", | ||
"-------------------:", | ||
"-------------------:", | ||
"-------------------:", | ||
) | ||
label_table.add_row(str(name), str(weight)) | ||
|
||
console.print(label_table) | ||
|
||
result_table = Table(title="Result Analysis") | ||
result_table.add_column("Model", justify="left", style="cyan", no_wrap=True) | ||
result_table.add_column("Accuracy", justify="left", style="magenta", no_wrap=True) | ||
result_table.add_column( | ||
"Balanced Accuracy", justify="left", style="green", no_wrap=True | ||
) | ||
result_table.add_column("F1 Score", justify="left", style="red", no_wrap=True) | ||
result_table.add_column("Custom Metric Score", justify="left", style="yellow") | ||
result_table.add_column("Time Taken", justify="left", style="white") | ||
|
||
for result in results: | ||
temp = [] | ||
for key, value in result.items(): | ||
temp.append(value) | ||
print( | ||
result_format.format(temp[0], temp[1], temp[2], temp[3], temp[4], temp[5]) | ||
|
||
result_table.add_row( | ||
str(temp[0]), | ||
str(temp[1]), | ||
str(temp[2]), | ||
str(temp[3]), | ||
str(temp[4]), | ||
str(temp[5]), | ||
) | ||
print("\n") | ||
|
||
console.print(result_table) |
Oops, something went wrong.