1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Pythonによるスクレイピング&機械学習[開発テクニック]の備忘録(4章)

Posted at

4章

lang-train.py

166ページのlang-train.pyを実行したら以下のような表示が返ってきました。

root@057e36518a17:/c/Users/yuki/my_dir/wap_scraping/src/ch4# python3 lang-train.py
/opt/conda/lib/python3.5/site-packages/sklearn/utils/validation.py:395: DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.
  DeprecationWarning)
Traceback (most recent call last):
  File "lang-train.py", line 45, in <module>
    clf.fit(data["freqs"], data["labels"])
  File "/opt/conda/lib/python3.5/site-packages/sklearn/svm/base.py", line 151, in fit
    X, y = check_X_y(X, y, dtype=np.float64, order='C', accept_sparse='csr')
  File "/opt/conda/lib/python3.5/site-packages/sklearn/utils/validation.py", line 521, in check_X_y
    ensure_min_features, warn_on_dtype, estimator)
  File "/opt/conda/lib/python3.5/site-packages/sklearn/utils/validation.py", line 424, in check_array
    context))
ValueError: Found array with 0 feature(s) (shape=(1, 0)) while a minimum of 1 is required.

解決

大した問題ではありませんでした。
テキストではlang配下にlang.zipを解凍すると記載されていたため、文字通り「lang」配下に解凍しました。
しかし、サンプルコードの中には

data = load_files("./lang/train/*.txt")
test = load_files("./lang/test/*.txt")

とあります。lang-train.pyはch4で実行されていたので、ほしいデータをロードできていなかったことになります。

サンプルコートを

"./lang/train/*.txt"

ではなく

"./lang/lang/train/*.txt"

とすることを考えましたが、サンプルコードはあまりいじりたくなかったので、
解凍先を「lang」配下ではなく、「ch4」直下にして解決しました。

lang-Webapp.py

未解決です。

docker起動時に以下のコマンドを実行しました。

$ docker run -it -v $HOME:$HOME -p 8080:8080  <CONTAINER ID> /bin/bash

起動後にcdでch4まで移動してから、以下のコマンドを実行しました。結果は以下の通り

$ python3 -m http.server --cgi 8080
Serving HTTP on 0.0.0.0 port 8080 ...

この状態でウェブブラウザを開いて「http://localhost:8080/cgi-bin/lang-Webapp.py」を指定してもページは表示されません。
image

どうしたものか。。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?