import matplotlib.pyplot as pl
%matplot inline
def learning_curves(X_train, y_train, X_test, y_test):
""" Calculates the performance of several models with varying sizes of training data.
The learning and testing error rates for each model are then plotted. """
print ("Creating learning curve graphs for max_depths of 1, 3, 6, and 10. . .")
# Create the figure window
fig = pl.figure(figsize=(10,8))
# We will vary the training set size so that we have 50 different sizes
sizes = np.rint(np.linspace(1, len(X_train), 50)).astype(int)
train_err = np.zeros(len(sizes))
test_err = np.zeros(len(sizes))
# Create four different models based on max_depth
for k, depth in enumerate([1,3,6,10]):
for i, s in enumerate(sizes):
# Setup a decision tree regressor so that it learns a tree with max_depth = depth
regressor = DecisionTreeRegressor(max_depth = depth)
# Fit the learner to the training data
regressor.fit(X_train[:s], y_train[:s])
# Find the performance on the training set
train_err[i] = performance_metric(y_train[:s], regressor.predict(X_train[:s]))
# Find the performance on the testing set
test_err[i] = performance_metric(y_test, regressor.predict(X_test))
# Subplot the learning curve graph
ax = fig.add_subplot(2, 2, k+1)
ax.plot(sizes, test_err, lw = 2, label = 'Testing Error')
ax.plot(sizes, train_err, lw = 2, label = 'Training Error')
ax.legend()
ax.set_title('max_depth = %s'%(depth))
ax.set_xlabel('Number of Data Points in Training Set')
ax.set_ylabel('Total Error')
ax.set_xlim([0, len(X_train)])
# Visual aesthetics
fig.suptitle('Decision Tree Regressor Learning Performances', fontsize=18, y=1.03)
fig.tight_layout()
fig.show()
when I 실행하십시오 learning_curves ' ()' 기능을 보여준다.
>. UserWarning:C:\Users\Administrator\Anaconda3\lib\site-packages\matplotlib\figure.py:397: 우저워닝: 그래서 비 gui 매플로리브 현재 사용하고 있는 백 그림을 표시할 수 없습니다.
! 이것이 스크린샷
추가 [%matplotlib 인라인] (https://ipython.readthedocs.io/en/stable/interactive/plotting.html) 는 노트북 플롯합니다 임포트하지 동안 부드럽게하기
%matplotlib inline
import matplotlib.pyplot as plt
[%matplotlib 인라인] (https://ipython.readthedocs.io/en/stable/interactive/plotting.html) 의 # 39, & # 39 를 inline& 매플로리브 백 설정합니다. 백엔드: 이와 함께 백 같은 출력을 플로팅에 명령의세 표시되었습니까 프론트엔드 주피터 노트북, 바로 아래의 코드 내에서 발생한 셀입니다 인라인 거잖나. 그러면 결과 플롯합니다 노트북 문서를 저장할 수 있다.
백 의해 사용되는 등 매플로리브 변경할 수 있습니다.
import matplotlib
matplotlib.use('TkAgg')
(이외에도 백 옵션, 하지만 전 그 때 나를 위한 '백' 로 변경 타카그 협력했습니다 비슷한 문제).
제가 테스트를 마친 추가하기만 https://matplotlib.org/examples/animation/dynamic_image.html
%matplotlib notebook
과연 어떤 일을 조금 쉽지 않을 것으로 보인다. 난 이제 다음 커널 중지하시겠습니까 했습니다 :- (
I was trying to make dl3d 클러스터링에는 유사한 위한 데이터 과학 자습서는. '내가 처음 돌아보 피g. 쇼 ()' 같은 경고야 잡을라는데 정확하지만 수도 있습니다. 잠시 검토완료 [Matplot3d] [2]. 그런데 난 () '와' 이 3d 모델을 그대로 내 표시되었는지 플t.쇼 했던 것으로 보인다. 너무 공감하는 것 같아요. Avamer 프레비쇼프 () '' 이 될 수 있습니다.
파이썬 3.5 와 주피터 노트북 사용
[2]: https://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html # mplot3d 자습서는
현재, 비 gui 를 사용하는 오류 " 매플로리브 백 또 수행됨 when I was trying to 명령을 사용하여 피g. 쇼 플롯할 표시 ' ()'. 내가 찾은 주피터 노트북, 그림, ax = 플t.서브플로스 있는 명령 ' ()' 와 같은 셀입니다 플롯할 명령을 할 수 있도록 하기 위해서는 플롯할 렌더링되었습니다.
예를 들어, 다음 코드는 제대로 보여주고 있는 플롯할 표시줄에는 아웃해야 [5]:
[3] 의.
import matplotlib.pyplot as plt
%matplotlib inline
[4] 에서:
x = 'A B C D E F G H'.split()
y = range(1, 9)
[5] 에서:
fig, ax = plt.subplots()
ax.bar(x, y)
아웃해야 [5]: (컨테이너입니다 객체에는 8 예술가)
반면,) 은 다음과 같은 코드를 플롯할 않습니다.
[5] 에서:
fig, ax = plt.subplots()
아웃해야 [5]:
[6] 에서:
ax.bar(x, y)
아웃해야 [6]: (컨테이너입니다 객체에는 8 예술가)
[6] 에서 아웃해야 " 명세서, 8 단 한 컨테이너입니다 객체에는 artists". 하지만 어떤 표시줄에는 플롯할 볼 수 있습니다.
같은 오류가 있었습니다. 그럼 내가 사용한 < br>;
'가져오기의 매플로리브 '매플로리브리우스 (& # 39, WebAgg& # 39;)
작동하잖아 좋았소 (rec.601 설치할 필요가 폭풍이요 볼 수 있는 웹, ('pip 설치처 폭풍이요'))
파이썬 버전: 3.7 매플로리브 버전: 3.1.1