-
-
Save codecademydev/dee5d3d54a1c47f89e84bb03ad0bb3d9 to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import codecademylib3_seaborn | |
import pandas as pd | |
from sklearn.model_selection import train_test_split | |
from sklearn.tree import DecisionTreeClassifier | |
import matplotlib.pyplot as plt | |
flags = pd.read_csv("flags.csv", header = 0) | |
#print(flags.head(12)) | |
labels = flags[["Landmass"]] | |
#print(labels.head(10)) | |
#data = flags[["Red", "Green", "Blue", "Gold", "White", "Black", "Orange"]] | |
data = flags[["Red", "Green", "Blue", "Gold", "White","Black", "Orange", "Circles", "Crosses","Saltires","Quarters","Sunstars","Crescent","Triangle"]] | |
train_data, test_data, train_labels, test_labels = train_test_split(data, labels, random_state=1) | |
#tree = DecisionTreeClassifier(random_state = 1) | |
#tree.fit(train_data, train_labels) | |
#print(tree.score(test_data, test_labels)) | |
scores = [] | |
for i in range(1, 21): | |
tree = DecisionTreeClassifier(random_state = 1, max_depth = i) | |
tree.fit(train_data, train_labels) | |
score = tree.score(test_data, test_labels) | |
scores.append(score) | |
#print(i, score) | |
plt.plot(range(1, 21), scores) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment