我正在关注神经网络1的教程
它在Python 2.7中.我正在使用3.4.这是困扰我的路线:
if test_data: n_test = len(test_data)
我明白了:TypeError: object of type 'zip' has no len().
有没有办法重写它,以便它在3.4中工作?
我发现很难理解如何修复我创建的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等方式尝试了很多解决方案,但我仍然不知道如何修复它.是的,之前出现过类似的问题,但不是在管道内.我必须在哪里申请toarray或todense?
我在Ubuntu 17.04上使用Keras 2.0(TensorFlow后端)进行二进制图像分类。一切都很好,除了我想看看哪些图像分类错误。我怎么做?
另外,不确定它是否可以解决我的问题,但是在TensorBoard中我无法使用该image选项卡,所以不知道这是否有帮助。
当然,我已经做了很多谷歌搜索,但我只是找不到答案。
我以为我理解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 ×2
keras ×1
lambda ×1
numpy ×1
pandas ×1
python-2.7 ×1
python-3.x ×1
scikit-learn ×1
tensorboard ×1
tensorflow ×1
ubuntu-17.04 ×1