반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- mglearn
- tensorflow
- bccard
- C언어
- broscoding
- discrete_scatter
- postorder
- html
- 대이터
- 웹 용어
- CES 2O21 참가
- KNeighborsClassifier
- vscode
- web
- 재귀함수
- paragraph
- web 용어
- CES 2O21 참여
- java역사
- web 개발
- web 사진
- 결합전문기관
- 머신러닝
- 데이터전문기관
- cudnn
- Keras
- classification
- 자료구조
- pycharm
- inorder
Archives
- Today
- Total
bro's coding
sklearn.tree.DecisionTreeClassifier.max_depth 변화 관찰 본문
[AI]/python.sklearn
sklearn.tree.DecisionTreeClassifier.max_depth 변화 관찰
givemebro 2020. 4. 20. 10:44반응형
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_breast_cancer
cancer =load_breast_cancer()
from sklearn.tree import DecisionTreeClassifier
X_train,X_test,y_train,y_test=train_test_split(cancer.data,cancer.target)
score_train=[]
score_test=[]
for depth in range(1,10):
model=DecisionTreeClassifier(max_depth=depth,random_state=2020)
model.fit(X_train,y_train)
score1=model.score(X_train,y_train)
score2=model.score(X_test,y_test)
score_train.append(score1)
score_test.append(score2)
plt.plot(range(1,10),score_train,'ro--')
plt.plot(range(1,10),score_test,'bs-')
plt.legend(['train','test'])
plt.xticks(range(1,10),range(1,10))
plt.xlabel('max_depth')
import mglearn
col1=0
col2=1
X_train,X_test,y_train,y_test=train_test_split(cancer.data[:,[col1,col2]],cancer.target)
plt.figure(figsize=[14,16])
for depth in range(1,10):
model=DecisionTreeClassifier(max_depth=depth,random_state=2020)
model.fit(X_train,y_train)
plt.subplot(3,3,depth)
plt.title('max_depth = '+str(depth))
mglearn.plots.plot_2d_classification(model,X_train)
mglearn.discrete_scatter(X_train[:,col1],X_train[:,col2],y_train,alpha=0.3)
반응형
'[AI] > python.sklearn' 카테고리의 다른 글
sklearn.RandomForestClassifier.feature_importances_(중요도 표현) (0) | 2020.04.20 |
---|---|
sklearn.ensemble.RandomForestClassifier.2 feature for visualization (0) | 2020.04.20 |
sklearn.ensemble.RandomForestClassifier.basic (0) | 2020.04.20 |
sklearn.install graphviz (0) | 2020.04.20 |
sklearn.non-linear regression(비선형회귀) (0) | 2020.04.19 |
sklearn.linear_model.Ridge.alpha에 따른 회귀선 변화 관찰 (0) | 2020.04.19 |
sklearn.linear_model.Lasso.alpha값에 따른 score변화 관찰 (0) | 2020.04.19 |
sklearn.Compare Ridge and Rasso (0) | 2020.04.17 |
Comments