LoginSignup
0
0

More than 5 years have passed since last update.

2次元座標に相関があったりなかったりするデータを作る

Last updated at Posted at 2018-09-26

2次元座標上の点に相関があったりなかったりする列を複数持つデータ群を作りたかった。
python素人なのでもっと良い書き方あるんだろうなと思いつつ。

output_6_0.png

%matplotlib inline
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
np.random.choice(2, 2)
array([0, 1])
ROWS = 500
COLS = 3

np.random.seed(0)
index = list(map(lambda x: 'ATTR_{:03d}'.format(x), range(COLS)))
names = list(map(lambda x: 'F_{:03d}'.format(x), range(ROWS)))
index.insert(0, '_x')
index.insert(1, '_y')
masks = list(map(lambda x: np.random.choice(2, 2), range(COLS)))
ws = list(map(lambda x: np.random.rand(2), range(COLS)))

df = pd.DataFrame()

print('masks=', masks) 
print('ws=', ws) 
a, b = np.random.rand(2)
for i in range(ROWS):
    x, y = np.random.rand(2)
    vs = list(map(lambda a: x*ws[a][0]*masks[a][0] + y*ws[a][1]*masks[a][1]+ np.random.rand(1)[0]/10, range(COLS)))
    vals = [x,y]
    vals.extend(vs)


    ddf = pd.Series(vals, index=index, name=names[i])
    df = df.append(ddf)
df.T
from pandas.plotting import scatter_matrix

scatter_matrix(df, diagonal='kde', color='k', alpha=0.5)

plt.show()
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0