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?

A sine curve should do the trick. Pick a sine curve with a vertical distance of $1$ and a period of 2 so the curve hits $0$ at the even numbers and $1$ at the odd numbers. Then the output is the probability of being off vs even, and the predicted probabilities exactly match the labels.
If you want to make an optimizer do some work, you could consider a model like $y=a+b\sin(cx+d)$, where you let the optimizer figure out the amplitude, frequency, phase shift, and vertical shift.
