Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

decision tree classifier

# Import DecisionTreeClassifier from sklearn.tree
from sklearn.tree import DecisionTreeClassifier

# Instantiate a DecisionTreeClassifier 'dt' with a maximum depth of 6
dt = DecisionTreeClassifier(max_depth=6, criterion='entropy///gini', random_state=1)

# Fit dt to the training set
dt.fit(X_train, y_train)

# Predict test set labels
y_pred = dt.predict(X_test)
print(y_pred[0:5])
# Import accuracy_score
from sklearn.metrics import accuracy_score

# Compute test set accuracy  
acc = accuracy_score(y_test, y_pred)
print("Test set accuracy: {:.2f}".format(acc))
Comment

decision tree classifier example

# Create Decision Tree classifer object
clf = DecisionTreeClassifier()

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

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

PREVIOUS NEXT
Code Example
Python :: append a dataframe to an empty dataframe 
Python :: python t test 
Python :: python for unity 
Python :: uppercase python 
Python :: .first() in django 
Python :: logistic regression algorithm 
Python :: #remove a sublist from a list-use remove method 
Python :: python sort descending 
Python :: get files in directory 
Python :: keyboard python 
Python :: how to change datetime format to mmyy in dataframe 
Python :: convert dictionary keys to list python 
Python :: python compare each item of one list 
Python :: py function 
Python :: messages in django 
Python :: python insert sorted 
Python :: python how to inspect pyd for functions 
Python :: inpuit inf terfminal ppython 
Python :: python list as queue 
Python :: python common elements in two arrays 
Python :: python syntax errors 
Python :: AI chatbot in Python - NAYCode.com 
Python :: python for data analysis 
Python :: python string: .join() 
Python :: python does string contain space 
Python :: df length 
Python :: to_frame pandas 
Python :: python random choices weights 
Python :: python pandas read_csv tsv 
Python :: python delete from dictionary pop 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =