错误信息中提到"ModuleNotFoundError: No module named 'distutils.msvccompiler'",这表明你的Python环境中缺少distutils模块。一般来说,distutils是Python标准库的一部分,但有时在某些Python发行版中可能需要单独安装。
确保distutils已安装。你可以通过安装相关包来解决这个问题:
bash
sudo apt-get install python3-distutils
如果你使用的是Windows,你可能需要确保安装了适当的构建工具,如Visual C++ Build Tools。
× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [19 lines of output]
Running from numpy source directory.
/tmp/pip-install-05bewr6x/numpy_bba1045d46cd499682244805e5bdada8/numpy/distutils/misc_util.py:464: SyntaxWarning: "is" with a literal. Did you mean "=="?
return is_string(s) and ('*' in s or '?' is s)
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "/tmp/pip-install-05bewr6x/numpy_bba1045d46cd499682244805e5bdada8/setup.py", line 394, in <module>
setup_package()
File "/tmp/pip-install-05bewr6x/numpy_bba1045d46cd499682244805e5bdada8/setup.py", line 373, in setup_package
from numpy.distutils.core import setup
File "/tmp/pip-install-05bewr6x/numpy_bba1045d46cd499682244805e5bdada8/numpy/distutils/__init__.py", line 8, in <module>
from . import ccompiler
File "/tmp/pip-install-05bewr6x/numpy_bba1045d46cd499682244805e5bdada8/numpy/distutils/ccompiler.py", line 17, in <module>
from numpy.distutils import log
File "/tmp/pip-install-05bewr6x/numpy_bba1045d46cd499682244805e5bdada8/numpy/distutils/log.py", line 13, in <module>
from numpy.distutils.misc_util import (red_text, default_text, cyan_text,
File "/tmp/pip-install-05bewr6x/numpy_bba1045d46cd499682244805e5bdada8/numpy/distutils/misc_util.py", line 15, in <module>
from distutils.msvccompiler import get_build_architecture
ModuleNotFoundError: No module named 'distutils.msvccompiler'
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for numpy
Running setup.py clean for numpy
error: subprocess-exited-with-error
× python setup.py clean did not run successfully.
│ exit code: 1
╰─> [10 lines of output]
Running from numpy source directory.
`setup.py clean` is not supported, use one of the following instead:
- `git clean -xdf` (cleans all files)
- `git clean -Xdf` (cleans all versioned files, doesn't touch
files that aren't checked into the git repo)
Add `--force` to your command to use it anyway if you must (unsupported).
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed cleaning build dir for numpy
Failed to build numpy
ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (numpy)
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
print("Number of duplicate observations in the dataset:", num_duplicates_data)
print("Proportion of duplicate observations in the dataset:", prop_duplicates_data)
data = data.drop_duplicates()
data = data.reset_index(drop=True)
from sklearn.model_selection import train_test_split
ax[0].set_title('Histogram of Number of Words per product description')
ax[0].set_xlabel('Number of words')
ax[1].set_title('Boxplots of Words per product description')
ax[1].set_xlabel('Product overall category')
ax[1].set_ylabel('Number of words')
def avg_leng_word(x):
return np.sum([len(w) for w in x.split()]) / len(x.split())
data['avg_prod_desc_length'] = data['description'].apply(avg_leng_word)
sns.histplot(data.iloc[tr_idx]['avg_prod_desc_length'], kde=True, stat='density', linewidth=0)
plt.title('Histogram of Average Length of Word in product description')
plt.xlabel('Average length of word')
ax[0].set_title('Histogram of Average Length of Word in product description')
ax[0].set_xlabel('Average length of word')
ax[1].set_title('Boxplots of Average Length of Word in product description')
ax[1].set_xlabel('Product overall category')
ax[1].set_ylabel('Average length of word')
from collections import defaultdict, Counter
import nltk
from nltk.corpus import stopwords
def create_corpus(column_name):
corpus = []
for w in data['{0}'.format(column_name)].str.split():
for i in w:
corpus.append(i.lower())
return corpus
Create a corpus of stopwords in product description
def create_corpus_dict(column_name):
corpuse = create_corpus(column_name)
stop_dict = defaultdict(int)
for word in corpuse:
if word in stopwords:
stop_dict[word] += 1
return sorted(stop_dict.items(), key=lambda x: x[1],
reverse=True)
prod_desc_x = []
prod_desc_y = []
counter = 0
for word, count in counter_prod_desc.most_common()[:100]:
if (counter < 30) and (word not in stopwords):
counter += 1
prod_desc_x.append(word)
prod_desc_y.append(count)
ax[0].title.set_text('30 most common stopwords in product description')
ax[1].title.set_text('30 most common unigram NON-stopwords in product description')
nltk.download('words')
words = set(nltk.corpus.words.words()) # english words
string.punctuation
remove non-english words.
def remove_non_english(row):
result = []
for text in row:
new_text = " ".join(w for w in text.split() if w in words)
result.append(new_text)
return result
remove non-printable characters.
def remove_not_ASCII(row):
result = []
for text in row.split('||'):
new_text = ''
for word in text.split():
word = ''.join([char for char in word if char in string.printable])
new_text += word + ' '
result.append(new_text[:-1])
return result
get rid of the punctuation.
def remove_all_punct(row):
result = []
for text in row:
table = str.maketrans('', '', string.punctuation)
new_text = text.translate(table)
result.append(new_text)
return result
lower text.
def lower_text(row):
result = []
for text in row:
new_text = text.lower()
result.append(new_text)
return result
remove numbers.
def remove_numbers(row):
result = []
for text in row:
num = re.compile(r'[-+]?[.\d][\d]+[:,.\d]')
new_text = num.sub(r"NUMBER", text)
result.append(new_text)
return result
remove emojis.
def remove_emojis(row):
result = ''
for text in row.split('||'):
emoji = re.compile("["u"\U0001F600-\U0001F64F""]+") # emojis
new_text = emoji.sub('rEMOJI', text)
result += new_text + '||'
return result
remove english stopwords.
def remove_stopwords(row): # should we remove 'not'?
result = []
for text in row:
non_stop = ' '.join(word for word in text.split() if word not in stops)
result.append(non_stop)
return result
f1score = f1_score(y_test, y_pred, average='weighted')
train_acc = round(model.score(x_train, y_train)*100)
test_acc = round(accuracy_score(y_test,y_pred)*100)
print(str(model.__class__.__name__) +" using "+ str(vectoriser))
print('Accuracy of classifier on training set:{}%'.format(train_acc))
print('Accuracy of classifier on test set:{}%' .format(test_acc))
ax[0].set_title('Histogram of Number of Words per product description')
ax[0].set_xlabel('Number of words')
ax[1].set_title('Boxplots of Words per product description')
ax[1].set_xlabel('Product overall category')
ax[1].set_ylabel('Number of words')
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVC
from sklearn.metrics import confusion_matrix
from sklearn.metrics import precision_score, recall_score, f1_score, accuracy_score
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
X, y = np.arange(10).reshape((5, 2)), range(5)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)
fig, ax = plt.subplots(figsize=(5, 5))
ax.matshow(conf_matrix, cmap=plt.cm.Oranges, alpha=0.3)
for i in range(conf_matrix.shape[0]):
for j in range(conf_matrix.shape[1]):
ax.text(x=j, y=i,s=conf_matrix[i, j], va='center', ha='center', size='xx-large')
docker run -it registry.cn-chengdu.aliyuncs.com/mdl_base_dev/ubuntu20.04_cuda11.3.1_cudnn8_python3.8:cuda12.1_cudnn9_torch2.2_tf2.12_mmcv2.1_mmdet3.3_transformers4.39