I can’t find anything that would help online and I’m begging for any tips with this. From what I can find online, this should be working, but it’s not. I got code similar to this working in R studio, before finding out that Python would be better for the project(digit recognition). I’m using Visual Studio Code for this project.
I’m super new to machine learning as a whole and this is the first real assignment I’ve been given, so any answers said like I’m 5 would help. (Professor doesn’t answer emails for a while and usually dances around the question.)
Here’s what I have imported(all are working and giving no errors):
from os import read
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
from sklearn.metrics import confusion_matrix
from sklearn.model_selection import validation_curve
from sklearn.model_selection import KFold
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import GridSearchCV
import matplotlib.pyplot as plt
import seaborn as sns
Here’s the code giving me hell:
tester = pd.read_table('C:\Users\42the\Downloads\PA_2\PA2_Data\PA2_Data\test.txt')
X = tester.drop('label', axis=1)
y = tester['label']
Here’s the error I’m getting:
Traceback (most recent call last):
File "c:/Users/42the/Desktop/Project2-SVM.py", line 19, in <module>
X = tester.drop('label', axis=1, inplace = True)
File "C:Users42theAppDataLocalProgramsPythonPython37libsite-packagespandasutil_decorators.py", line 311, in wrapper
return func(*args, **kwargs)
File "C:Users42theAppDataLocalProgramsPythonPython37libsite-packagespandascoreframe.py", line 4913, in drop
errors=errors,
File "C:Users42theAppDataLocalProgramsPythonPython37libsite-packagespandascoregeneric.py", line 4150, in drop
obj = obj._drop_axis(labels, axis, level=level, errors=errors)
File "C:Users42theAppDataLocalProgramsPythonPython37libsite-packagespandascoregeneric.py", line 4185, in _drop_axis
new_axis = axis.drop(labels, errors=errors)
File "C:Users42theAppDataLocalProgramsPythonPython37libsite-packagespandascoreindexesbase.py", line 6017, in drop
raise KeyError(f"{labels[mask]} not found in axis")
KeyError: "['label'] not found in axis"
Everything points to “‘label'” being wrong, but everything I can find about it says it should be working.
I thought it was because I was using the same txt file exported through Excel to be a csv file, but that wasn’t the issue(so I changed it back to the txt file). This is for a class and the professor told us to use this: https://www.kaggle.com/code/nishan192/mnist-digit-recognition-using-svm/notebook but that doesn’t give much context on these lines of code.
Also, here is the first two data points in that tester file for reference:
9 -1 -1 -1 -1 -1 -0.948 -0.561 0.148 0.384 0.904 0.29 -0.782 -1 -1 -1 -1 -1 -1 -1 -1 -0.748 0.588 1 1 0.991 0.915 1 0.931 -0.476 -1 -1 -1 -1 -1 -1 -0.787 0.794 1 0.727 -0.178 -0.693 -0.786 -0.624 0.834 0.756 -0.822 -1 -1 -1 -1 -0.922 0.81 1 0.01 -0.928 -1 -1 -1 -1 -0.39 1 0.271 -1 -1 -1 -1 0.012 1 0.248 -1 -1 -1 -1 -1 -0.402 0.326 1 0.801 -0.998 -1 -1 -0.981 0.645 1 -0.687 -1 -1 -1 -1 -0.792 0.976 1 1 0.413 -0.976 -1 -1 -0.993 0.834 0.897 -0.951 -1 -1 -1 -0.831 0.14 1 1 0.302 -0.889 -1 -1 -1 -1 0.356 0.794 -0.836 -1 -0.445 0.074 0.833 1 1 0.696 -0.881 -1 -1 -1 -1 -1 -0.368 0.955 1 1 1 1 0.905 1 1 -0.262 -1 -1 -1 -1 -1 -1 -1 -0.507 0.451 0.692 0.692 -0.007 -0.237 1 0.882 -0.795 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0.155 1 0.436 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -0.991 0.703 1 -0.025 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -0.833 0.959 1 -0.629 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -0.6 0.998 0.841 -0.932 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -0.424 1 0.732 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -0.908 0.43 0.622 -0.973 -1 -1 -1 -1 -1
6 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -0.783 -0.973 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -0.364 0.789 -0.371 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -0.467 0.963 0.609 -0.986 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -0.875 0.605 0.96 -0.351 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0.05 1 0.096 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -0.582 0.97 0.532 -0.922 -1 -1 -1 -1 -1 -1 -0.602 0.307 0.718 0.718 -0.373 -0.998 0.723 1 -0.431 -1 -1 -1 -1 -1 -0.817 -0.136 0.808 1 1 1 0.697 -0.67 0.965 0.659 -1 -1 -1 -1 -1 -0.512 0.738 1 0.839 -0.336 -0.977 0.433 0.878 0.161 1 -0.102 -1 -1 -1 -1 -0.643 0.87 0.97 0.264 -0.971 -1 -0.399 1 0.117 0.835 0.968 -0.701 -1 -1 -1 -1 0.198 1 0.052 -1 -1 -0.291 0.876 0.79 -0.819 0.392 0.962 -0.461 -1 -1 -1 -0.948 0.82 1 -0.168 -0.475 0.28 0.968 0.88 -0.613 -1 -0.551 0.854 0.98 0.498 0.324 0.324 0.328 0.998 1 0.97 0.995 0.976 0.25 -0.642 -1 -1 -1 -0.64 0.661 0.971 1 1 1 0.95 0.774 0.774 0.302 -0.522 -1 -1 -1 -1 -1 -1 -1 -0.663 -0.606 -0.606 -0.606 -0.688 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
(First one is 9 and hex code and the second one is 6 and hex code. These are on one line, but wrap around due to length.)
Wesley Thompson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.