Python Forum

Full Version: Neural Network mensagem error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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 <
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)
Thanks. It worked well.