python随机森林特征重要性都不超过10%_RandomForestClassifier(随机森林检测每个特征的重要性及每个样例属于哪个类的概率)...

#In the next recipe, we'll look at how to tune the random forest classifier.#Let's start by importing datasets:from sklearn import datasetsX, y = datasets.make_classification(1000)# X(1000,20)#y(1000)...
摘要由CSDN通过智能技术生成

#In the next recipe, we'll look at how to tune the random forest classifier.

#Let's start by importing datasets:

from sklearn import datasets

X, y = datasets.make_classification(1000)

# X(1000,20)

#y(1000) 取值范围【0,1】

from sklearn.ensemble import RandomForestClassifier

rf = RandomForestClassifier()

rf.n_jobs=-1

rf.fit(X, y)

print ("Accuracy:\t", (y == rf.predict(X)).mean())

print ("Total Correct:\t", (y == rf.predict(X)).sum())

#每个例子属于哪个类的概率

probs = rf.predict_proba(X)

import pandas as pd

probs_df = pd.DataFrame(probs, columns=['', ''])

probs_df['was_correct'] = rf.predict(X) == y

import matplotlib.pyplot as plt

f, ax = plt.subplots(figsize=(7, 5))

probs_df.groupby('').wa

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值