0
$\begingroup$

I am in third year of university, this simple py program is meant to use the Gaussian Naive Bayes algorithm to create a model and evaluate it.

StudentD = pd.read_csv ('StudentDataset.csv') 
StudentD.columns.get_loc('failures') #Find the index of the column using name
failure = StudentD.iloc[:,[15]]
failure = failure.replace(range(2,4),1)
StudentD.iloc[:,[15]] = failure 

#relationship at [:,[23] ] , yes or no becomes 0 /1

LabelEnc = preprocessing.LabelEncoder()
LabelEnc.fit(StudentD.iloc[:,[23]])
swap = LabelEnc.transform(StudentD.iloc[:,[23]])
StudentD.iloc[:,[23]] = swap


x = StudentD[['relationship', 'goout', 'Dalc', 'Walc']]

x2 = StudentD[['relationship', 'studytime','absences', 'goout', 'Dalc', 'Walc' ]]

y = StudentD[['failures']]

x_train, x_test, y_train, y_test = train_test_split(
        x, y, random_state=0)

x_train2, x_test2, y_train2, y_test2 = train_test_split(
        x2, y, random_state=0)


y_pred1 = gnb.fit(x_train, y_train).predict(x_test)
# includes extra featues
y_pred2 = gnb.fit(x_train2,y_train2).predict(x_test2)  

print(accuracy_score(y_test, y_pred1, normalize= True) * 100)
print(accuracy_score(y_test2, y_pred2, normalize = True ) * 100)

However, even with the second list of features in x2, my accuracy score drops by about 1% with these introduced features, is this due to how I developed the code or because the features aren't constructive in increasing accuracy. Its 81.22605363984674% and 80.84291187739464%.

$\endgroup$
  • $\begingroup$ It is helpful to provide a link to that csv, maybe via github, or make fake data so that your results are reproducible. $\endgroup$ – Alex Dec 3 '19 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.