goh*_*goh 1 python numpy pandas scikit-learn
我有以下内容
(Pdb) training
array(<418326x223957 sparse matrix of type '<type 'numpy.float64'>'
with 165657096 stored elements in Compressed Sparse Row format>, dtype=object)
(Pdb) training.shape
()
Run Code Online (Sandbox Code Playgroud)
为什么没有形状信息?
编辑:这就是我所做的:
training, target, test, projectids = generate_features(outcomes, projects, resources)
target = np.array([1. if i == 't' else 0. for i in target])
projectids = np.array([i for i in projectids])
print 'vectorizing training features'
d = DictVectorizer(sparse=True)
training = d.fit_transform(training[:10].T.to_dict().values())
#test_data = d.fit_transform(training.T.to_dict().values())
test_data = d.transform(test[:10].T.to_dict().values())
print 'training shape: %s, %s' %(training.shape[0], training[1])
print 'test shape: %s, %s' %(test_data.shape[0], test_data[1])
print 'saving vectorized instances'
with open(filename, "wb") as f:
np.save(f, training)
np.save(f, test_data)
np.save(f, target)
np.save(f, projectids)
Run Code Online (Sandbox Code Playgroud)
在这个时间点,我的训练形状仍然存在(10, 121).
稍后,我只是通过重新初始化4个变量
with open("../data/f1/training.dat", "rb") as f:
training = np.load(f)
test_data = np.load(f)
target = np.load(f)
projectids = np.load(f)
Run Code Online (Sandbox Code Playgroud)
但形状消失了.
有形状信息
array(<418326x223957 sparse matrix of type '<type 'numpy.float64'>'
with 165657096 stored elements in Compressed Sparse Row format>, dtype=object)
Run Code Online (Sandbox Code Playgroud)
这是一个项目的数组,0维度,因此形状().那个项目是dtype=object.具体来说,它是一个稀疏数组 - 显示屏中显示尺寸<418...x22....
我要去问DictVectorizer及fit_transform,但这并不重要.这是更改值的保存和加载操作.
我的猜测是你没有加载你刚写的文件.
你np.save(f,training)正在np.array用dtype 包装稀疏矩阵object.这就是你在负载上看到的.
training = training.item()
Run Code Online (Sandbox Code Playgroud)
从该数组包装器中取出稀疏矩阵.
是418326x223957的形状training与完整的数据集,(10, 121)形状为减少调试一套?
| 归档时间: |
|
| 查看次数: |
2890 次 |
| 最近记录: |