Java研究API方法(Java look into API method)
有没有办法通过API查看最初给定的方法? 我是编程的初学者,有时候在使用给定的方法时会感觉像是采取了大量的快捷方式,而且如果我不得不自己编写它,我真的不知道会使用什么工具。
提前感谢给出的建议。
Is there a way to look into originally given methods by API? I am a beginner in programming and sometimes feel like taking huge shortcuts when using given methods and not really having an idea what tools i would use if i had to write it on my own.
Thanks in advance for given advices.
原文:https://stackoverflow.com/questions/35239610
最满意答案
除了迭戈的回答:
RandomForestClassifier
是一个分类器,用于预测离散数量的类的类分配,而无需在类标签之间进行排序。如果你想输出连续的浮点数,你应该尝试使用
RandomForestRegressor
等回归模型。您可能必须将输出限制在范围[0,6],因为没有保证,模型不会输出预测值,例如
6.2
。编辑以回答第二点,
predict
方法需要样本清单。 因此,您应该为您的案例提供一份样品清单。 尝试:print rf.predict([testdataset[-1]])
或者可选地:
print rf.predict(testdataset[-1:])
我想知道你为什么在这种情况下不会出错。
编辑 :输出没有意义:数据集的形状是什么?
>>> print np.asarray(train).shape >>> print np.asarray(target).shape >>> print np.asarray(testdataset).shape
In addition to Diego's answer:
RandomForestClassifier
is a classifier to predict class assignment for a discrete number of classes without ordering between the class labels.If you want to output continuous, floating point rating, you should try to use a regression model such as
RandomForestRegressor
instead.You might have to clamp the output to the range [0, 6] as there is no guaranty the model will not output predictions such as
6.2
for instance.Edit to answer you second point, the
predict
method expects a list of samples. Hence you should provide it with a list of one sample in your case. Try:print rf.predict([testdataset[-1]])
or alternatively:
print rf.predict(testdataset[-1:])
I wonder why you don't get an error in that case.
Edit: the ouput does not really make sense: what is the shape of your datasets?
>>> print np.asarray(train).shape >>> print np.asarray(target).shape >>> print np.asarray(testdataset).shape
相关问答
更多-
除了迭戈的回答: RandomForestClassifier是一个分类器,用于预测离散数量的类的类分配,而无需在类标签之间进行排序。 如果你想输出连续的浮点数,你应该尝试使用RandomForestRegressor等回归模型。 您可能必须将输出限制在范围[0,6],因为没有保证,模型不会输出预测值,例如6.2 。 编辑以回答第二点, predict方法需要样本清单。 因此,您应该为您的案例提供一份样品清单。 尝试: print rf.predict([testdataset[-1]]) 或者可选地: ...
-
我知道这是迟了10个月,但我认为你要找的是来自imblearn的BalancedBaggingClassifier 。 imblearn.ensemble.BalancedBaggingClassifier(base_estimator=None, n_estimators=10, max_samples=1.0, max_features=1.0, bootstrap=True, bootstrap_features=False, oob_score=False, warm_start=False, ...
-
感谢质疑太好的结果! 数据中的每个要素(列)仅包含少量不同的值。 如果我计算正确,那么只有14个唯一不同的行 。 这有两个含义: 您很可能过度拟合,因为您只有14个有效样本但有36个特征。 相同的行很可能再次出现在测试集和训练集中。 这意味着您正在测试模型所训练的相同数据。 由于该模型完全适合这些数据,因此您可以获得完美的结果。 编辑 我刚才意识到我没有回答实际问题 - 如何解决? 那要看。 如果运气好,有人在准备数据时出错。 如果数据是正确的,事情就会变得更加困难。 首先,删除重复的行,例如通过执行np. ...
-
随机森林不进行特征提取。 他们使用给定的数据集中的特征,在这个例子中,这些特征只是来自Olivetti faces数据集的像素强度。 max_features参数确定“查找最佳拆分时要考虑的ExtraTreesRegressor数”(在林使用的决策树学习算法内)。 值32可能是凭经验确定的。 Random forests do not do feature extraction. They use the features in the dataset given to them, which in thi ...
-
从评论中回答答案。 尝试通过设置较小的n_estimators参数来减少树的数量。 然后,您可以尝试使用max_depth或min_samples_split控制树深度,并使用深度交易来增加估算量。 Moving answer from comments. Try reducing the number of trees by setting a smaller n_estimators parameter. You can then try to control the tree depth using ...
-
隔离森林(Isolation Forest)[2023-10-22]
使用你的代码 在您的代码打印y_pred_outliers之后 : # fit the model clf = IsolationForest(max_samples=100, random_state=rng) clf.fit(X_train) y_pred_train = clf.predict(X_train) y_pred_test = clf.predict(X_test) y_pred_outliers = clf.predict(X_outliers) print(y_pred_outli ... -
带有bootstrap的随机森林=在scikit-learn python中为False(Random Forest with bootstrap = False in scikit-learn python)[2022-01-31]
您似乎将观察的引导与特征的采样混为一谈。 统计学习简介为随机森林提供了非常好的介绍。 随机森林的好处来自于通过对观测和特征进行采样来创建各种各样的树木。 Bootstrap = False告诉它在有或没有替换的情况下对观察结果进行采样 - 当它为False时仍然应该进行采样,只是没有替换。 您可以通过将max_features设置为功能的共享或仅仅是整数来告诉它要采样的功能份额(这是您通常会调整以找到最佳参数的内容)。 当你构建每棵树时,你不会每天都有这样的事情 - 这就是RF价值的来源。 每棵树都是一个非 ... -
最可能的情况是您的培训数据没有很好的预测价值。 鉴于你试图“预测股票交易的方向”,这应该不会令人意外,因为这个问题是不可能解决的。 The most likely scenario is that your training data does not have great predictive value. Given that you're attempting to "predict stock exchange direction", this shouldn't be surprising sin ...
-
随机森林分类 - SciKit与Weka预测有100个特征(Random Forest Classification - SciKit vs Weka on prediction with 100 features)[2022-04-15]
结束评论中的讨论,使StackOverflow将此问题标记为已回答: 显然OP能够通过丢弃具有缺失值的样本并使用GridSearchCV网格搜索最佳超参数值来达到可比性。 在这种情况下,单热编码分类特征显然不会对结果产生太大影响。 Wrapping up the discussion in the comments to make StackOverflow mark this question as answered: Apparently OP was able to reach comparable ... -
如果只是将级别映射到数值,python会将您的值视为数字。 也就是说,即使你的水平最初是无序的,数字1<2等等。 想想“距离”问题。 1到2之间的距离为1,介于1和3之间为2.但是,您的分类变量之间的原始距离是多少? 例如,“香蕉”“桃子”和“苹果”之间的距离是多少? 你认为他们都是平等的吗? 关于虚拟变量:如果你有3个类并创建3个虚拟变量,它们不仅仅是相关的,它们是线性相关的。 这永远不会好。 If you just map levels to numeric values, python will tr ...