def _build_feature_importance_dataframe()

in src/lookoutequipment/plot.py [0:0]


    def _build_feature_importance_dataframe(self, freq='1min', prediction_index=0):
        """
        Builds a feature importance dataframe with the importance evolution of 
        each signal over time.
        
        Parameters:
            freq (string):
                The datetime index frequence (defaults to '1min'). This must 
                be a string following this format: XXmin where XX is a number
                of minutes.
            prediction_index (integer):
                You can add several predicted ranges in your plot. Use this
                argument to specify for which one you wish to plot a histogram
                for (defaults to 0)
                
        Returns:
            pandas.DataFrame: a dataframe with the feature importance evolutio
            of each signal over time.
        """
        if self.expanded_results is None:
            expanded_results = []
            predicted_ranges = self._predictions_ranges[prediction_index]
            num_events = predicted_ranges.shape[0]
            for index, row in predicted_ranges.iterrows():
                new_row = dict()
                new_row.update({'start': row['start']})
                new_row.update({'end': row['end']})
                new_row.update({'prediction': 1.0})

                diagnostics = pd.DataFrame(row['diagnostics'])
                diagnostics = dict(zip(diagnostics['name'], diagnostics['value']))
                new_row = {**new_row, **diagnostics}

                expanded_results.append(new_row)

            expanded_results = pd.DataFrame(expanded_results)

            freq_int = int(freq[:-3])
            cols = list(expanded_results.columns)[3:]
            expanded_results['end2'] = expanded_results['end'] + pd.to_timedelta(freq_int, unit='m')

            df1 = expanded_results[['start'] + cols].copy()
            df2 = expanded_results[['end'] + cols].copy()
            df3 = expanded_results[['end2'] + cols].copy()

            df1.columns = ['timestamp'] + cols
            df2.columns = ['timestamp'] + cols
            df3.columns = ['timestamp'] + cols

            df3.iloc[:, 1:] = 0.0

            expanded_results = pd.concat([df1, df2, df3], axis='index').sort_index()
            expanded_results = expanded_results.sort_values(by='timestamp', ascending=True)
            expanded_results = expanded_results.set_index('timestamp')
            expanded_results = expanded_results.resample(rule=freq).first()
            expanded_results = expanded_results.fillna(method='ffill')
            
            self.expanded_results = expanded_results

        return self.expanded_results