In section 2.9 of classic examples of Python machine learning, you want to practice the quality of automobile feature evaluation yourself, so you need to preprocess the data. The code includes encoding the string mark into the corresponding number, as shown in the following code
input_data = ['vhigh', 'vhigh', '2', '2', 'small', 'low']
input_data_encoded = [-1] * len(input_data)
for i,item in enumerate(input_data):
input_data_encoded[i] = int(label_encoder[i].transform(input_data[i]))
Error reporting:
Traceback (most recent call last):
File "E:/17770426925/PythonLeaning/Machine-Learning/classifier/classifier.py", line 255, in <module>
input_data_encoded[i] = int(label_encoder[i].transform(input_data[i]))
File "D:\ProgramData\Anaconda3\lib\site-packages\sklearn\preprocessing\label.py", line 147, in transform
y = column_or_1d(y, warn=True)
File "D:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\validation.py", line 562, in column_or_1d
raise ValueError("bad input shape {0}".format(shape))
ValueError: bad input shape ()
Therefore, it can be seen that it is label_encoder[i].transform(input_Input in data [i])_Data [i] is not in the correct form and needs to be changed to list, so the code can be improved:
for i, item in enumerate(input_data):
labels=[]
labels.append(input_data[i])
input_data_encoded[i] = int(label_encoder[i].transform(labels))
Similar Posts:
- Keras.utils.to in keras_ Categorical method
- Tensorflow error due to uninitialized variable [How to Fix]
- Python Importerror: DLL load failed: unable to find the specified module
- Python OpenCV BUG: all the input arrays must have same number of dimensions
- [Solved] Tensorflow:ImportError: DLL load failed: The specified module cannot be found Failed to load the native TensorFlow runtime
- pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it’s not in you…
- [How to Solve Pytorch Error] EOFError: Ran out of input
- [Solved] UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xa5 in position 1508: illegal multibyte sequence
- Problems and solutions in running tensorflow
- [Solved] torch.cuda.CudaError: CUDA driver version is insufficient for CUDA runtime version (35) [ WARN:0