LoginSignup
0
0

More than 3 years have passed since last update.

Pythonで多変量正規分布を使わずに楕円っぽい散布図を作る

Posted at

はじめに

 機械学習のサイトでは点を楕円形にプロットした図をよく見かけます。その作り方が分からなかったので、Numpyをいじって作ってみました。

コード

ellipseLike.py
import numpy as np
import matplotlib.pyplot as plt

#出力件数
n = 1000

#乱数を発生
x = np.random.uniform(-4, 4, n)
y = np.random.uniform(-1, 1, n)

#フィルタリング
coordinates = np.array([((x[i])**2 + (y[i])**2)**(1/2) < 1 for i in range(n)])
index = np.where(coordinates==True)

#座標を操作
x_points = x[index] *4
y_points = y[index]

#座標を回転移動(30度)
x_points2 = x_points * (3**(1/2)) - y_points * (1/2)
y_points2 = x_points * (1/2) + y_points * (3**(1/2))

#プロット
plt.scatter(x_points2, y_points2)
plt.show()

結果

ellipse.png

おわりに

 作り終わってから多変量正規分布を知りました。勉強不足でした...

 ご覧いただきありがとうございました。コメント・ご指摘等ありましたらよろしくお願いいたします。

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