Code-SPA/dataset_property_new.py
def collinearity_assess(X, y, plot, xticks = None , yticks = None, round_number = 0):
    """
    This funcion assesses collinearity in the independent variables, using variation inflation facor
    Using rule of thumb VIF > 5, then the explanatory variable given is highly collinear with the other
    explanatory variables, and the parameter estimates will have large standard errors because of this.
    
    Input: 
        X: independent variables of size N x m
        y: dependent variable of size N x 1
        plot: flag for plotting
    
    Output:
        int, whether there is collinearity in independent variable
    """
    scaler_x = StandardScaler()
    scaler_x.fit(X)
    X = scaler_x.transform(X)
    
    scaler_y = StandardScaler()
    scaler_y.fit(y)
    y=scaler_y.transform(y)
    
    if np.shape(X)[1] == 1:
        ##univariate regression problem does not suffer from coolinearity
        #print('Univariate system, no multicollinearity')
        return 0
    elif np.shape(X)[1] > np.shape(X)[0]:
        #print('Number of samples smaller than feature size, multicollineairty presents')
        return 1
    
    else:
        VIF = [variance_inflation_factor(X, i) for i in range(0,np.shape(X)[1])]
        if plot:
            print('=== Multicollinearity Results ===')
        ## plot for VIF values
            if xticks is None:
                xticks = [r'x$_'+str(i)+'$' for i in range(1,np.shape(X)[1]+1)]
            if yticks is None:
                yticks = ['y']
                
            plt.figure(figsize=(X.shape[1],3))
            sns.set(font_scale=1.6)
            sns.set_style("whitegrid")
            ax=sns.heatmap(np.array(VIF).reshape(1,-1),linewidths=0.8,vmin=1,vmax=10,cmap='Blues',annot=True,\
                               linecolor="white",annot_kws={"size": 14},xticklabels=xticks,square=True,\
                               yticklabels=yticks, cbar_kws={'label': 'variance inflation factor',"orientation": "horizontal",'ticks' : [1, 5, 10]}) 
            plt.savefig('VIF_' + str(round_number)+'.png', dpi = 600,bbox_inches='tight')
            
                
        #check whether VIF>5
        for i in range(0,np.shape(X)[1]):
            if VIF[i] > 5:
                return int(True)
            
        return int(False)

    This funcion assesses collinearity in the independent variables, using variation inflation facor
    Using rule of thumb VIF > 5, then the explanatory variable given is highly collinear with the other
    explanatory variables, and the parameter estimates will have large standard errors because of this.
    
    Input: 
        X: independent variables of size N x m
        y: dependent variable of size N x 1
        plot: flag for plotting
    
    Output:
        int, whether there is collinearity in independent variable
    
This funcion assesses collinearity in the independent variables, using variation inflation facor
Using rule of thumb VIF > 5, then the explanatory variable given is highly collinear with the other
explanatory variables, and the parameter estimates will have large standard errors because of this.

independent variables of size N x m
y: dependent variable of size N x 1
plot: flag for plotting

