Search
 
SCRIPT & CODE EXAMPLE
 

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

decision tree

from sklearn.datasets import load_iris
>>> from sklearn import tree
>>> X, y = load_iris(return_X_y=True)
>>> clf = tree.DecisionTreeClassifier()
>>> clf = clf.fit(X, y)
Comment

Decision Tree

from sklearn.datasets import make_classification
from sklearn import tree
from sklearn.model_selection import train_test_split
 
X, t = make_classification(100, 5, n_classes=2, shuffle=True, random_state=10)
X_train, X_test, t_train, t_test = train_test_split(
    X, t, test_size=0.3, shuffle=True, random_state=1)
 
model = tree.DecisionTreeClassifier()
model = model.fit(X_train, t_train)
 
predicted_value = model.predict(X_test)
print(predicted_value)
 
tree.plot_tree(model)
 
zeroes = 0
ones = 0
for i in range(0, len(t_train)):
    if t_train[i] == 0:
        zeroes += 1
    else:
        ones += 1
 
print(zeroes)
print(ones)
 
val = 1 - ((zeroes/70)*(zeroes/70) + (ones/70)*(ones/70))
print("Gini :", val)
 
match = 0
UnMatch = 0
 
for i in range(30):
    if predicted_value[i] == t_test[i]:
        match += 1
    else:
        UnMatch += 1
 
accuracy = match/30
print("Accuracy is: ", accuracy)
Comment

Decision Tree

from sklearn import tree

Y = data['Class']
X = data.drop(['Name','Class'],axis=1)

clf = tree.DecisionTreeClassifier(criterion='entropy',max_depth=3)
clf = clf.fit(X, Y)
Comment

Decision tree code

col_names = ['pregnant', 'glucose', 'bp', 'skin', 'insulin', 'bmi', 'pedigree', 'age', 'label']
# load dataset
pima = pd.read_csv("pima-indians-diabetes.csv", header=None, names=col_names)
POWERED BY DATACAMP WORKSPACE
COPY CODE
Comment

PREVIOUS NEXT
Code Example
Python :: unique list 
Python :: dbscan example 
Python :: how to get checkbutton from a list 
Python :: how can i aggregate without group by in pandas 
Python :: how to hello world in python 
Python :: software developer tools list 
Python :: change group box border color pyqt5 
Python :: how to set a hyperlink in python 
Python :: how to create a spark schema using a string 
Python :: importing a python file from another folder 
Python :: python function 
Python :: scale values in 0 100 python 
Python :: merge two dict python 
Python :: Merge 2 or more notebooks into one 
Python :: http404 django 
Python :: ros teleop 
Python :: Using replace() method to remove newlines from a string 
Python :: compare two data frames in assert 
Python :: all python statements 
Python :: mid point circle drawing 
Python :: pandas convert hex string to int 
Python :: python download chromebook 
Python :: pandas print column by index 
Python :: mistborn order to read 
Python :: Pivot Spark data frame using python 
Python :: set method in python 
Python :: django pycharm 
Python :: Customizing scatter plot with pyplot object 
Python :: Selenium get response body python 
Python :: capitalise texts 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =