D3MUnsupervised/SpectralClustering.py
def produce(self, *, inputs: Inputs, timeout: float = None, iterations: int = None) -> CallResult[Outputs]:
        """
        Parameters
        ----------
        inputs : dataframe 

        Returns
        ----------
        Outputs
            The output is a transformed dataframe of X fit into an embedded space, n feature columns will equal n_components hyperparameter
            For timeseries datasets the output is the dimensions concatenated to the timeseries filename dataframe
        """ 
    
        targets = inputs.metadata.get_columns_with_semantic_type('https://metadata.datadrivendiscovery.org/types/TrueTarget')
        if not len(targets):
            targets = inputs.metadata.get_columns_with_semantic_type('https://metadata.datadrivendiscovery.org/types/TrueTarget')
        if not len(targets):
            targets = inputs.metadata.get_columns_with_semantic_type('https://metadata.datadrivendiscovery.org/types/SuggestedTarget')
        target_names = [list(inputs)[t] for t in targets]
        index = inputs.metadata.get_columns_with_semantic_type('https://metadata.datadrivendiscovery.org/types/PrimaryKey')
        index_names = [list(inputs)[i] for i in index]
 
        X_test = inputs.drop(columns = list(inputs)[index[0]])
        X_test = X_test.drop(columns = target_names).values
        
        # special semi-supervised case - during training, only produce rows with labels
        series = inputs[target_names] != ''
        if series.any().any():
            inputs = dataframe_utils.select_rows(inputs, np.flatnonzero(series))
            X_test = X_test[np.flatnonzero(series)]

        sc_df = d3m_DataFrame(pandas.DataFrame(self.sc.fit_predict(X_test), columns=['cluster_labels']))

        # just add last column of last column ('clusters')
        col_dict = dict(sc_df.metadata.query((metadata_base.ALL_ELEMENTS, 0)))
        col_dict['structural_type'] = type(1)
        if self.hyperparams['task_type'] == 'classification':
            col_dict['semantic_types'] = ('http://schema.org/Integer', 'https://metadata.datadrivendiscovery.org/types/Attribute')
            col_dict['name'] = 'cluster_labels'
        else:
            col_dict['semantic_types'] = ('http://schema.org/Integer', 'https://metadata.datadrivendiscovery.org/types/PredictedTarget')
            col_dict['name'] = target_names[0]
        sc_df.metadata = sc_df.metadata.update((metadata_base.ALL_ELEMENTS, 0), col_dict)
        
        df_dict = dict(sc_df.metadata.query((metadata_base.ALL_ELEMENTS, )))
        df_dict_1 = dict(sc_df.metadata.query((metadata_base.ALL_ELEMENTS, ))) 
        df_dict['dimension'] = df_dict_1
        df_dict_1['name'] = 'columns'
        df_dict_1['semantic_types'] = ('https://metadata.datadrivendiscovery.org/types/TabularColumn',)
        df_dict_1['length'] = 1        
        sc_df.metadata = sc_df.metadata.update((metadata_base.ALL_ELEMENTS,), df_dict)
                
        return CallResult(utils_cp.append_columns(inputs, sc_df))

        Parameters
        ----------
        inputs : dataframe 

        Returns
        ----------
        Outputs
            The output is a transformed dataframe of X fit into an embedded space, n feature columns will equal n_components hyperparameter
            For timeseries datasets the output is the dimensions concatenated to the timeseries filename dataframe
        
Parameters
inputs : dataframe

Returns

Outputs
The output is a transformed dataframe of X fit into an embedded space, n feature columns will equal n_components hyperparameter
For timeseries datasets the output is the dimensions concatenated to the timeseries filename dataframe
Parameters inputs : dataframe Returns Outputs The output is a transformed dataframe of X fit into an embedded space n feature columns will equal n_components hyperparameter For timeseries datasets the output is the dimensions concatenated to the timeseries filename dataframe
def produce(self, *, inputs: Inputs, timeout: float = None, iterations: int = None) -> CallResult[Outputs]:
        targets = inputs.metadata.get_columns_with_semantic_type('https://metadata.datadrivendiscovery.org/types/TrueTarget')
        if not len(targets):
            targets = inputs.metadata.get_columns_with_semantic_type('https://metadata.datadrivendiscovery.org/types/TrueTarget')
        if not len(targets):
            targets = inputs.metadata.get_columns_with_semantic_type('https://metadata.datadrivendiscovery.org/types/SuggestedTarget')
        target_names = [list(inputs)[t] for t in targets]
        index = inputs.metadata.get_columns_with_semantic_type('https://metadata.datadrivendiscovery.org/types/PrimaryKey')
        index_names = [list(inputs)[i] for i in index]
        X_test = inputs.drop(columns = list(inputs)[index[0]])
        X_test = X_test.drop(columns = target_names).values
        series = inputs[target_names] != ''
        if series.any().any():
            inputs = dataframe_utils.select_rows(inputs, np.flatnonzero(series))
            X_test = X_test[np.flatnonzero(series)]
        sc_df = d3m_DataFrame(pandas.DataFrame(self.sc.fit_predict(X_test), columns=['cluster_labels']))
        col_dict = dict(sc_df.metadata.query((metadata_base.ALL_ELEMENTS, 0)))
        col_dict['structural_type'] = type(1)
        if self.hyperparams['task_type'] == 'classification':
            col_dict['semantic_types'] = ('http://schema.org/Integer', 'https://metadata.datadrivendiscovery.org/types/Attribute')
            col_dict['name'] = 'cluster_labels'
        else:
            col_dict['semantic_types'] = ('http://schema.org/Integer', 'https://metadata.datadrivendiscovery.org/types/PredictedTarget')
            col_dict['name'] = target_names[0]
        sc_df.metadata = sc_df.metadata.update((metadata_base.ALL_ELEMENTS, 0), col_dict)
        df_dict = dict(sc_df.metadata.query((metadata_base.ALL_ELEMENTS, )))
        df_dict_1 = dict(sc_df.metadata.query((metadata_base.ALL_ELEMENTS, ))) 
        df_dict['dimension'] = df_dict_1
        df_dict_1['name'] = 'columns'
        df_dict_1['semantic_types'] = ('https://metadata.datadrivendiscovery.org/types/TabularColumn',)
        df_dict_1['length'] = 1        
        sc_df.metadata = sc_df.metadata.update((metadata_base.ALL_ELEMENTS,), df_dict)
        return CallResult(utils_cp.append_columns(inputs, sc_df))
