質問編集履歴
5
文法修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -69,9 +69,11 @@
|
|
69
69
|
x_combined = X_train.iloc[:, [0,1]].values
|
70
70
|
y_combined = y_train.values
|
71
71
|
|
72
|
-
|
72
|
+
|
73
73
|
d = {'Iris-setosa':0, 'Iris-versicolor':1, 'Iris-virginica':2}
|
74
74
|
y = np.array(list(map(lambda i : d[i], y_combined)))
|
75
|
+
|
76
|
+
model.fit(x_combined, y)
|
75
77
|
|
76
78
|
print(np.unique(np.array(y)))
|
77
79
|
|
4
書式改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,8 +14,13 @@
|
|
14
14
|
### 発生している問題・エラーメッセージ
|
15
15
|
|
16
16
|
```
|
17
|
+
plot_decision_regions( x_combined, y, clf=model)と書いている行で
|
18
|
+
|
17
|
-
|
19
|
+
can only concatenate str (not "int") to str
|
20
|
+
|
21
|
+
というエラーが出ています。
|
18
22
|
```
|
23
|
+
|
19
24
|
|
20
25
|
### 該当のソースコード
|
21
26
|
|
@@ -31,38 +36,42 @@
|
|
31
36
|
df = pd.read_csv("iris.csv")
|
32
37
|
df.head()
|
33
38
|
|
34
|
-
X = df[["SepalLength","SepalWidth","PetalLength","PetalWidth"]]
|
39
|
+
X = df.loc[:, ["SepalLength","SepalWidth","PetalLength","PetalWidth"]]
|
35
|
-
y = df["Name"]
|
40
|
+
y = df.loc[:, "Name"]
|
41
|
+
|
36
42
|
|
37
43
|
X_train, X_test, y_train, y_test = train_test_split(X, y)
|
44
|
+
model = svm.SVC()
|
45
|
+
model.fit(X_train,y_train)
|
38
46
|
X_train.shape, X_test.shape
|
39
47
|
|
40
|
-
data_train = pd.DataFrame(X_train)
|
48
|
+
#data_train = pd.DataFrame(X_train)
|
41
|
-
data_train["Name"] = y_train
|
49
|
+
#data_train["Name"] = y_train
|
42
50
|
|
43
|
-
sns.pairplot(data_train, hue='Name', palette="husl")
|
51
|
+
#sns.pairplot(data_train, hue='Name', palette="husl")
|
44
52
|
|
45
|
-
X_train = data_train[["SepalLength","SepalWidth","PetalLength","PetalWidth"]].values
|
53
|
+
#X_train = data_train[["SepalLength","SepalWidth","PetalLength","PetalWidth"]].values
|
46
|
-
y_train = data_train["Name"].values
|
54
|
+
#y_train = data_train["Name"].values
|
47
55
|
|
48
|
-
from sklearn import svm,metrics
|
49
56
|
|
50
|
-
model = svm.SVC()
|
51
|
-
|
52
|
-
pre =
|
57
|
+
pre = model.predict(X_test)
|
53
58
|
|
54
59
|
ac_score = metrics.accuracy_score(y_test,pre)
|
55
60
|
print("正解率=", ac_score)
|
56
61
|
|
62
|
+
|
63
|
+
|
64
|
+
#ここからデータ可視化
|
57
65
|
import matplotlib.pyplot as plt
|
58
66
|
from mlxtend.plotting import plot_decision_regions
|
67
|
+
%matplotlib inline
|
59
68
|
|
60
|
-
x_combined = X_t
|
69
|
+
x_combined = X_train.iloc[:, [0,1]].values
|
61
|
-
y_combined = y_t
|
70
|
+
y_combined = y_train.values
|
62
71
|
|
63
72
|
model.fit(x_combined, y_combined)
|
64
73
|
d = {'Iris-setosa':0, 'Iris-versicolor':1, 'Iris-virginica':2}
|
65
|
-
y = list(map(lambda i : d[i], y_combined))
|
74
|
+
y = np.array(list(map(lambda i : d[i], y_combined)))
|
66
75
|
|
67
76
|
print(np.unique(np.array(y)))
|
68
77
|
|
3
文法の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -61,10 +61,13 @@
|
|
61
61
|
y_combined = y_test.values
|
62
62
|
|
63
63
|
model.fit(x_combined, y_combined)
|
64
|
+
d = {'Iris-setosa':0, 'Iris-versicolor':1, 'Iris-virginica':2}
|
65
|
+
y = list(map(lambda i : d[i], y_combined))
|
64
66
|
|
67
|
+
print(np.unique(np.array(y)))
|
65
68
|
|
66
69
|
fig = plt.figure(figsize=(13,8))
|
67
|
-
plot_decision_regions( x_combined, y
|
70
|
+
plot_decision_regions( x_combined, y, clf=model)
|
68
71
|
plt.show()
|
69
72
|
```
|
70
73
|
|
2
誤字修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,17 +20,6 @@
|
|
20
20
|
### 該当のソースコード
|
21
21
|
|
22
22
|
```python
|
23
|
-
import numpy as np
|
24
|
-
import pandas as pd
|
25
|
-
import seaborn as sns
|
26
|
-
sns.set_style("whitegrid")
|
27
|
-
import matplotlib.pyplot as plt
|
28
|
-
%matplotlib inline
|
29
|
-
from sklearn.model_selection import train_test_split, cross_validate
|
30
|
-
|
31
|
-
df = pd.read_csv("iris.csv")
|
32
|
-
df.head()
|
33
|
-
|
34
23
|
import numpy as np
|
35
24
|
import pandas as pd
|
36
25
|
import seaborn as sns
|
1
誤字修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -75,7 +75,7 @@
|
|
75
75
|
|
76
76
|
|
77
77
|
fig = plt.figure(figsize=(13,8))
|
78
|
-
plot_decision_regions( x_combined,
|
78
|
+
plot_decision_regions( x_combined, y_combined, clf=model)
|
79
79
|
plt.show()
|
80
80
|
```
|
81
81
|
|