成功解决TypeError: unsupported operand type(s) for %: 'NoneType' and 'dict'

简介: 成功解决TypeError: unsupported operand type(s) for %: 'NoneType' and 'dict'

解决问题


TypeError: unsupported operand type(s) for %: 'NoneType' and 'dict'


190520:第二次遇到




解决方法:暂时注释掉了下边代码,运行了后边的代码。

原因分析:kNNR_uni.predict(X_test_split)方法,对传入的输入的数据不支持,尽管经过多次测试,没有发现其他除了整型、浮点型等其他类型的数据。


from sklearn.neighbors import KNeighborsRegressor

#T2.1、kNN(平均回归)weights='uniform'。

kNNR_uni = KNeighborsRegressor(weights='uniform')

kNNR_uni.fit(X_train_split, y_train_split)

kNNR_uni_predict = kNNR_uni.predict(X_test_split)

#T2.2、kNN(加权回归):weights='distance'。

kNNR_dis = KNeighborsRegressor(weights='distance')

kNNR_dis.fit(X_train_split, y_train_split)

kNNR_dis_predict = kNNR_dis.predict(X_test_split)


解决思路


类型错误:%不支持操作数类型:'NoneType'和'dict'



解决方法


T1、还没有完全解决,暂时先对%前后的变量分别输出

print(globals()['__doc__'] % locals())

改为

print(globals()['__doc__'], locals())


期待网友更好的解答!


相关文章
|
3月前
|
计算机视觉 Python
解决 NoneType‘ object has no attribute ‘astype’ 问题
解决 NoneType‘ object has no attribute ‘astype’ 问题
78 0
成功解决TypeError: ‘encoding’ is an invalid keyword argument for this function
成功解决TypeError: ‘encoding’ is an invalid keyword argument for this function
|
数据库 OceanBase
RuntimeError: 'PluginContext' object has no attribute 'set_variable'
RuntimeError: 'PluginContext' object has no attribute 'set_variable'
99 2
|
Python
AttributeError: 'dict' object has no attribute 'has_key'
AttributeError: 'dict' object has no attribute 'has_key'
125 0
TypeError: custom() got an unexpected keyword argument ‘path‘
TypeError: custom() got an unexpected keyword argument ‘path‘
135 0
|
PyTorch TensorFlow 算法框架/工具
TensorflowConv2D:AttributeError: ‘int‘ object has no attribute ‘lower‘
TensorflowConv2D:AttributeError: ‘int‘ object has no attribute ‘lower‘
246 0
TensorflowConv2D:AttributeError: ‘int‘ object has no attribute ‘lower‘
|
计算机视觉
成功解决TypeError: __init__() got an unexpected keyword argument 'n_iterations'
成功解决TypeError: __init__() got an unexpected keyword argument 'n_iterations'
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
430 0
TypeError: 'encoding' is an invalid keyword argument for this function
TypeError: 'encoding' is an invalid keyword argument for this function
245 0
|
Python
SyntaxError: Missing parentheses in call to 'print'
SyntaxError: Missing parentheses in call to 'print'
127 0