A memorandum of scraping & machine learning [development technique] by Python (Chapter 4)

Chapter 4

lang-train.py When I ran lang-train.py on page 166, I got the following display.

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.

Solution

It wasn't a big deal. Since the text stated that lang.zip should be decompressed under lang, it was literally decompressed under "lang". But in the sample code

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

There is. Since lang-train.py was running on ch4, it means that we couldn't load the data we wanted.

Sample coat

"./lang/train/*.txt"

not

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

I thought about it, but I didn't want to mess with the sample code so much, so The problem was solved by setting the decompression destination directly under "ch4" instead of under "lang".

lang-Webapp.py It is unsolved.

I ran the following command when docker started.

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

After booting, cd to ch4 and then execute the following command. The result is as follows

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

Even if you open a web browser in this state and specify "http: //localhost:8080/cgi-bin/lang-Webapp.py", the page will not be displayed. image

What should I do? ..

Recommended Posts

A memorandum of scraping & machine learning [development technique] by Python (Chapter 4)
A memorandum of scraping & machine learning [development technique] by Python (Chapter 5)
A memorandum of extraction by python bs4 request
Get a glimpse of machine learning in Python
Python learning memo for machine learning by Chainer Chapter 13 Basics of neural networks
Python learning memo for machine learning by Chainer until the end of Chapter 2
Build a machine learning application development environment with Python
A beginner's summary of Python machine learning is super concise.
[Python] A memorandum of beautiful soup4
Machine learning summary by Python beginners
"Scraping & machine learning with Python" Learning memo
Python learning memo for machine learning by Chainer Chapter 8 Introduction to Numpy
Python learning memo for machine learning by Chainer Chapter 10 Introduction to Cupy
Python learning memo for machine learning by Chainer Chapter 9 Introduction to scikit-learn
[Learning memo] Basics of class by python
Python & Machine Learning Study Memo ④: Machine Learning by Backpropagation
Creating a development environment for machine learning
Judgment of igneous rock by machine learning ②
A memorandum of python string deletion process
Python learning memo for machine learning by Chainer Chapter 13 Neural network training ~ Chainer completed
A beginner of machine learning tried to predict Arima Kinen with python
Machine learning memo of a fledgling engineer Part 1
Classification of guitar images by machine learning Part 1
Machine learning starting with Python Personal memorandum Part2
Python & Machine Learning Study Memo ⑤: Classification of irises
Machine learning starting with Python Personal memorandum Part1
A memorandum of calling Python from Common Lisp
Python & Machine Learning Study Memo ②: Introduction of Library
About the development contents of machine learning (Example)
Get a list of Qiita likes by scraping
Analysis of shared space usage by machine learning
[Translation] scikit-learn 0.18 Tutorial Introduction of machine learning by scikit-learn
Machine learning memo of a fledgling engineer Part 2
Reasonable price estimation of Mercari by machine learning
Classification of guitar images by machine learning Part 2
A story about data analysis by machine learning
Build a Python machine learning environment with a container
Chapter 6 Supervised Learning: Classification pg212 ~ [Learn by moving with Python! New machine learning textbook]
Implementation of a model that predicts the exchange rate (dollar-yen rate) by machine learning
Basic data frame operations written by beginners in a week of learning Python
A memorandum of method often used in machine learning using scikit-learn (for beginners)
Predicting the goal time of a full marathon with machine learning-③: Visualizing data with Python-
[Recommended tagging for machine learning # 2.5] Modification of scraping script
Run a machine learning pipeline with Cloud Dataflow (Python)
Build a machine learning Python environment on Mac OS
Python learning memo for machine learning by Chainer Chapters 1 and 2
Installation of TensorFlow, a machine learning library from Google
[Machine learning] "Abnormality detection and change detection" Let's draw the figure of Chapter 1 in Python.
Basics of Python learning ~ What is a string literal? ~
Summary of the basic flow of machine learning with Python
Group by consecutive elements of a list in Python
Memo for building a machine learning environment using Python
[Python] Chapter 01-02 About Python (Execution and installation of development environment)
MALSS, a tool that supports machine learning in Python
A concrete method of predicting horse racing by machine learning and simulating the recovery rate
An example of a mechanism that returns a prediction by HTTP from the result of machine learning
Build a python machine learning study environment on macOS sierra
Python Machine Learning Programming Chapter 2 Classification Problems-Machine Learning Algorithm Training Summary
A memorandum of stumbling on my personal HEROKU & Python (Flask)
Collect machine learning data by scraping from bio-based public databases
[Python] How to make a list of character strings character by character