質問編集履歴
4
コード囲み忘れ
title
CHANGED
File without changes
|
body
CHANGED
@@ -78,6 +78,7 @@
|
|
78
78
|
|
79
79
|
#### LinearRegression
|
80
80
|
|
81
|
+
```python
|
81
82
|
df4 = df.copy()
|
82
83
|
|
83
84
|
from sklearn.linear_model import LinearRegression
|
@@ -92,6 +93,7 @@
|
|
92
93
|
print(name, lr.coef_, lr.intercept_)
|
93
94
|
|
94
95
|
sns.scatterplot(x='ta', y='m', hue='cluster', data=df4)
|
96
|
+
```
|
95
97
|
|
96
98
|

|
97
99
|
|
3
LinearRegressionを追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -76,6 +76,25 @@
|
|
76
76
|
|
77
77
|

|
78
78
|
|
79
|
+
#### LinearRegression
|
80
|
+
|
81
|
+
df4 = df.copy()
|
82
|
+
|
83
|
+
from sklearn.linear_model import LinearRegression
|
84
|
+
|
85
|
+
lr = LinearRegression()
|
86
|
+
lr.fit(df4['ta'].values.reshape(-1, 1), df4['m'].values.reshape(-1, 1))
|
87
|
+
pred_y = lr.predict(df4['ta'].values.reshape(-1, 1)).reshape(-1)
|
88
|
+
df4['cluster'] = (df4['m'] < pred_y).astype(int)
|
89
|
+
|
90
|
+
for name, dfg in df4.groupby('cluster'):
|
91
|
+
lr.fit(dfg['ta'].values.reshape(-1, 1), dfg['m'].values.reshape(-1, 1))
|
92
|
+
print(name, lr.coef_, lr.intercept_)
|
93
|
+
|
94
|
+
sns.scatterplot(x='ta', y='m', hue='cluster', data=df4)
|
95
|
+
|
96
|
+

|
97
|
+
|
79
98
|
### 補足情報(FW/ツールのバージョンなど)
|
80
99
|
|
81
100
|
Python3.8
|
2
df3を追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -61,6 +61,8 @@
|
|
61
61
|
#### SpectralClustering
|
62
62
|
|
63
63
|
```python
|
64
|
+
df3 = df.copy()
|
65
|
+
|
64
66
|
from sklearn import cluster
|
65
67
|
|
66
68
|
spectral = cluster.SpectralClustering(n_clusters=2, eigen_solver='arpack', affinity='nearest_neighbors')
|
1
サンプルデータ追加、GaussianMixtureとSpectralClusteringを追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -18,22 +18,62 @@
|
|
18
18
|
### 該当のソースコード
|
19
19
|
|
20
20
|
```python
|
21
|
+
import pandas as pd
|
22
|
+
|
23
|
+
url = "https://docs.google.com/spreadsheets/d/e/2PACX-1vSA9NhTNG6rcb1BAdVzC2RYgPPCCd0ryo1YconlDj7TK15IAO8rIi3uY9FzRCkXsj48BO4hWtceriKq/pub?gid=0&single=true&output=csv"
|
24
|
+
|
25
|
+
df = pd.read_csv(url)
|
26
|
+
|
21
27
|
sns.scatterplot(x='ta', y='m', data=df)
|
22
28
|
```
|
23
29
|
|
24
30
|
### 試したこと
|
25
31
|
|
32
|
+
#### KMeans
|
26
33
|
```python
|
34
|
+
df1 = df.copy()
|
35
|
+
|
27
36
|
from sklearn.cluster import KMeans
|
28
37
|
|
29
38
|
kmeans = KMeans(n_clusters=2, random_state=0)
|
30
|
-
clusters = kmeans.fit(df)
|
31
39
|
|
40
|
+
clusters = kmeans.fit(df1)
|
32
|
-
|
41
|
+
df1['cluster'] = clusters.labels_
|
33
42
|
|
34
|
-
sns.scatterplot(x='ta', y='m', hue='cluster', data=
|
43
|
+
sns.scatterplot(x='ta', y='m', hue='cluster', data=df1)
|
35
44
|
```
|
45
|
+

|
36
46
|
|
47
|
+
#### GaussianMixture
|
48
|
+
```python
|
49
|
+
df2 = df.copy()
|
50
|
+
|
51
|
+
from sklearn.mixture import GaussianMixture
|
52
|
+
|
53
|
+
model = GaussianMixture(n_components=2)
|
54
|
+
model.fit(df2)
|
55
|
+
df2['cluster'] = model.predict(df2)
|
56
|
+
|
57
|
+
sns.scatterplot(x='ta', y='m', hue='cluster', data=df2)
|
58
|
+
```
|
59
|
+

|
60
|
+
|
61
|
+
#### SpectralClustering
|
62
|
+
|
63
|
+
```python
|
64
|
+
from sklearn import cluster
|
65
|
+
|
66
|
+
spectral = cluster.SpectralClustering(n_clusters=2, eigen_solver='arpack', affinity='nearest_neighbors')
|
67
|
+
|
68
|
+
clusters = spectral.fit(df3)
|
69
|
+
|
70
|
+
df3['cluster'] = clusters.labels_
|
71
|
+
|
72
|
+
sns.scatterplot(x='ta', y='m', hue='cluster', data=df3)
|
73
|
+
```
|
74
|
+
|
75
|
+

|
76
|
+
|
37
77
|
### 補足情報(FW/ツールのバージョンなど)
|
38
78
|
|
39
79
|
Python3.8
|