def produce ( self , * , inputs : Inputs , timeout : float = None , iterations : int = None ) -> CallResult [ Outputs ] : targets = inputs . metadata . get_columns_with_semantic_type ( 'https://metadata.datadrivendiscovery.org/types/TrueTarget' ) if not len ( targets ) : targets = inputs . metadata . get_columns_with_semantic_type ( 'https://metadata.datadrivendiscovery.org/types/TrueTarget' ) if not len ( targets ) : targets = inputs . metadata . get_columns_with_semantic_type ( 'https://metadata.datadrivendiscovery.org/types/SuggestedTarget' ) target_names = [ list ( inputs ) [ t ] for t in targets ] index = inputs . metadata . get_columns_with_semantic_type ( 'https://metadata.datadrivendiscovery.org/types/PrimaryKey' ) index_names = [ list ( inputs ) [ i ] for i in index ] X_test = inputs . drop ( columns = list ( inputs ) [ index [ 0 ] ] ) X_test = X_test . drop ( columns = target_names ) . values series = inputs [ target_names ] != '' if series . any ( ) . any ( ) : inputs = dataframe_utils . select_rows ( inputs , np . flatnonzero ( series ) ) X_test = X_test [ np . flatnonzero ( series ) ] sc_df = d3m_DataFrame ( pandas . DataFrame ( self . sc . fit_predict ( X_test ) , columns = [ 'cluster_labels' ] ) ) col_dict = dict ( sc_df . metadata . query ( ( metadata_base . ALL_ELEMENTS , 0 ) ) ) col_dict [ 'structural_type' ] = type ( 1 ) if self . hyperparams [ 'task_type' ] == 'classification' : col_dict [ 'semantic_types' ] = ( 'http://schema.org/Integer' , 'https://metadata.datadrivendiscovery.org/types/Attribute' ) col_dict [ 'name' ] = 'cluster_labels' else : col_dict [ 'semantic_types' ] = ( 'http://schema.org/Integer' , 'https://metadata.datadrivendiscovery.org/types/PredictedTarget' ) col_dict [ 'name' ] = target_names [ 0 ] sc_df . metadata = sc_df . metadata . update ( ( metadata_base . ALL_ELEMENTS , 0 ) , col_dict ) df_dict = dict ( sc_df . metadata . query ( ( metadata_base . ALL_ELEMENTS , ) ) ) df_dict_1 = dict ( sc_df . metadata . query ( ( metadata_base . ALL_ELEMENTS , ) ) ) df_dict [ 'dimension' ] = df_dict_1 df_dict_1 [ 'name' ] = 'columns' df_dict_1 [ 'semantic_types' ] = ( 'https://metadata.datadrivendiscovery.org/types/TabularColumn' , ) df_dict_1 [ 'length' ] = 1 sc_df . metadata = sc_df . metadata . update ( ( metadata_base . ALL_ELEMENTS , ) , df_dict ) return CallResult ( utils_cp . append_columns ( inputs , sc_df ) )
Parameters
inputs : dataframe
Parameters inputs : dataframe
"""
        Parameters
        ----------
        inputs : dataframe 

        Returns
        ----------
        Outputs
            The output is a transformed dataframe of X fit into an embedded space, n feature columns will equal n_components hyperparameter
            For timeseries datasets the output is the dimensions concatenated to the timeseries filename dataframe
        """ # special semi-supervised case - during training, only produce rows with labels # just add last column of last column ('clusters')
self
inputs
Inputs
timeout
float
iterations
int