简体   繁体   English

类型错误:to_numeric() 缺少 1 个必需的位置参数:'arg'

[英]TypeError: to_numeric() missing 1 required positional argument: 'arg'

Hi I am new to Machine Learning and working on a fun project based on Crime Prediction.嗨,我是机器学习的新手,正在从事一个基于犯罪预测的有趣项目。 The following code block is returning an error.以下代码块返回错误。 I am using the datasets provided on the UCI ML Repo .我正在使用UCI ML Repo上提供的数据集。

df_d=pd.read_csv('communities-crime-full.csv')
df
df['highCrime'] = np.where(df['ViolentCrimesPerPop']>0.1, 1, 0)
Y = df['highCrime']

# print('total len is ',len(Y))
initial=pd.read_csv('communities-crime-full.csv')
initial = initial.drop('communityname', 1)
initial = initial.drop('ViolentCrimesPerPop', 1)
initial = initial.drop('fold', 1)
initial = initial.drop('state', 1)
initial = initial.drop('community', 1)
initial = initial.drop('county', 1)
skipinitialspace = True

feature_name=list(initial)
#initial=initial.convert_objects(convert_numeric=True)
initial=initial.apply(pd.to_numeric(errors='coerce').isnull())
New_data=initial.fillna(initial.mean())
# print('before...')
# print(initial)
# print('after...')
# print(New_data)  
clf = tree.DecisionTreeClassifier(max_depth=3)
# clf = tree.DecisionTreeClassifier()
clf = clf.fit(New_data, Y)
clf
fold=df['fold']
scores = cross_val_score(clf, New_data, Y,fold,'accuracy',10)
print('cross_val_accuracy is ',scores) 
print('cross_val_accuracy_avg is ',np.array(scores).mean()) 
scores = cross_val_score(clf, New_data, Y,fold,'precision',10)
print('cross_val_precision is ',scores) 
print('cross_val_precision_avg is ',np.array(scores).mean()) 
scores = cross_val_score(clf, New_data, Y,fold,'recall',10)
print('cross_val_recall is ',scores) 
print('cross_val_recall_avg is ',np.array(scores).mean())

I receive the following error我收到以下错误

TypeError                                 Traceback (most recent call last)
<ipython-input-53-9f206c43d444> in <module>()
     17 feature_name=list(initial)
     18 #initial=initial.convert_objects(convert_numeric=True)
---> 19 initial=initial.apply(pd.to_numeric(errors='coerce').isnull())
     20 New_data=initial.fillna(initial.mean())
     21 # print('before...')

TypeError: to_numeric() missing 1 required positional argument: 'arg'

Since you're trying to use pd.to_numeric as function reference, you can't call it with kwargs this way.由于您尝试使用pd.to_numeric作为 function 参考,因此您不能以这种方式使用 kwargs 调用它。

Either:任何一个:

initial = initial.apply(pd.to_numeric, errors='coerce')

Or Use lambda:或使用 lambda:

initial = initial.apply(lambda x: pd.to_numeric(x, errors='coerce'))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在ubuntu上,TypeError:chown()缺少1个必需的位置参数:&#39;numeric_owner&#39; - On ubuntu ,TypeError: chown() missing 1 required positional argument: 'numeric_owner' 类型错误:tokenize_lemmatize_spacy() 缺少 1 个必需的位置参数:&#39;first_arg&#39; - TypeError: tokenize_lemmatize_spacy() missing 1 required positional argument: 'first_arg' Pandas GroupBy.agg() 抛出 TypeError:aggregate() 缺少 1 个必需的位置参数:&#39;arg&#39; - Pandas GroupBy.agg() throws TypeError: aggregate() missing 1 required positional argument: 'arg' TypeError:scatter()缺少1个必需的位置参数:“ y” - TypeError: scatter() missing 1 required positional argument: 'y' TypeError:save()缺少1个必需的位置参数:“ self” - TypeError: save() missing 1 required positional argument: 'self' Python错误:TypeError:…缺少1个必需的位置参数: - Python ERROR: TypeError: … missing 1 required positional argument: TypeError:缺少1个必需的位置参数:&#39;ponto&#39; - TypeError: missing 1 required positional argument: 'ponto' 类型错误:函数缺少 1 个必需的位置参数 - TypeError: fuction missing 1 required positional argument 类型错误:search() 缺少 1 个必需的位置参数:&#39;name&#39; - TypeError: search() missing 1 required positional argument: 'name' tkinter TypeError:缺少1个必需的位置参数: - tkinter TypeError: missing 1 required positional argument:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM