Python Decision Tree
SATYA RAM KUMAR
Adaptable and versatile fresher with a strong work ethic and a willingness to learn new things.
?? Exciting Update ??
I'm thrilled to share a recent achievement in my data science journey! ????
?? Decision Tree Accuracy ??
I've created a decision tree model in Python that delivers impressive accuracy using real-world data from a CSV file. ??
?? What's a decision tree, you ask? ??
A decision tree is a powerful machine-learning algorithm that helps us make data-driven decisions. It's like a digital Sherlock Holmes, uncovering hidden patterns and relationships within our data. ???♂?
?? The Steps I Took ??
Source Code:
import pandas as pd
import numpy as np
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.tree import plot_tree
import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
data=pd.read_csv("E:\\3rd year\\labs\\DWDM\\Naivebayees.csv")
print(data.iloc[1])
d1=data[['RI','Na','Mg','Al','K','Ca','Ba','Fe']]
d2=data['Type']
x_train,x_test,y_train,y_test=train_test_split(d1,d2,test_size=0.8,random_state=43)
clf=DecisionTreeClassifier()
clf.fit(x_train,y_train)
y_predict=clf.predict(x_test)
traindata=accuracy_score(y_true=y_train,y_pred=clf.predict(x_train))
testdata=accuracy_score(y_true=y_test,y_pred=y_predict)
print('The training data is :\n',traindata)
print('The accuracy of Testing data is :\n',testdata)
plt.figure(figsize=(12,8))
plot_tree(clf,feature_names=list(d1.columns),class_names=list(map(str,clf.classes_)),filled=True)
plt.show()
Here For better visualization of decision tree I take test_size=0.8
The Output for Accuracy And Tree:
Used CSV File for this code.
???? This project highlights the power of Python in data analysis and the potential for data-driven insights.
?? Share your thoughts, questions, or experiences with data science. I'm always eager to connect with like-minded professionals.
#DataScience #Python #MachineLearning #DecisionTree #DataAnalysis
Thanks Dr. Subhash Bhagavan Kommina sir, Srinadh Unnava sir.
Student at Sasi Institute of Technology & Engineering
10 个月Nice