我知道已经有很多关于断言失败的问题。但是没有一个对我有用。听我说完
代码如下:
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/bits/stl_vector.h:1045: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = char; _Alloc = std::allocator; std::vector<_Tp, _Alloc>::reference = char&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]: Assertion '__builtin_expect(__n < this->size(), true)' failed. Aborted (core dumped)
错误发生在第行:
outliers_df = outliers_model.fit(df, outliers_print = 10, return_outliers = True)
Python版本:
Python 3.9.2 (default, Feb 20 2021, 00:00:00) [GCC 10.2.1 20201125 (Red Hat 10.2.1-9)] on linux
操作系统:
Fedora 5.10.12-200.fc33.x86_64
IDE:
Visual Studio Code
代码在GoogleColab中运行良好。那么为什么它只发生在IDE中呢?如果是环境或环境问题,我该怎么办?这是我第一次使用VisualStudio代码
多谢各位
这里是图书馆的作者。代码中有一个bug,只有在安装程序定义了宏
_GLIBCXX_ASSERTIONS
时才会触发,否则不会显示。它现在应该在最新版本(1.7.0)中修复-如果问题仍然存在,请重试(pip install -U outliertree
),并在github问题跟踪程序中进行评论我对异常树了解不够,不知道如何修复错误。但是,您看到的错误在函数
std::vector::operator[]
中,它是std::vector
的索引访问函数。断言错误只是意味着您试图访问索引大于向量长度的项至于为什么您只在VS代码中看到这个错误,我假设这是因为断言通常只在调试模式下检查。GoogleCollab可能是在没有断言的发布模式下编译的——这并不意味着你不能访问越界项目,它只是不能捕获错误
我建议您使用gdb或其他调试器来了解您试图越界访问的向量,然后在问题上附加stacktrace。也许用OutlierTree提交一份bug报告——这似乎是他们可以更好地处理的事情
相关问题 更多 >
编程相关推荐