当前位置: 首页>>代码示例>>Python>>正文


Python DecisionTreeClassifier.transform方法代码示例

本文整理汇总了Python中sklearn.tree.DecisionTreeClassifier.transform方法的典型用法代码示例。如果您正苦于以下问题:Python DecisionTreeClassifier.transform方法的具体用法?Python DecisionTreeClassifier.transform怎么用?Python DecisionTreeClassifier.transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sklearn.tree.DecisionTreeClassifier的用法示例。


在下文中一共展示了DecisionTreeClassifier.transform方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Customer

# 需要导入模块: from sklearn.tree import DecisionTreeClassifier [as 别名]
# 或者: from sklearn.tree.DecisionTreeClassifier import transform [as 别名]
#Mean Feature Importance
print "Mean Feature Importance %.6f" %np.mean(importances)


# In[9]:

#Okay so looks like some features are much more important than the others. Attribute 0 for instance is the status of
#checking accounts of the Customer (Importance 13%) while Attribute 7 is how long they've been employed with the 
#current employer (3.6%). It makes sense that one matters more than other.

#Let's do some trimming. We'll try to transform the Training set to include only features that are atleast as important as
#the mean of importances. Let's find out if this improves the accuracy.

#Luckily this is very easy to do in sklearn. RF has a transform method that helps with this.
X_train_r = estimator.transform(X_train, threshold='mean')
X_test_r = estimator.transform(X_test, threshold='mean')

#Let's run the learning curve again.
title = "Learning Curves -Iter2 (Random Forests, n_estimators=%.6f, feature_importances > mean)" %(n_estimators)
estimator = RandomForestClassifier(n_estimators=n_estimators, max_depth=max_depth, n_jobs=10)
plot_learning_curve(estimator, title, X_train_r, y_train, cv=cv)
plt.show()

#Looks like that didn't really have much of an impact on the model. Let's find out how well the model will generalize
#by predicting on the Test dataset.


# In[11]:

#Let's call fit on the estimator so we can look at feature importances.
开发者ID:pogigroo,项目名称:practice_Random_Forests,代码行数:32,代码来源:Random+Forests+with+scikit-learn.py


注:本文中的sklearn.tree.DecisionTreeClassifier.transform方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。