Created
          February 16, 2021 04:36 
        
      - 
      
 - 
        
Save ksv-muralidhar/dcdfa81a7e174d8a4cc1161e4b9f3fb3 to your computer and use it in GitHub Desktop.  
    Gaussian Transforms
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | from sklearn.preprocessing import FunctionTransformer, ColumnTransformer | |
| log_transform = FunctionTransformer(lambda x: np.log(x)) | |
| ct = ColumnTransformer(transformers=[['log_transform',log_transform,list(range(len(X.columns)))]],remainder='passthrough') | |
| log_X = ct.fit_transform(X).copy() | |
| log_X = pd.DataFrame(log_X,columns=[0,1,2,3]).copy() | 
  
    
      This file contains hidden or 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
    
  
  
    
  | reciprocal_transform = FunctionTransformer(lambda x: 1/x) | |
| ct = ColumnTransformer(transformers=[['reciprocal_transform',reciprocal_transform,list(range(len(X.columns)))]],remainder='passthrough') | |
| reci_X = ct.fit_transform(X).copy() | |
| reci_X = pd.DataFrame(reci_X,columns=[0,1,2,3]).copy() | 
  
    
      This file contains hidden or 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
    
  
  
    
  | square_transform = FunctionTransformer(lambda x: x ** 2) | |
| ct = ColumnTransformer(transformers=[['square_transform',square_transform,list(range(len(X.columns)))]],remainder='passthrough') | |
| square_X = ct.fit_transform(X).copy() | |
| square_X = pd.DataFrame(square_X,columns=[0,1,2,3]).copy() | 
  
    
      This file contains hidden or 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
    
  
  
    
  | from sklearn.preprocessing import PowerTransformer | |
| boxcox_transform = PowerTransformer(method="box-cox") | |
| ct = ColumnTransformer(transformers=[['boxcox_transform',boxcox_transform,list(range(len(X.columns)))]],remainder='passthrough') | |
| boxcox_X = ct.fit_transform(X).copy() | |
| boxcox_X = pd.DataFrame(boxcox_X,columns=[0,1,2,3]).copy() | 
  
    
      This file contains hidden or 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
    
  
  
    
  | boxcox_transform = PowerTransformer(method="box-cox") | |
| boxcox_transform.fit(X) | |
| boxcox_transform.lambdas_ | 
  
    
      This file contains hidden or 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
    
  
  
    
  | yeo_transform = PowerTransformer(method="yeo-johnson") | |
| ct = ColumnTransformer(transformers=[['yeo_transform',yeo_transform,list(range(len(X.columns)))]],remainder='passthrough') | |
| yeo_X = ct.fit_transform(X).copy() | |
| yeo_X = pd.DataFrame(yeo_X,columns=[0,1,2,3]).copy() | 
  
    
      This file contains hidden or 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
    
  
  
    
  | yeo_transform = PowerTransformer(method="yeo-johnson") | |
| yeo_transform.fit(X) | |
| yeo_transform.lambdas_ | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment