In [5]:
# まずデータを作る所
# sin(x) + ばらつきのデータセット
import numpy as np
from pandas import DataFrame, Series
from numpy.random import normal
def create_dataset(n):
dataset = DataFrame(columns=['x','y'])
for i in range (0, n):
x = i / n
y = np.sin(2 * np.pi * x) + normal(scale=0.3)
dataset = dataset.append(Series([x,y], index=['x','y']), ignore_index=True)
return dataset
ds = create_dataset(100)
ds
Out[5]:
x
y
0
0.00
0.225373
1
0.01
0.030305
2
0.02
0.248564
3
0.03
0.138032
4
0.04
0.514605
5
0.05
0.261101
6
0.06
0.954766
7
0.07
0.174435
8
0.08
0.813449
9
0.09
0.555545
10
0.10
0.463886
11
0.11
0.622488
12
0.12
1.161724
13
0.13
1.521768
14
0.14
0.445272
15
0.15
0.807365
16
0.16
0.843347
17
0.17
0.867194
18
0.18
0.792921
19
0.19
0.758954
20
0.20
1.160296
21
0.21
0.992885
22
0.22
1.186167
23
0.23
0.942970
24
0.24
1.174175
25
0.25
1.260397
26
0.26
0.999984
27
0.27
0.979278
28
0.28
1.153074
29
0.29
0.985798
...
...
...
70
0.70
-0.451844
71
0.71
-0.229258
72
0.72
-0.979577
73
0.73
-1.145458
74
0.74
-1.281806
75
0.75
-0.886598
76
0.76
-0.948168
77
0.77
-0.751186
78
0.78
-1.371044
79
0.79
-0.509851
80
0.80
-1.158715
81
0.81
-1.057092
82
0.82
-0.988765
83
0.83
-0.744789
84
0.84
-0.747300
85
0.85
-0.578981
86
0.86
-0.906026
87
0.87
-0.801827
88
0.88
-0.950508
89
0.89
-0.551105
90
0.90
-0.844942
91
0.91
-0.439600
92
0.92
-1.151315
93
0.93
-0.926518
94
0.94
-0.769381
95
0.95
-0.601675
96
0.96
-0.216480
97
0.97
-0.108653
98
0.98
0.082461
99
0.99
-0.143131
100 rows × 2 columns
In [ ]:
Content source: ara-ta3/ml4se
Similar notebooks: