我知道已经有很多关于断言失败的内容了。但没有一个对我有用。听我说。
这是代码:
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
集成开发环境:
Visual Studio Code
代码在 Google Colab 中运行良好。那么为什么它只发生在 IDE 中呢?如果是设置或环境问题,我该怎么办?这是我第一次使用 Visual Studio Code。
谢谢
最佳答案
这里是该库的作者。代码中有一个错误,只有当设置定义了宏 _GLIBCXX_ASSERTIONS
时才会触发,否则不会显示。现在应该已在最新版本 (1.7.0) 中修复 - 请重试 (pip install -U outliertree
),如果问题仍然存在,请在 github 问题跟踪器中发表评论。
关于python - Visual Studio Code Python 中的 "Assertion ' __builtin_expect(__n < this->size(), true) ' failed"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66892158/