首页 \ 问答 \ Java研究API方法(Java look into API method)

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
更新时间:2022-09-18 12:09

最满意答案

除了迭戈的回答:

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 ...
  • 使用你的代码 在您的代码打印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 = 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 ...
  • 结束评论中的讨论,使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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)