Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

decisiontreeclassifier sklearn

from sklearn.tree import DecisionTreeClassifier
Comment

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 :: how to access a file from root folder in python project 
Python :: python cassandra 
Python :: pandas make currency with commas 
Python :: set comprehension 
Python :: make virtual environment python 
Python :: django request.data example 
Python :: or en python 
Python :: tkinter change button foreground 
Python :: tail a log file with python 
Python :: fraction to float 
Python :: pygame template 
Python :: python cursor placement 
Python :: torch cos 
Python :: python in kali linux 
Python :: The options auto_now, auto_now_add, and defa ult are mutually exclusive. Only one of these options may be present. 
Python :: python async await function 
Python :: switch case python 3.10 
Python :: django permissions 
Python :: tkinter convert Entry to string 
Python :: python load file with multiple jsons 
Python :: apply 2d mask to 3d array python 
Python :: block content 
Python :: how to get csv file first row first column value in python 
Python :: python genetic algorithm library 
Python :: python remove second occurrence of character in string 
Python :: foreach loop in python 
Python :: pass variable to thread target 
Python :: alternative to time.sleep() in python 
Python :: python string: .format() 
Python :: variable globale python 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =