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 :: 2 for loops at the same time in Python 
Python :: How do I get the parent directory in Python? 
Python :: string to list separated by space python 
Python :: how to merge two dataframes 
Python :: adding columns in cpecific position 
Python :: python ddos 
Python :: find record where dataframe column value contains 
Python :: get int64 column pandas 
Python :: difference between 2 timestamps pandas 
Python :: send message if user is banned discord.py 
Python :: printing float number python 
Python :: how to merge more than 2 dataframes in python 
Python :: save and load a machine learning model using Pickle 
Python :: pangram function 
Python :: Installing packages from requirements.txt file 
Python :: case insensitive replace python 
Python :: check pygame version 
Python :: make binary tree in python 
Python :: python currency signs 
Python :: how to flatten a nested list in python 
Python :: find most frequent element in an array python 
Python :: stock market api python 
Python :: pandas dataframe delete column 
Python :: with open python 
Python :: how to make a numpy array 
Python :: loop append to list python 
Python :: check if string is empty python 
Python :: set pytesseract cmd path 
Python :: change plot size matplotlib 
Python :: create a dataframe python 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =