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 :: append string variable with integer python 
Python :: how to call a class from another class python? 
Python :: python % meaning 
Python :: assert in selenium python 
Python :: upload folder to s3 bucket python 
Python :: wails install 
Python :: delete list using slicing 
Python :: encoding character or string to integer in python 
Python :: destructuring in for loops python 
Python :: reverse string in python without using function 
Python :: insert value in string python 
Python :: tri fusion python code 
Python :: argparse parse path 
Python :: algebraic pyramid python 
Python :: how to create tupple in python 
Python :: horizontal barplot 
Python :: check pd.NaT python 
Python :: get first not null value from column dataframe 
Python :: python logging repeated messages 
Python :: django get form id from request 
Python :: python indent print 
Python :: python open file check error 
Python :: centos install python 3.9 thelinuxterminal.com 
Python :: mistborn series 
Python :: convert to lwercase in df column 
Python :: set pop in python 
Python :: print in pytest python 
Python :: how to print values without space in python 
Python :: override get_queryset django with url parameters 
Python :: how to parse http request in python 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =