AttributeError: 'NoneType' object has no attribute 'replace'

I am new to XGBoost. Please help

from xgboost import XGBClassifier

from numpy import loadtxt
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from matplotlib import pyplot as plt
dataset = loadtxt(‘file.csv’, delimiter = “,”)

X= dataset[:,0:8]
Y = dataset[:8]
seed = 7
test_size = 0.33
X_train, X_test, y_train, y_test = train_test_split(X,Y,test_size = test_size, random_state = seed)
model = XGBClassifier()
model.fit(X_train,y_train)
print(model)
prediction = model.predict(X_test)
accuracy = accuracy_score(y_test, predictions)
print(‘Accuracy = %.2f%%’ % (accuracy * 100))

I think this line should be Y = dataset[:,8]. (Notice the comma.)

1 Like

Thanks for pointing out my mistake… but now i am getting a new error
Type error: unhashable type: ‘slice’
I tried using iloc but no gain
I am using DEAP dataset for EEG.

Are you using Pandas dataframe? See

import pickle

from xgboost import XGBClassifier

from graphviz import Digraph

from xgboost import plot_tree

import numpy as np

from numpy import loadtxt

import pandas as pd

from sklearn.metrics import mean_squared_error

from sklearn.model_selection import train_test_split

from sklearn.impute import SimpleImputer

from sklearn.metrics import accuracy_score

from matplotlib import pyplot as plt

a = pickle.load(open(’/content/s05.dat’, ‘rb’) ,encoding = ‘iso-8859-1’)

b = pd.DataFrame(np.concatenate(a[‘data’]))

c = b[0:40]

c = c.astype(‘int’)

print©

X = c.iloc[:,0:8].values

Y = c.iloc[:,8].values

seed = 42

test_size = 0.33

X_train, X_test, y_train, y_test = train_test_split(X,Y,test_size = test_size, random_state = seed)

model = XGBClassifier()

model.fit(X_train,y_train)

print(model)

plot_tree(model)

plt.plot©

plt.show

predictions = model.predict(X_test)

acc = accuracy_score(y_test, predictions)

print(‘Accuracy = %.2f%%’ % (acc * 100))

mse = mean_squared_error(y_test, predictions)

print('MSE = ', mse)

I am getting accuracy of 0%
and MSE = 16472.92

I am using a DEAP dataset having preprocessed data in python (numpy) .dat format
There are 32 DAT files , i have chosen #5 DAT file
Link to the dataset: https://www.eecs.qmul.ac.uk/mmv/datasets/deap/readme.html