





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A Decision Tree is a Flow Chart, and can help you make decisions based on previous experience. Decision tree learning is a method commonly used in data mining. The goal is to create a model that predicts the value of a target variable based on several input variables. A decision tree is a simple representation for classifying examples
Typology: Study Guides, Projects, Research
1 / 9
This page cannot be seen from the preview
Don't miss anything!






import pandas as pd from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split from sklearn.tree import DecisionTreeClassifier from sklearn.metrics import classification_report from sklearn import tree as t import matplotlib.pyplot as plt %matplotlib inline iris=load_iris() dir(iris) df=pd.DataFrame(iris.data, columns=iris.feature_names) df["target"]=iris.target x=df.drop(["target"], axis="columns") y=df.target x_train, x_test, y_train, y_test=train_test_split(x,y,t est_size=0.20) model=DecisionTreeClassifier(max_depth= 2 ) model.fit(x_train,y_train) #training the model #model.score(x_test,y_test) ypred=model.predict(x_test) #print(classification_report(ypred,y_test)) plt.figure(figsize=( 15 , 10 )) t.plot_tree(model, filled=True) plt.show()
else: ones += 1 print(zeroes) print(ones) val = 1 - ((zeroes/ 70 )(zeroes/ 70 ) + (ones/ 70 )(ones/ 70 )) print("Gini :", val) match = 0 UnMatch = 0 for i in range( 30 ): if predicted_value[i] == t_test[i]: match += 1 else: UnMatch += 1 accuracy = match/ 30 print("Accuracy is: ", accuracy)
dataset = np.array( [['Asset Flip', 100 , 1000 ], ['Text Based', 500 , 3000 ], ['Visual Novel', 1500 , 5000 ], ['2D Pixel Art', 3500 , 8000 ], ['2D Vector Art', 5000 , 6500 ], ['Strategy', 6000 , 7000 ], ['First Person Shooter', 8000 , 15000 ], ['Simulator', 9500 , 20000 ], ['Racing', 12000 , 21000 ], ['RPG', 14000 , 25000 ], ['Sandbox', 15500 , 27000 ], ['Open-World', 16500 , 30000 ], ['MMOFPS', 25000 , 52000 ], ['MMORPG', 30000 , 80000 ] ])
print(dataset)
X_grid = np.arange(min(X), max(X), 0.01)
X_grid = X_grid.reshape((len(X_grid), 1 ))
plt.scatter(X, y, color = 'red')
plt.plot(X_grid, regressor.predict(X_grid), color = 'bl ue')
plt.title('Profit to Production Cost (Decision Tree Reg ression)')
plt.xlabel('Production Cost')
plt.ylabel('Profit')
plt.show()