TypeError: ‘DataFrame’ 对象不可调用,适用于 DBscan

数据集如下

storeid,revenue,profit,country101,11434,2345,IN101,12132,3445,US102,21343,4545,CH103,34423,3432,CH103,43435,3234,JP103,34345,3335,IN

代码如下

import pandas as pdfrom sklearn.cluster import DBSCANimport matplotlib.pyplot as pltimport numpy as npfrom sklearn.preprocessing import StandardScalerimport seaborn as snsfrom pylab import rcParamsfrom collections import Countersns.set(rc={'figure.figsize':(11.7,8.27)})sns.set_style('whitegrid')df = pd.read_csv('1.csv',index_col=None)df.head()df.columns = df.columns.str.replace(' ', '')dummies = pd.get_dummies(data = df)del dummies['Unnamed:0']model = DBSCAN(eps = 2.25, min_samples=19).fit(dummies)print (model)target = dummies.iloc[:,0]data = dummies.iloc[:,1:-1]outliers_df = pd.DataFrame(data)print (Counter(model.labels_))print(outliers_df(model.labels_==-1)) 

print(outliers_df(model.labels_==-1)) 抛出 TypeError: ‘DataFrame’ 对象不可调用


回答:

使用 布尔索引[] 来按掩码过滤:

print(outliers_df[model.labels_==-1])    revenue  profit  country_CH  country_IN  country_JP0    11434    2345           0           1           01    12132    3445           0           0           02    21343    4545           1           0           03    34423    3432           1           0           04    43435    3234           0           0           15    34345    3335           0           1           0

Related Posts

如何对SVC进行超参数调优?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

如何在初始训练后向模型添加训练数据?

我想在我的scikit-learn模型已经训练完成后再…

使用Google Cloud Function并行运行带有不同用户参数的相同训练作业

我正在寻找一种方法来并行运行带有不同用户参数的相同训练…

加载Keras模型,TypeError: ‘module’ object is not callable

我已经在StackOverflow上搜索并阅读了文档,…

在计算KNN填补方法中特定列中NaN值的”距离平均值”时

当我从头开始实现KNN填补方法来处理缺失数据时,我遇到…

使用巨大的S3 CSV文件或直接从预处理的关系型或NoSQL数据库获取数据的机器学习训练/测试工作

已关闭。此问题需要更多细节或更清晰的说明。目前不接受回…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注