Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

decision tree algorithm python

import pandas
from sklearn import tree
from sklearn.tree import DecisionTreeClassifier
import matplotlib.pyplot as plt

df = pandas.read_csv("data.csv")

d = {'UK': 0, 'USA': 1, 'N': 2}
df['Nationality'] = df['Nationality'].map(d)
d = {'YES': 1, 'NO': 0}
df['Go'] = df['Go'].map(d)

features = ['Age', 'Experience', 'Rank', 'Nationality']

X = df[features]
y = df['Go']

dtree = DecisionTreeClassifier()
dtree = dtree.fit(X, y)

tree.plot_tree(dtree, feature_names=features)
Comment

python decision tree

# Create Decision Tree classifer object
clf = DecisionTreeClassifier(criterion="entropy", max_depth=3)

# Train Decision Tree Classifer
clf = clf.fit(X_train,y_train)

#Predict the response for test dataset
y_pred = clf.predict(X_test)

# Model Accuracy, how often is the classifier correct?
print("Accuracy:",metrics.accuracy_score(y_test, y_pred))
Comment

PREVIOUS NEXT
Code Example
Python :: decision tree python 
Python :: how to delete record in django 
Python :: python how to use logarithm 
Python :: faker, generates fake data for you 
Python :: how to calculate approximate distance with latitude and longitude 
Python :: delete item from list python 
Python :: python create a program that runs through all possible combinations 
Python :: django loginview 
Python :: python how to make integer show 2 numbers 
Python :: recursive binary search python 
Python :: how to declare a dictionary in python 
Python :: np.vectorize 
Python :: python opencv check image read 
Python :: python counter 
Python :: python length 
Python :: merge dataframe using pandas 
Python :: qpushbutton clicked 
Python :: python = align 
Python :: ipython and virtualenvs 
Python :: python read from stdin pipe 
Python :: example of tinker in python 
Python :: render to response django 
Python :: Count the number of cells that contain a specific value in a pandas dataframe python 
Python :: how to get all the keys of a dictionary in python 
Python :: values missing comparing datasets 
Python :: Chudnovsky algorithm in python codes 
Python :: is python good for competitive programming 
Python :: how to make reportlab table header bold in python 
Python :: difference between awswrangler and boto3 
Python :: python vs java 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =