Skip to content

Commit

Permalink
changed the title of plots
Browse files Browse the repository at this point in the history
  • Loading branch information
qchiujunhao committed Aug 1, 2024
1 parent ca79cf5 commit bcda55c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
23 changes: 14 additions & 9 deletions tools/feature_importance.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def __init__(self, task_type, output_dir, data_path=None, data=None, target_col
self.data = data
else:
self.target_col = target_col
self.task_type = task_type
self.data = pd.read_csv(data_path, sep=None, engine='python')
self.data.columns = self.data.columns.str.replace('.', '_')
self.data = self.data.fillna(self.data.median(numeric_only=True))
self.task_type = task_type
self.target = self.data.columns[int(target_col) - 1]
self.exp = ClassificationExperiment() if task_type == 'classification' else RegressionExperiment()
self.plots = {}
Expand Down Expand Up @@ -96,21 +96,26 @@ def generate_html_report(self, coef_html):
encoded_image = self.encode_image_to_base64(plot_path)
plots_html += f"""
<div class="plot" id="{plot_name}">
<h3>{plot_name.replace('_', ' ').capitalize()}</h3>
<h2>Feature importance analysis from a trained Random Forest</h2>
<h3>{'Use gini impurity for calculating feature importance for classification'
'and Variance Reduction for regression'
if plot_name == 'tree_importance'
else 'SHAP Summary from a trained lightgbm'}</h3>
<img src="data:image/png;base64,{encoded_image}" alt="{plot_name}">
</div>
"""

# Generate HTML content with tabs
html_content = f"""
<h1>PyCaret Feature Importance Report</h1>
<h1>PyCaret Feature Importance Report</h1>
<div id="coefficients" class="tabcontent">
<h2>Coefficients (based on a trained Logistic Regression Model)</h2>
<div>{coef_html}</div>
</div>
{plots_html}
"""
<div id="coefficients" class="tabcontent">
<h2>Coefficients (based on a trained
{'Logistic Regression' if self.task_type == 'classification' else 'Linear Regression'} Model)</h2>
<div>{coef_html}</div>
</div>
{plots_html}
"""

return html_content

Expand Down
3 changes: 1 addition & 2 deletions tools/pycaret_train.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<tool id="pycaret_tool" name="PyCaret Model Comparison" version="@VERSION@" profile="@PROFILE@">
<description>Compare different machine learning models on a dataset using PyCaret.</description>
<description>Compare different machine learning models on a dataset using PyCaret. Do feature analysis using LR, Random Forest and LightGBM. </description>
<macros>
<import>pycaret_macros.xml</import>
</macros>
Expand Down Expand Up @@ -164,7 +164,6 @@
</tests>
<help>
This tool uses PyCaret to train and evaluate machine learning models.
Ensure that the Conda environment specified in the requirements is correctly set up.
</help>
<expand macro="macro_citations" />
</tool>

0 comments on commit bcda55c

Please sign in to comment.