小编Ada*_*tra的帖子

Python 2 - > 3:'zip'类型的对象没有len()

我正在关注神经网络1的教程

它在Python 2.7中.我正在使用3.4.这是困扰我的路线:

if test_data: n_test = len(test_data)

我明白了:TypeError: object of type 'zip' has no len().

有没有办法重写它,以便它在3.4中工作?

python-2.7 python-3.x

39
推荐指数
3
解决办法
3万
查看次数

Scikit-Learn的管道:传递了稀疏矩阵,但需要密集数据

我发现很难理解如何修复我创建的Pipeline(阅读:主要是从教程中粘贴).这是python 3.4.2:

df = pd.DataFrame
df = DataFrame.from_records(train)

test = [blah1, blah2, blah3]

pipeline = Pipeline([('vectorizer', CountVectorizer()), ('classifier', RandomForestClassifier())])

pipeline.fit(numpy.asarray(df[0]), numpy.asarray(df[1]))
predicted = pipeline.predict(test)
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我得到:

TypeError: A sparse matrix was passed, but dense data is required. Use X.toarray() to convert to a dense numpy array.
Run Code Online (Sandbox Code Playgroud)

这是为了线pipeline.fit(numpy.asarray(df[0]), numpy.asarray(df[1])).

我已经通过numpy,scipy等方式尝试了很多解决方案,但我仍然不知道如何修复它.是的,之前出现过类似的问题,但不是在管道内.我必须在哪里申请toarraytodense

python numpy pandas scikit-learn

27
推荐指数
4
解决办法
2万
查看次数

在Tensorflow上使用Keras进行图像分类:如何查找训练期间哪些图像分类不正确?

我在Ubuntu 17.04上使用Keras 2.0(TensorFlow后端)进行二进制图像分类。一切都很好,除了我想看看哪些图像分类错误。我怎么做?

另外,不确定它是否可以解决我的问题,但是在TensorBoard中我无法使用该image选项卡,所以不知道这是否有帮助。

当然,我已经做了很多谷歌搜索,但我只是找不到答案。

deep-learning keras tensorflow tensorboard ubuntu-17.04

5
推荐指数
1
解决办法
1498
查看次数

理解这个lambda函数是如何工作的

我以为我理解lambda函数是如何工作的,尽管我自己并没有使用它们.但是本教程下面的lambda 完全让我感到困惑:

import matplotlib.pyplot as plt
import numpy as np
import sklearn
import sklearn.datasets
import sklearn.linear_model
import matplotlib
Run Code Online (Sandbox Code Playgroud)

那很简单.更多:

# Generate a dataset and plot it
np.random.seed(0)
X, y = sklearn.datasets.make_moons(200, noise=0.20)
plt.scatter(X[:,0], X[:,1], s=40, c=y, cmap=plt.cm.Spectral)
clf = sklearn.linear_model.LogisticRegressionCV()
clf.fit(X, y)

# Helper function to plot a decision boundary.
# If you don't fully understand this function don't worry, it just generates the contour plot below.

def plot_decision_boundary(pred_func):

    # Set min and max values and give it …
Run Code Online (Sandbox Code Playgroud)

python lambda

1
推荐指数
1
解决办法
8309
查看次数