[python] plot the values ​​before and after the conversion of yeojohnson conversion

python


import numpy as np
import pandas as pd

#Copy the formula here
# https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.yeojohnson.html
def yeojohnson(lmbda, x):
    if x >= 0 and lmbda != 0:
        y = ((x + 1)**lmbda - 1) / lmbda
    
    elif x >= 0 and lmbda == 0:
        y = np.log(x + 1)
    
    elif x < 0 and lmbda != 2:
        y = -((-x + 1)**(2 - lmbda) - 1) / (2 - lmbda)
        
    elif x < 0 and lmbda == 2:
        y = -np.log(-x + 1)
    
    else:
        #Should not reach
        raise
    
    return y

#Value to convert
x_ary = np.arange(21)-10

#Try a combination of two patterns of lmbda
for lmbda_ary in [np.arange(10)*0.25, np.arange(10)*0.5]:
    
    #Convert and combine into df
    X_dic = {}
    for lmbda in lmbda_ary:
        X_dic[lmbda] = [yeojohnson(lmbda, float(x)) for x in x_ary]
    df = pd.DataFrame(X_dic, index=x_ary)
    
    #drawing
    df.plot(cmap='viridis', marker='.')
    plt.xlabel('Original value (x)')
    plt.ylabel('Converted value (y)')
    plt.title('Change in value after conversion when lmbda is changed')
    plt.show()

output: スクリーンショット 2021-01-16 午後11.22.05.png

Recommended Posts

[python] plot the values ​​before and after the conversion of yeojohnson conversion
Fill the missing value (null) of DataFrame with the values before and after with pyspark
Remove double-byte spaces before and after the character string (python)
Notify the contents of the task before and after executing the task in Fabric
[Python] Various combinations of strings and values
[Python] Summary of conversion between character strings and numerical values (ascii code)
Summary of the differences between PHP and Python
The answer of "1/2" is different between python2 and 3
Specifying the range of ruby and python arrays
Compare the speed of Python append and map
About the * (asterisk) argument of python (and itertools.starmap)
A discussion of the strengths and weaknesses of Python
plot the coordinates of the processing (python) list and specify the number of times in draw ()
the zen of Python
The story of Python without increment and decrement operators.
The process of installing Atom and getting Python running
Python --Explanation and usage summary of the top 24 packages
Visualize the range of interpolation and extrapolation with python
Plot and understand the multivariate normal distribution in Python
Referencing and changing the upper bound of Python recursion
I checked out the versions of Blender and Python
Rotate and scale the image before cropping [python] [OpenCV]
The story of automatic language conversion of TypeScript / JavaScript / Python
[Python] Types of statistical values (features) and calculation methods
Towards the retirement of Python2
[Python] Heron's formula functionalization and calculation of the maximum area
Python --Check type of values
The process of making Python code object-oriented and improving it
Python: Create a dictionary from a list of keys and values
The websocket of toio (nodejs) and python / websocket do not connect.
I want to know the features of Python and pip
[Tips] Problems and solutions in the development of python + kivy
About the features of Python
Source installation and installation of Python
Play with the password mechanism of GitHub Webhook and Python
The Power of Pandas: Python
I compared the speed of Hash with Topaz, Ruby and Python
Count the number of Thai and Arabic characters well in Python
[Introduction to Python] I compared the naming conventions of C # and Python.
[Python] How to get the first and last days of the month
[Python] I thoroughly explained the theory and implementation of logistic regression
The story of running python and displaying the results without closing vim
[Python] I thoroughly explained the theory and implementation of decision trees
[python] Get the rank of the values in List in ascending / descending order
Get and set the value of the dropdown menu using Python and Selenium
Convert the result of python optparse to dict and utilize it
Verification of the theory that "Python and Swift are quite similar"
Get the title and delivery date of Yahoo! News in Python
Environment construction of python and opencv
Plot the spread of the new coronavirus
[Python] The stumbling block of import
First Python 3 ~ The beginning of repetition ~
Existence from the viewpoint of Python
pyenv-change the python version of virtualenv
Change the Python version of Homebrew
This and that of python properties
[Python] Understanding the potential_field_planning of Python Robotics
Review of the basics of Python (FizzBuzz)
Coexistence of Python2 and 3 with CircleCI (1.0)
About the basics list of Python basics
Summary of Python indexes and slices