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 answer won't solve your problem directly, but I think it's important to give a more philosophical interpretation, otherwise the question might results a bit confusing for a beginner.
I am a statistician, not a machine learning or computer science expert, so expect inaccuracies and superficiality in the content (please, feel free to enrich it with more technical details, I would be thankful).
Here comes the point:
As previous answers and comments pointed out, the answer to this question is completely deterministic. You don't need a machine learning algorithm to solve it, because if you know the definition of odd and even number, that itself would be the trivial solution to the question. This solution can be interpreted and solved straightforwardly by any basic machine. To be more practical, for most modern programming languages this problem can be answer by a single IF statement: IF (the number can be divided by 2 with reminder equal to zero) THEN (even) ELSE (odd). Naturally, in the all answers provided above they assumed to know this definition and they built the model around it. Inevitably the accuracy will be always 1. And I can tell you more: if I know the definition there are infinite perfect solutions to your problem, think about it!
Imagining that we don't know the definition of even/odd number. How do I solve this problem? Well, I don't really know what is the problem you are trying to solve because a real problem would come with a set of features, that is some real (and imperfect) pieces of information that we have available to classify odd and even numbers.
To sum it up, do we know the definition of odd or even number?

*

*YES. Then, there is no need for classification algorithms because we know the answer already and it is straightforwardly translatable in machine language.

*NO. Then, we need some real data (features) and a trial-and-error strategy to understand what's the best model in terms of accuracy.

I hope this helps providing a different view point.