int, whether there is collinearity in independent variable
This funcion assesses collinearity in the independent variables using variation inflation facor Using rule of thumb VIF > 5 then the explanatory variable given is highly collinear with the other explanatory variables and the parameter estimates will have large standard errors because of this . independent variables of size N x m y : dependent variable of size N x 1 plot : flag for plotting int whether there is collinearity in independent variable
def collinearity_assess(X, y, plot, xticks = None , yticks = None, round_number = 0):
    scaler_x = StandardScaler()
    scaler_x.fit(X)
    X = scaler_x.transform(X)
    scaler_y = StandardScaler()
    scaler_y.fit(y)
    y=scaler_y.transform(y)
    if np.shape(X)[1] == 1:
        return 0
    elif np.shape(X)[1] > np.shape(X)[0]:
        return 1
    else:
        VIF = [variance_inflation_factor(X, i) for i in range(0,np.shape(X)[1])]
        if plot:
            print('=== Multicollinearity Results ===')
            if xticks is None:
                xticks = [r'x$_'+str(i)+'$' for i in range(1,np.shape(X)[1]+1)]
            if yticks is None:
                yticks = ['y']
            plt.figure(figsize=(X.shape[1],3))
            sns.set(font_scale=1.6)
            sns.set_style("whitegrid")
            ax=sns.heatmap(np.array(VIF).reshape(1,-1),linewidths=0.8,vmin=1,vmax=10,cmap='Blues',annot=True,\
                               linecolor="white",annot_kws={"size": 14},xticklabels=xticks,square=True,\
                               yticklabels=yticks, cbar_kws={'label': 'variance inflation factor',"orientation": "horizontal",'ticks' : [1, 5, 10]}) 
            plt.savefig('VIF_' + str(round_number)+'.png', dpi = 600,bbox_inches='tight')
        for i in range(0,np.shape(X)[1]):
            if VIF[i] > 5:
                return int(True)
        return int(False)
def collinearity_assess ( X , y , plot , xticks = None , yticks = None , round_number = 0 ) : scaler_x = StandardScaler ( ) scaler_x . fit ( X ) X = scaler_x . transform ( X ) scaler_y = StandardScaler ( ) scaler_y . fit ( y ) y = scaler_y . transform ( y ) if np . shape ( X ) [ 1 ] == 1 : return 0 elif np . shape ( X ) [ 1 ] > np . shape ( X ) [ 0 ] : return 1 else : VIF = [ variance_inflation_factor ( X , i ) for i in range ( 0 , np . shape ( X ) [ 1 ] ) ] if plot : print ( '=== Multicollinearity Results ===' ) if xticks is None : xticks = [ r'x$_' + str ( i ) + '$' for i in range ( 1 , np . shape ( X ) [ 1 ] + 1 ) ] if yticks is None : yticks = [ 'y' ] plt . figure ( figsize = ( X . shape [ 1 ] , 3 ) ) sns . set ( font_scale = 1.6 ) sns . set_style ( "whitegrid" ) ax = sns . heatmap ( np . array ( VIF ) . reshape ( 1 , - 1 ) , linewidths = 0.8 , vmin = 1 , vmax = 10 , cmap = 'Blues' , annot = True , linecolor = "white" , annot_kws = { "size" : 14 } , xticklabels = xticks , square = True , yticklabels = yticks , cbar_kws = { 'label' : 'variance inflation factor' , "orientation" : "horizontal" , 'ticks' : [ 1 , 5 , 10 ] } ) plt . savefig ( 'VIF_' + str ( round_number ) + '.png' , dpi = 600 , bbox_inches = 'tight' ) for i in range ( 0 , np . shape ( X ) [ 1 ] ) : if VIF [ i ] > 5 : return int ( True ) return int ( False )
This funcion assesses collinearity in the independent variables, using variation inflation facor
Using rule of thumb VIF > 5, then the explanatory variable given is highly collinear with the other
explanatory variables, and the parameter estimates will have large standard errors because of this.
This funcion assesses collinearity in the independent variables using variation inflation facor Using rule of thumb VIF > 5 then the explanatory variable given is highly collinear with the other explanatory variables and the parameter estimates will have large standard errors because of this .
"""
    This funcion assesses collinearity in the independent variables, using variation inflation facor
    Using rule of thumb VIF > 5, then the explanatory variable given is highly collinear with the other
    explanatory variables, and the parameter estimates will have large standard errors because of this.
    
    Input: 
        X: independent variables of size N x m
        y: dependent variable of size N x 1
        plot: flag for plotting
    
    Output:
        int, whether there is collinearity in independent variable
    """ ##univariate regression problem does not suffer from coolinearity
 #print('Univariate system, no multicollinearity')
 #print('Number of samples smaller than feature size, multicollineairty presents')
 ## plot for VIF values
 #check whether VIF>5

X
y
plot
xticks
yticks
round_number