In [ ]:
# シグモイド関数のデータを作成する

In [13]:
# 関数を作成
import numpy as np

def sigmoid(x):
    return 1/(1+np.exp(-x)) # math.exp(x)だとスカラーしか受け付けない.np.exp(x)としてリスト全体を受けて,リストを返すのがコツ.

In [15]:
# 関数をグラフ表示
import matplotlib.pyplot as plt

# 定義域を設定
xmin = -5.0
xmax = 5.0
num = 100 # xminからxmaxまでをnum個で区切る
x = np.linspace(xmin, xmax, num)

# 関数から値域を取得
y = sigmoid(x)

# 点どうしを直線でつなぐ
plt.plot(x, y)

# 適切な表示範囲を指定
plt.xlim(xmin, xmax)

# グリッド追加
plt.grid(True)

# 表示
plt.show()

In [16]:
# データをファイル出力

import pandas as pd

df = pd.DataFrame({"x":x,"y":y})
df.to_csv("data.csv")
df.to_csv("data.csv", header=None, index=False)

x = np.round(x, 3)
y = np.round(y, 3)
df = pd.DataFrame({"x":x,"y":y})
df.to_csv("data.csv", header=None, index=False)

In [36]:
# データファイルにノイズを加える.

def sigmoid(x):
    return 1/(1+np.exp(-x)) + np.random.normal(0, 0.05, len(x))

x = np.linspace(xmin, xmax, num)
x += np.random.normal(0, 0.5, len(x))
y = sigmoid(x)

plt.scatter(x, y)
plt.xlim(xmin, xmax)
plt.grid(True)
plt.show()

df = pd.DataFrame({"x":x,"y":y})
df.to_csv("data.csv", header=None, index=False)


/usr/local/opt/pyenv/versions/anaconda3-2.4.0/lib/python3.5/site-packages/matplotlib/collections.py:590: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  if self._edgecolors == str('face'):

In [ ]: