갈루아의 반서재

728x90

쥬피터 노트북에서 다음과 같이 그래프가 보이지 않는 경우 

sklearn_1
In [3]:
# 속성을 표준화한다
scaler = preprocessing.StandardScaler().fit(X_train)
X_train = scaler.transform(X_train)
X_test = scaler.transform(X_test)
In [4]:
import matplotlib.pyplot as plt
colors = ['red', 'greenyellow', 'blue']
for i in xrange(len(colors)):
    xs = X_train[:,0][y_train == i]
    ys = X_train[:,1][y_train == i]
    plt.scatter(xs, ys, c=colors[i])
plt.legend(iris.target_names) 
plt.xlabel('Sepal length')
plt.ylabel('Sepal width')
Out[4]:
<matplotlib.text.Text at 0x7fc3298533d0>




아래의 3라인을 추가한다. 그래프가 정상 출력됨을 확인할 수 있다.


1
2
3
4
%matplotlib inline
 
import matplotlib
import numpy as np
cs


sklearn_1

In [3]:
# 속성을 표준화한다
scaler = preprocessing.StandardScaler().fit(X_train)
X_train = scaler.transform(X_train)
X_test = scaler.transform(X_test)
In [4]:
%matplotlib inline

import matplotlib
import numpy as np
import matplotlib.pyplot as plt
colors = ['red', 'greenyellow', 'blue']
for i in xrange(len(colors)):
    xs = X_train[:,0][y_train == i]
    ys = X_train[:,1][y_train == i]
    plt.scatter(xs, ys, c=colors[i])
plt.legend(iris.target_names) 
plt.xlabel('Sepal length')
plt.ylabel('Sepal width')
Out[4]:
<matplotlib.text.Text at 0x7ff9bf1e6690>



728x90