- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试使用分类的决策树来根据某些参数识别两个类(重命名为 0 和 1)。我使用数据集训练它,然后在“测试数据集”上运行它。当我尝试计算测试数据集中每个数据点的概率时,它仅返回 0 或 1。我不知道是什么问题。
这里是示例代码:
clf=tree.DecisionTreeClassifier(random_state=0)
结果是:
trained=clf.fit(data,identifier) # 标识符为0或1的训练数据
预测=训练有素的预测(测试数据)
In [9]: predict
Out[9]:
array([0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0,
1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0,
0, 0, 1, 0, 0, 0])
In [10]: trained.predict_proba(test_data)[:,1]
Out[10]:
array([ 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 1., 1., 1.,
0., 0., 1., 0., 0., 0., 0., 1., 0., 0., 1., 1., 0.,
1., 0., 1., 0., 0., 1., 0., 0., 0., 1., 1., 1., 1.,
0., 1., 1., 0., 0., 1., 0., 0., 0., 1., 0., 0., 0.])
我想生成 ROC,此时它只为 FPR/TPR 返回 3 个数据点。
这是完整的数据集:标识符是“数据”的最后一列。
训练数据:
Spectral_Index,W1-W2,W2-W3,HR0.3-100,HR50-2,Gamma,Class
1.4304664,0.61,2.18,0.3819051,0.99992716,1.93,0
1.6969398,0.54,1.93,0.66479063,0.9999814,2.11,0
2.233997,1.02,3.18,0.55532146,0.9999979,2.07,0
2.230639,0.77,2.34,0.0012237767,1.0,1.81,0
1.7325432,0.71,2.27,0.34395835,1.0,1.9,0
1.8728518,0.8,2.14,0.4255796,1.0,1.96,0
1.9818852,0.7,2.18,-0.08978904,1.0,1.66,0
2.3864453,0.95,2.51,0.109010585,0.98401743,1.81,0
2.5911317,0.94,2.49,0.60381645,0.99991965,2.03,0
1.9564596,0.81,2.29,0.3843,0.9999495,2.08,0
2.1506176,0.93,2.62,0.28551856,0.9999999,1.91,0
1.9069784,0.62,1.76,0.041608978,1.0,1.86,0
1.6216202,0.77,2.11,-0.14271076,1.0,1.7,0
2.276335,0.68,2.14,0.40399882,1.0,2.06,0
2.2430172,1.0,2.94,0.61844856,1.0,2.12,0
1.0226197,0.66,2.07,-0.14886126,1.0,1.84,0
2.2564504,1.06,2.77,0.6974536,0.99844635,2.16,0
2.2819016,0.88,2.37,0.30696234,0.999996,1.86,0
1.4881139,0.7,2.09,0.40853307,1.0,1.82,0
2.4640048,0.9,2.39,0.35103577,1.0,2.02,0
2.656071,0.72,2.29,0.21568911,0.9999046,2.11,0
1.7204628,0.62,2.01,0.19794853,1.0,1.8,0
1.9134961,0.86,2.27,0.37281907,1.0,1.94,0
1.3061943,0.67,2.01,0.3463318,0.99999976,1.86,0
1.8845558,0.64,2.01,0.12364135,0.9999834,1.84,0
2.4409518,1.12,3.31,0.7502838,1.0,2.17,0
1.9501582,0.85,2.34,0.29961613,0.9999974,1.92,0
2.1314192,1.03,2.62,0.69623667,1.0,2.28,0
1.7345899,0.69,2.61,0.38524705,0.99999887,2.09,0
1.7095753,0.75,2.08,0.21696341,0.9999987,1.95,0
1.9115254,0.83,2.17,-0.046689913,1.0,1.85,0
1.565369,0.67,2.01,-0.04827315,0.9999915,1.79,0
2.2971635,0.59,2.1,0.35741857,1.0,2.0,0
3.042759,1.06,2.94,0.70878696,0.9999844,2.15,0
2.340724,0.96,2.74,0.42822766,0.99999416,1.97,0
1.8552977,0.74,2.09,0.07262661,1.0,1.69,0
2.0324602,0.66,2.05,-0.07643526,0.9999982,1.83,0
1.8508979,0.67,1.96,0.054557554,0.99997455,1.75,0
2.7983437,0.96,2.58,0.8554537,0.9999992,2.2,0
2.1728642,1.09,3.05,0.61488354,1.0,2.04,0
3.113785,0.66,1.85,0.48011553,0.99995273,1.95,0
3.0665417,0.78,2.19,0.27814054,1.0,1.86,0
2.0060341,0.83,2.39,0.20785762,0.9999502,1.85,0
2.1786506,0.57,2.0,0.33096096,1.0,1.91,0
1.823961,0.72,1.96,-0.103285044,1.0,1.6,0
1.612012,0.68,2.15,-0.3136376,0.65517294,1.52,0
2.1615896,0.87,2.4,0.47535577,1.0,2.04,0
2.3053634,1.06,2.92,0.67040676,0.9991328,2.15,0
1.7525402,0.73,2.12,0.25563625,0.9999979,1.92,0
2.7306526,0.91,2.35,0.68943393,-0.4308276,2.1,0
2.2549937,1.07,2.91,0.6077795,0.9999626,2.04,0
2.0924683,0.69,2.04,-0.068183094,0.3497915,1.77,0
2.210627,0.84,2.09,0.6309954,0.99999976,1.99,0
2.4609168,0.67,2.08,0.29552716,0.99964327,1.96,0
2.5169518,0.84,2.45,0.35437247,0.9999745,1.92,0
2.1841373,0.9,2.51,0.5617463,1.0,2.15,0
3.0673068,0.8,2.22,0.17641401,1.0,1.9,0
2.6202004,0.97,2.47,0.36663872,1.0,2.03,0
1.9694642,0.95,2.54,0.33140072,0.99998665,2.04,0
1.8766946,0.84,2.32,-0.024992371,0.99999803,1.94,0
2.9352057,1.2,2.96,0.6385377,0.9951195,2.18,0
1.4075257,0.86,2.27,0.046303034,0.9999998,1.81,0
1.8769667,0.6,2.0,0.08842805,0.15410244,1.83,0
1.2585826,0.71,1.96,0.005930161,0.78259146,1.72,0
2.2046561,0.9,2.37,0.62021697,1.0,2.07,0
1.0217602,0.49,1.89,-0.26944694,0.9999997,1.66,0
2.1021683,1.05,2.78,0.5306551,1.0,2.14,0
2.4789429,0.94,2.52,0.34224525,0.9999965,2.01,0
2.1449182,0.8,2.32,0.37609425,0.9997282,2.25,0
2.7071185,0.83,2.36,0.75363404,1.0,2.31,0
1.8445525,1.04,2.76,0.6075378,0.88632137,2.14,0
1.6024263,1.09,2.63,0.64461184,1.0,2.18,0
2.0292685,0.53,2.15,0.090091705,1.0,1.92,0
2.0858748,0.71,1.86,0.14351326,0.9999994,1.88,0
2.1292083,0.81,2.31,0.33257455,1.0,1.95,0
1.6344122,0.84,2.38,0.6371139,0.9999998,2.11,0
1.7532507,0.75,2.04,0.16182575,1.0,1.78,0
2.2479355,0.97,2.72,0.41953298,1.0,2.04,0
2.5790315,1.07,2.96,0.7216893,0.9999953,2.11,0
3.0039942,1.03,2.44,0.8042694,0.9998856,2.25,1
3.7599833,1.16,3.23,0.9095345,0.66683024,2.39,1
2.8912013,1.05,2.67,0.85215354,0.9967052,2.27,1
3.8784094,1.11,3.18,0.6971026,1.0,2.19,1
2.1862392,1.13,2.7,0.65855825,1.0,2.28,1
2.7684402,1.16,2.79,0.9261603,-0.9540385,2.35,1
1.7551649,0.56,2.18,0.23092282,1.0,1.98,1
2.804592,1.13,2.98,0.84827685,1.0,2.3,1
1.9874831,1.0,2.98,0.87599415,1.0,2.21,1
2.5059428,1.16,2.79,0.97649753,0.9997586,2.42,1
2.812127,1.12,3.11,0.87392867,1.0,2.21,1
2.9445121,1.06,3.17,0.8849491,1.0,2.41,1
2.7388847,1.11,2.78,0.84986275,0.96669436,2.32,1
2.1416433,1.1,3.61,0.7671358,0.9999998,2.29,1
2.3661094,1.05,3.16,0.73194104,0.99990827,2.14,1
2.761189,1.09,2.81,0.7681978,-0.99955946,2.23,1
2.6658804,1.02,3.36,0.8036201,0.98403203,2.28,1
2.720667,0.99,2.78,0.97055733,0.9781505,2.48,1
2.6812658,0.98,3.05,0.73290765,1.0,2.09,1
1.4784714,0.62,1.97,0.418,1.0,2.02,0
1.7488811,0.7,2.05,0.418,0.99999624,2.02,0
测试数据:
Spectral_Index,W1-W2,W2-W3,HR0.3-100,HR50-2,Gamma
1.6724254,0.95,2.58,0.92031854,1.0,2.15
2.552926,0.93,2.74,0.63588345,-0.30092865,2.18
2.5737462,0.86,2.22,0.43023747,1.0,2.08
2.1701677,0.62,2.19,0.6892167,1.0,2.15
3.6152358,0.96,2.58,0.67760235,0.99704355,2.06
3.6193092,0.82,2.34,0.4083981,0.9973078,2.04
2.0209844,1.02,2.86,0.8595182,-0.9979041,2.36
2.166221,1.07,3.0,0.7177616,-0.99961376,2.3
2.7933478,0.94,2.4,0.678935,1.0,2.12
2.2969048,0.86,2.29,0.18689133,1.0,1.96
3.1255674,1.15,2.77,0.9290483,0.6387009,2.28
2.3548958,1.01,2.46,0.75331503,-1.0,2.21
3.9791226,1.15,3.04,0.87006325,-0.99919724,2.43
2.3430493,0.85,2.42,0.81132597,-0.9999996,2.04
3.7431624,0.79,2.57,0.704,0.99952716,2.20784
3.1846259,1.14,2.85,0.9104803,0.99891067,2.3
3.1416001,0.73,2.26,0.5679769,1.0,1.98
2.670179,0.85,2.66,0.7376513,0.97939825,2.1
3.010911,0.79,2.38,0.21750104,0.21187924,1.82
1.4430648,0.9,2.38,0.7361963,0.999758,2.11
2.8149416,1.07,2.62,0.94750744,0.9967568,2.4
3.8395922,1.09,2.91,0.27485812,0.99887043,2.05
3.1686394,0.66,2.11,0.529385,1.0,1.9
3.190167,1.09,3.1,0.8501991,0.9507157,2.23
3.8597586,1.13,3.64,0.89043206,0.17880388,2.42
2.1516426,0.85,2.24,0.6673518,0.9985168,2.2
2.1318088,0.98,2.64,0.85542095,1.0,2.22
1.6740437,0.97,2.99,0.86632746,0.9983954,2.41
4.273427,1.01,2.71,0.8941501,0.64256436,2.47
2.284782,0.92,2.7,0.5820462,0.6981752,2.1
3.343603,1.06,2.84,0.6901738,0.83269715,2.13
5.766362,1.2,3.74,0.99009913,0.99998844,2.49
2.1547525,0.95,3.02,0.75229234,0.99604213,2.57
2.9853358,0.91,2.37,0.62881154,-0.98792726,2.06
2.8614197,0.82,2.15,0.75643075,1.0,2.19
3.6815813,1.14,3.24,0.8886577,-0.030438267,2.39
4.539201,1.17,2.83,0.93989134,0.23378997,2.55
3.35261,1.1,2.73,0.9184936,0.9998006,2.41
3.6697345,1.16,3.57,0.9515105,0.9999988,2.43
1.9781204,0.91,2.85,-0.06649571,0.9999991,1.7
2.6618617,1.1,3.24,0.8348949,-0.9834342,2.29
3.8140056,1.18,3.25,0.8766021,1.0,2.39
2.1926181,1.05,2.3,0.6880097,1.0,2.3
2.0248337,0.83,2.29,0.3604591,0.46159065,2.05
3.904931,1.13,2.46,0.9100119,1.0,2.32
1.9945884,0.94,2.5,0.4632657,0.9869119,2.05
3.3342967,1.1,3.04,0.51323855,-0.5262294,2.23
2.3138714,0.91,2.36,0.90414697,0.9999977,2.29
2.3118904,1.04,3.01,0.87289846,0.998577,2.29
2.246307,1.07,2.72,0.6147379,0.9999993,2.11
1.6369493,0.89,2.34,0.61421084,0.9997295,2.22
3.6198807,0.93,2.62,0.7463702,0.9994778,2.07
最佳答案
没有问题 - 树的行为完全符合预期。
决策树根据落入给定叶子的每个类别的样本数计算类别概率。
The default values for the parameters controlling the size of the trees (e.g.
max_depth
,min_samples_leaf
, etc.) lead to fully grown and unpruned trees
即树一直生长到完全(过度)适合训练数据为止。这意味着每个叶子中的所有训练样本都属于同一类,而测试样本要么匹配该类 (p=1),要么不匹配该类 (p=0)。
为了获得更精细的概率估计,您可以限制 min_samples_leaf
以便每片叶子中的样本数量最少,这些样本将用于计算概率(使用一个样本您会得到 [0, 1] - 例如 10 个样本,您可以获得 [0, 0.1, 0.2, ..., 0.9, 1])。您将不得不试验这些设置,以找出最适合您和您的数据的数字。
关于python - DecisionTreeClassifier predict_proba 返回 0 或 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48219986/
假设我的标记数据有两个类 1 和 0。当我在测试集上运行 Predict_proba 时,它返回一个包含两列的数组。哪一列对应哪个类? 最佳答案 第 0 列对应于类 0,第 1 列对应于类 1。 关于
只是一个简单的问题,如果我想将对象分类为 0 或 1,但我希望模型返回一个“可能性”概率,例如,如果一个对象是 0.7,这意味着它有 0.7 的机会进入第 1 类,我是做回归还是坚持使用分类器并使用
我想通过交叉验证从逻辑回归模型预测概率。我知道您可以获得交叉验证分数,但是否可以从 predict_proba 返回值而不是分数? # imports from sklearn.linear_mode
我在我的数据集上训练了一个 RandomForestClassifier,可以从文本正文中预测 8 个不同的主题。对于给定示例,数据集如下所示 X_train = [[0,0,0,0,0,1,0,0,
我正在使用 Python 的 sklearn 对文本进行分类。 我调用函数 predict_proba,它看起来像这样: [[ 6.74918834e-53 1.59981248e-51 2
我正在使用 scikit-learn 通过逻辑回归来实现分类。使用 predict() 函数预测类标签,而使用 predict_proba() 函数打印预测概率。 下面粘贴了代码片段: # Parti
我正在处理一个多类、高度不平衡的分类问题。我使用随机森林作为基础分类器。 我必须在考虑多个标准(指标:精度、召回 conf_matrix、roc_auc)的情况下给出模型性能报告。 模型火车: rf
我使用 Scikit-learn 和 XGBoost 在同一数据上训练了 2 个梯度提升模型。 Scikit-learn 模型 GradientBoostingClassifier( n_es
scikit-learn 的 DecisionTreeClassifier 支持通过 predict_proba() 函数预测每个类的概率。 DecisionTreeRegressor 中不存在这一点
所以我使用 sci-kit learns RandomForestClassifier 将天文来源的数据分为三类。为了让我的问题更简单,我在测试集中仅使用了两个来源,并获得了 predict_prob
我正在使用 sklearn 库来训练和测试我的数据。 targetDataCsv = pd.read_csv("target.csv","rt")) testNormalizedCsv = csv.
我试图通过调用 Keras 模型的 predict_proba() 生成类(class)分数,但似乎没有这个函数!它是否因为我在谷歌中看到一些例子而被弃用?我正在使用 Keras 2.2.2。 最佳答
运行Python 3.7.3 我制作了一个简单的 GMM 并将其拟合到一些数据。使用predict_proba方法,返回的是1和0,而不是属于每个高斯的输入的概率。 我最初在更大的数据集上尝试过这个,
在docs , predict_proba(self, x, batch_size=32, verbose=1) 是 Generates class probability predictions f
我正在尝试使用LinearSVC 分类器 更新:添加了导入 import nltk from nltk.tokenize import word_tokenize from nltk.classify
这是来自 How to know what classes are represented in return array from predict_proba in Scikit-learn 的后续
我有许多类和对应的特征向量,当我运行 predict_proba() 时,我会得到这个: classes = ['one','two','three','one','three'] feature =
我正在尝试了解如何 sklearn's MLP Classifier检索其 predict_proba 函数的结果。 该网站仅列出: Probability estimates 还有很多其他的,例如
predict_proba 返回神经网络中的误差 我在这个链接上看到了例子 https://machinelearningmastery.com/how-to-make-classification-
我训练了一个简单的随机森林分类器,然后当我使用相同的测试输入测试预测时: rf_clf.predict([[50,0,500,0,20,0,250000,1.5,110,0,0,2]]) rf_clf
我是一名优秀的程序员,十分优秀!