Would a machine learning classifier algorithm be able to determine whether a number is odd or even? I was testing out some classifier algorithms in scikit but wasn't able to find a classifier (linear or non-linear) that managed to provide good prediction on whether an input number is odd or even. Here's the code:
import numpy as np
from sklearn.linear_model import SGDClassifier
from sklearn.linear_model import LogisticRegression, LogisticRegressionCV, RidgeClassifierCV
from sklearn.svm import SVC, NuSVC
length = 10000

evens = np.array([np.arange(0, length*2, 2)])
zeroes = np.array([np.resize([[0]], length)])

odds = np.array([np.arange(1, length*2, 2)])
ones = np.array([np.resize([[1]], length)])

evens_data = np.concatenate((evens.T, zeroes.T), axis=1)
odds_data = np.concatenate((odds.T, ones.T), axis=1)

data = np.array([np.append(evens_data, odds_data)]).reshape(length*2, 2)
np.random.shuffle(data)
X = np.array([data[:,0]]).reshape(length*2,1)
y = data[:,1]

## 
## Tried all algorithms below
##
# clf = LogisticRegression(random_state=42, max_iter=1000)
# clf = LogisticRegressionCV(cv=5, random_state=42, max_iter=1000)
# clf = RidgeClassifierCV(cv=5)
# clf = SGDClassifier(max_iter=1000)
# clf = SVC(random_state=42, max_iter=1000)
clf = NuSVC(random_state=42)
clf.fit(X, y)

for tuple_ in [(np.arange(0, 20, 2), 0), (np.arange(1, 22, 2), 1)]:
    X, y = tuple_
    for x in X:
        predicted = clf.predict([[x]])
        print(f'{"Good" if predicted[0] == y else "Bad"} predicting: {x} is {predicted[0]} and it should be {y}')

I anticipate some people saying that I could (should) have processed my data in a more machine learning ready way (like translating it to binary) but I didn't want to do that as my idea is to being able to find a classifier algorithm that could clusterize the data based on features not as clear as odd/even but on something the analyst couldn't foresee just by looking at the data.
I wonder if Linear or SVM-based classifier algorithms aren't able to do that. If not, I'd appreciate someone explaining why not.
Also, (if Linear / SVM-based classifiers are not indicated for this job) what would be the right tool for that?

This is a fun little problem.
@jbowman notes

"As is often the case, the issue is one of defining your features".

One way to engineer a feature for this problem is to look at the last digit of the number. Here is a simple little script in sklearn
import numpy as np
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import OneHotEncoder, FunctionTransformer

@np.vectorize
def get_last_digit_of_float(x):
    str_x = str(x)
    if len(str_x) == 1:
        return int(str_x)
    else:
        return int(str_x[-1])

last_digit_transformer = FunctionTransformer(get_last_digit_of_float)

def main():

    train_set = np.arange(100).reshape(-1, 1)
    y_train = np.arange(100) % 2
    test_set = np.arange(100, 200).reshape(-1, 1)
    y_test = np.arange(100, 200) % 2

    model = make_pipeline(
        last_digit_transformer,
        OneHotEncoder(categories='auto', sparse=False, handle_unknown='error', drop='first'),
        LogisticRegression(solver='lbfgs', multi_class='multinomial')
    )

    model.fit(train_set, y_train)

    print('Test Set Accuracy:', model.score(test_set, y_test))


if __name__ == '__main__':
    main()

This returns a test set accuracy of 1.0.  The trick here is to turn the last digit of the number into a feature and then one hot encode the number. This works because any number which ends in an even number is also even.  The result is a design matrix with 9 columns (numbers 1 through 9, 0 is not needed in this case since it is absorbed by the intercept in Logistic regression).  As always, a clever feature engineering approach is all that is needed.
