Python Forum
Neural Network mensagem error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Neural Network mensagem error
#1
Dear Sir, I'm trying do to a program that predict the emission of polluting gases from a Thermal Coal Plant. I would like help to solve the following mensagem error:
Thanks in advance

!pip install xgboost
import xgboost as xgb
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import GridSearchCV
import pandas as pd
from sklearn.metrics import mean_squared_error, r2_score, explained_variance_score, mean_absolute_error, median_absolute_error, mean_squared_log_erro
df = pd.read_csv('Dados_AP_CO_07_04_2020_5.csv',encoding='cp1252')
df.tail()
X = df.drop(['[CO]mg/m³N'], axis = 1)
y = df['[CO]mg/m³N']
data_dmatrix = xgb.DMatrix(data=X, label=y)
df.columns = [regex.sub("_", col) if any(x in str(col) for x in set(('[', ']', '<'))) else col for col in df.columns.values]
Error:
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-4-8fdb17ecdc00> in <module> ----> 1 data_dmatrix = xgb.DMatrix(data=X, label=y) 2 df.columns = [regex.sub("_", col) if any(x in str(col) for x in set(('[', ']', '<'))) else col for col in df.columns.values] ~\Anaconda3\lib\site-packages\xgboost\core.py in __init__(self, data, label, weight, base_margin, missing, silent, feature_names, feature_types, nthread) 493 self.set_base_margin(base_margin) 494 --> 495 self.feature_names = feature_names 496 self.feature_types = feature_types 497 ~\Anaconda3\lib\site-packages\xgboost\core.py in feature_names(self, feature_names) 956 not any(x in f for x in set(('[', ']', '<'))) 957 for f in feature_names): --> 958 raise ValueError('feature_names must be string, and may not contain [, ] or <') 959 else: 960 # reset feature_types also ValueError: feature_names must be string, and may not contain [, ] or <
Reply
#2
It seems that DMatrix constructor tries to extract feature_names from the data frame you provided, but
column names contain specific symbols that are disallowed.
Try to pass raw data instead, e.g. xgb.DMatrix(data=X.values, label=y.values)
Reply
#3
Thanks. It worked well.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Neural network and data analysis from clients survey result pthon3 2 1,864 Mar-17-2022, 02:21 AM
Last Post: jefsummers
  Multilayer Perceptron Neural Network erdemath 3 2,282 Aug-09-2021, 11:07 PM
Last Post: jefsummers
  Neural Network importance weights / coefficients jkaustin 1 2,030 Nov-10-2020, 07:44 PM
Last Post: jefsummers
  Get error message in a GAN neural network tutorial jdude50 0 1,649 Oct-22-2020, 11:11 PM
Last Post: jdude50
  Explain Me Neural Network Ai's Harshil 2 1,974 Oct-22-2020, 04:50 AM
Last Post: Harshil
  construction of Neural Network for solving Differential equations arshad 0 1,608 Jun-04-2020, 09:20 AM
Last Post: arshad
  coding neural network programmer19890620 4 3,391 Feb-27-2020, 04:26 AM
Last Post: programmer19890620
  Why does this simple neural network not learn? PythonIsGreat 1 2,083 Aug-30-2019, 05:49 PM
Last Post: ThomasL
  First neural network: Problem with the weight factos 11112294 0 2,142 Jan-12-2019, 09:11 PM
Last Post: 11112294
  Neural network nesrine 0 2,614 Dec-11-2018, 03:48 PM
Last Post: nesrine

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020