Python Decision Tree
Here the Output

Python Decision Tree

?? 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 ??

  1. Data Collection: I gathered relevant data from a CSV file.
  2. Data Preprocessing: Cleaned, transformed, and prepared the data for analysis.
  3. Model Building: Constructed a decision tree using Python's scikit-learn library.
  4. Model Training: Taught the decision tree to make sense of the data.
  5. Evaluation: Measured the model's accuracy, and the results were impressive!

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:

for test_size=0.8
plot of Decision 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.

Hemanth Paluri

Student at Sasi Institute of Technology & Engineering

10 个月

Nice

回复

要查看或添加评论,请登录

社区洞察

其他会员也浏览了