简体   繁体   中英

Error while building Classification Tree in python

This is a code which i found in scikit learn website

from sklearn.datasets import load_iris
from sklearn import tree
iris = load_iris()
clf = tree.DecisionTreeClassifier()
clf = clf.fit(iris.data, iris.target)

here what is (iris.data,iris.target), for my project purpose using this code i've modified like pest=open("project.csv","r+")

clf=clf.fit(pest.data,pest.target)

but i get an error file has no attribute "data". please click on this to view my data set "project" .

I need to get a tree which has the root node crops and the leaf nodes toxicity level. How can I set the root node and the class label. I've tried a lot but could not get it.

It would seem that your pest only contains your file content. You should probably add a step where you select which part of the file is the data and which is the target.

It seems that you only open the .csv file, and you don't load anything from it. You need to load the data and specify which column is 'data' and which column is 'target'. Here are some sample codes for loading data from csv files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM