成功解决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())


期待网友更好的解答!


相关文章
|
8月前
|
计算机视觉 Python
解决 NoneType‘ object has no attribute ‘astype’ 问题
解决 NoneType‘ object has no attribute ‘astype’ 问题
161 0
|
开发者
SyntaxError: cannot assign to literal错误
SyntaxError: cannot assign to literal错误
2368 1
成功解决TypeError: ‘encoding’ is an invalid keyword argument for this function
成功解决TypeError: ‘encoding’ is an invalid keyword argument for this function
|
8月前
Uncaught TypeError: Cannot use ‘in‘ operator to search for ‘path‘ in undefined
Uncaught TypeError: Cannot use ‘in‘ operator to search for ‘path‘ in undefined
|
8月前
|
Python
完美解决丨TypeError: fun() takes 2 positional arguments but 3 were given
完美解决丨TypeError: fun() takes 2 positional arguments but 3 were given
|
8月前
|
Python
完美解决丨+# TypeError: ‘dict_keys‘ object does not support indexing
完美解决丨+# TypeError: ‘dict_keys‘ object does not support indexing
|
计算机视觉
成功解决TypeError: __init__() got an unexpected keyword argument 'n_iterations'
成功解决TypeError: __init__() got an unexpected keyword argument 'n_iterations'
TypeError: custom() got an unexpected keyword argument ‘path‘
TypeError: custom() got an unexpected keyword argument ‘path‘
167 0
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
480 0
TypeError: 'encoding' is an invalid keyword argument for this function
TypeError: 'encoding' is an invalid keyword argument for this function
280 0

热门文章

最新文章