Professional Documents
Culture Documents
DA3ML
DA3ML
Machine Learning
Ans:
le = preprocessing.LabelEncoder()
df = pd.read_excel("ML2.xlsx")
df["Laptop_Model"] = le.fit_transform(df["Laptop_Model"])
y = df.iloc[:, 2].values
#Splitting
full_tree=DecisionTreeClassifier(random_state=30)
full_tree.fit(X_train,y_train)
plt.figure(figsize=(4,4),dpi=1000)
plot_tree(full_tree,filled=True)
plt.show()
Output:
After Applying Data Pruning:
max_depth=full_tree.get_depth()
clf = clf.fit(X_train,y_train)
y_pred = clf.predict(X_test)
print(classification_report(y_test, clf.predict(X_test)))
plt.figure(figsize=(4,4),dpi=1000)
plot_tree(clf,filled=True)
plt.show()
Output:
Conclusion: