我是python新手,在我的文本分类问题中发现了此错误。我知道这与重塑X和Y有关,但是由于我在python方面的专业知识不足,所以我无法执行此操作,因为我目前正在学习python。我想获取完整的分类报告,但这只是给我带来准确性。有人可以帮助获得完整的分类报告,包括精度,召回率,f1得分和支持。谢谢您。
public function show($id)
{
$categoryName = Category::where('id', $id)->value('name');
$products = Product::where('categorie', categoryName)->paginate();
return view('categories.show')->with('products',$products);
}
这是我遇到的错误。
Dataset = pd.read_csv('projectdatacornew.csv')
daf= {'post':Dataset['description'],'tags':Dataset['types']}
df = pd.DataFrame(daf)
my_tags = ['Requirement','Non-Requirement']
df = df[pd.notnull(df['tags'])]
print(df.head(10))
print(df['post'].apply(lambda x: len(x.split(' '))).sum())
df = shuffle(df)
df = shuffle(df)
df = shuffle(df)
max_words = 1000
batch_size = 10
epochs = 2
train_posts, test_posts, train_tags, test_tags =
train_test_split(df['post'], df['tags'], test_size=0.3, random_state=39)
tokenize = text.Tokenizer(num_words=max_words, char_level=False)
tokenize.fit_on_texts(train_posts) # only fit on train
x_train = tokenize.texts_to_matrix(train_posts)
x_test = tokenize.texts_to_matrix(test_posts)
encoder = LabelEncoder()
encoder.fit(train_tags)
y_train = encoder.transform(train_tags)
y_test = encoder.transform(test_tags)
num_classes = np.max(y_train) + 1
y_train = utils.to_categorical(y_train, num_classes)
y_test = utils.to_categorical(y_test, num_classes)
x_train.shape
print(x_train.shape)
x_train.shape
print(y_train.shape)
x_train.shape
print(x_test.shape)
x_train.shape
print(y_test.shape)
# Build the model
model = Sequential()
model.add(Dense(512, input_shape=(max_words,)))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(num_classes))
model.add(Activation('sigmoid'))
model.compile(loss='categorical_crossentropy',
optimizer='adam',
metrics=['accuracy'])
history = model.fit(x_train, y_train,
batch_size=batch_size,
epochs=epochs,
verbose=1,
validation_split=0.1)
score = model.evaluate(x_test, y_test,
batch_size=batch_size, verbose=1)
print('Test accuracy:', score[1])
accr = model.evaluate(x_test,y_test)
print('Test set\n Loss: {:0.3f}\n Accuracy:
{:0.3f}'.format(accr[0],accr[1]))
print(classification_report(y_test, score))
print(confusion_matrix(y_test, score))