python中shape 0_Python错误:找到包含0个样本(shape =(0,262))的数组,同时至少需要1个...

在构建自然语言处理模型时,遇到ValueError:数组含有0个样本(shape=(0, 262)),至少需要1个。问题出现在`reg.predict(test)`时。代码涉及数据预处理、特征选择、矩阵操作和Ridge回归模型训练。尝试对数据集进行切分和预测,但测试集形状导致错误。" 104592327,7515569,DC9靶机渗透复现:从信息收集到提权,"['网络安全', '渗透测试', 'Kali Linux', 'SQLmap', 'Linux权限']
摘要由CSDN通过智能技术生成

所以我试图在python中构建一个自然学习处理器,我正在使用我在网上找到的一些代码,然后调整自己的东西。但现在,它只是不想工作。它一直在给我

ValueError: Found array with 0 sample(s) (shape=(0, 262)) while a minimum of 1 is required.

这是我的代码。我道歉,如果它是凌乱的我只是直接从互联网上复制它:

from collections import Counter

import pandas

from nltk.corpus import stopwords

import pandas as pd

import numpy

headlines = []

apps = pd.read_csv('DataUse.csv')

for e in apps['title_lower']:

headlines.append(e)

testdata = pd.read_csv('testdata.csv')

# Find all the unique words in the headlines.

unique_words = list(set(" ".join(headlines).split(" ")))

def make_matrix(headlines, vocab):

matrix = []

for headline in headlines:

# Count each word in the headline, and make a dictionary.

counter = Counter(headline)

# Turn the dictionary into a matrix row using the vocab.

row = [counter.get(w, 0) for w in vocab]

matrix.append(row)

df = pandas.DataFrame(matrix)

df.columns = unique_words

return df

print(make_matrix(headlines, unique_words))

import re

# Lowercase, then replace any non-letter, space, or digit character in the headlines.

new_headlines = [re.sub(r'[^\w\s\d]','',h.lower()) for h in headlines]

#

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值