def DecisionTree(inputdf):
import numpy as np
import scipy as sp
from sklearn import tree
from sklearn.metrics import precision_recall_curve
from sklearn.metrics import classification_report
from sklearn.cross_validation import train_test_split
x = np.array(inputdf.select("param1_1","param2_1").toPandas())
y = np.array(inputdf.select('label').toPandas())
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.3)
clf = tree.DecisionTreeClassifier(criterion='entropy')
#print(clf)
clf.fit(x_train, y_train)
'''save '''
#with open("tree.dot", 'w') as f:
#f = tree.export_graphviz(clf, out_file=f)
#print(clf.feature_importances_)
answer = clf.predict(x_test)
#print(x_train)
#print(answer)
#print(y_train)
print(np.mean(answer == y_test))
#precision, recall, thresholds = precision_recall_curve(y_train, clf.predict(x_train))
#answer = clf.predict_proba(x)[:,1]
#print(classification_report(y, answer, target_names = [1, 0]))
sklearn中决策树的实现
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 客户端安装sudo apt-get install postgresql-client 服务器安装sudo apt...