Scipy hstack results in “TypeError: no supported conversion for types: (dtype('float64'), dtype('O')
X =sp.sparse.hstack((X, OtherColumn.values)) #error here
sc = preprocessing.StandardScaler().fit(X)
X = sc.transform(X)
X_test = sc.transform(X_test)
Full error message:
--------------------------------------------------------------------------- TypeErrorTraceback (most recent call last)
in () ---> 47 X =sp.sparse.hstack((X, OtherColumn.values)) 48 sc = preprocessing.StandardScaler().fit(X) 49 X = sc.transform(X)C:\Users\Simon\Anaconda\lib\site-packages\scipy\sparse\construct.pyc in hstack(blocks, format, dtype) 421 422""" --> 423return bmat([blocks], format=format, dtype=dtype) 424 425 C:\Users\Simon\Anaconda\lib\site-packages\scipy\sparse\construct.pyc in bmat(blocks, format, dtype) 537nnz = sum([A.nnz for A in blocks[block_mask]]) 538if dtype is None: --> 539dtype = upcast(*tuple([A.dtype for A in blocks[block_mask]])) 540 541row_offsets = np.concatenate(([0], np.cumsum(brow_lengths)))C:\Users\Simon\Anaconda\lib\site-packages\scipy\sparse\sputils.pyc in upcast(*args) 58return t 59 ---> 60raise TypeError('no supported conversion for types: %r' % (args,)) 61 62 TypeError: no supported conversion for types: (dtype('float64'), dtype('O'))
【Scipy hstack results in “TypeError: no supported conversion for types: (dtype('float64'), dtype('O')】修改方法如下:
sparse.hstack(X, A) # error
sparse.hstack(X.astype(object), A) # cast X to object;
return object
sparse.hstack(X, A.astype(float)) # cast A to float;
return float
hstack(X.A, A) # make X dense, result will be type object
推荐阅读
- 推荐系统论文进阶|CTR预估 论文精读(十一)--Deep Interest Evolution Network(DIEN)
- Python专栏|数据分析的常规流程
- Python|Win10下 Python开发环境搭建(PyCharm + Anaconda) && 环境变量配置 && 常用工具安装配置
- Python绘制小红花
- Pytorch学习|sklearn-SVM 模型保存、交叉验证与网格搜索
- OpenCV|OpenCV-Python实战(18)——深度学习简介与入门示例
- python|8. 文件系统——文件的删除、移动、复制过程以及链接文件
- 爬虫|若想拿下爬虫大单,怎能不会逆向爬虫,价值过万的逆向爬虫教程限时分享
- 分布式|《Python3网络爬虫开发实战(第二版)》内容介绍
- java|微软认真聆听了开源 .NET 开发社区的炮轰( 通过CLI 支持 Hot Reload 功能)