我知道断言失败已经有很多了。但对我来说都没有用。听我说完。
这是代码:
import numpy as np, pandas as pd
from outliertree import OutlierTree
### random data frame with an obvious outlier
nrows = 100
np.random.seed(1)
df = pd.DataFrame({
"numeric_col1" : np.r_[np.random.normal(size = nrows - 1), np.array([float(1e6)])],
"numeric_col2" : np.random.gamma(1, 1, size = nrows),
"categ_col" : np.random.choice(['categA', 'categB', 'categC'], size = nrows)
})
### test data frame with another obvious outlier
df_test = pd.DataFrame({
"numeric_col1" : np.random.normal(size = nrows),
"numeric_col2" : np.r_[np.array([float(-1e6)]), np.random.gamma(1, 1, size = nrows - 1)],
"categ_col" : np.random.choice(['categA', 'categB', 'categC'], size = nrows)
})
### fit model
outliers_model = OutlierTree()
outliers_df = outliers_model.fit(df, outliers_print = 10, return_outliers = True) # gives error
### find outliers in new data
new_outliers = outliers_model.predict(df_test)
### print outliers in readable format
outliers_model.print_outliers(new_outliers)这是一个错误:
/usr/include/c++/10/bit/stl_vector.h:1045: std::vector<_Tp,_Alloc>::reference std::vector<_Tp,_Alloc>::operatorstd::vector<_Tp, _Alloc>::size_type with _Tp = char;_Alloc =std:allocator;std::vector<_Tp,_Alloc>::reference = char&;std::vector<_Tp,_Alloc>::size_type =长无符号int:断言'__builtin_expect(__n < this->size(),true)‘失败。中止(核心倾弃)
错误发生在线上:
outliers_df = outliers_model.fit(df, outliers_print = 10, return_outliers = True)
Python版本:
LinuxPython3.9.2(默认情况下,2021年2月20日,00:00:00) GCC 10.2.1 20201125 (红帽10.2.1-9)
操作系统:
Fedora 5.10.12-200.fc33.x86_64
IDE:
Visual代码
代码在Google中运行良好。那么,为什么它只发生在IDE中呢?如果是环境或环境问题,我能做些什么呢?这是我第一次使用Visual代码。
谢谢
发布于 2021-04-01 04:23:26
这里图书馆的作者。代码中有一个错误,只有在安装程序定义了宏_GLIBCXX_ASSERTIONS之后才会触发,否则不会出现。现在应该修复最新版本(1.7.0) -如果问题仍然存在,请重试(pip install -U outliertree)并在github问题跟踪器中发表评论。
发布于 2021-03-31 17:21:11
我对OutlierTree不太了解,不知道如何修复错误。但是,您看到的错误在函数std::vector::operator[]中,它是std::vector按索引函数进行的访问。断言错误仅仅意味着您试图以大于向量长度的索引访问某个项。
至于为什么您只在VS代码中看到此错误,我认为这是因为断言通常只在调试模式下进行检查。Google可能是在没有断言的情况下在发布模式下编译的--这并不意味着您不访问超出范围的项,它只是没有捕捉到错误。
我建议您使用gdb或其他调试器来了解您尝试访问哪个向量,然后在您的问题上附加一个堆栈跟踪。也许向OutlierTree提交一个bug报告--这似乎是他们可以更好地处理的事情。
https://stackoverflow.com/questions/66892158
复制相似问题