<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 XOR
Step1:  Multivariante Regression - Housing Data Set
https
Step2:  Binary Classification - Pima Indians Diabetes Data Set
https
Step3:  Image Classification - MNIST dataset
http
Step4:  Image Classification - CIFAR-10 dataset
https
<ASSISTANT_TASK:>
Python Code:
def xor(X):
    if not ft.reduce(lambda old, new: old == new,X >= 0):
        return 1
    else:
        return 0 
    
x_train = np.array([(np.random.random_sample(5000) - 0.5) * 2 for dim in range(2)]).transpose()
x_test  = np.array([(np.random.random_sample(100)  - 0.5) * 2 for dim in range(2)]).transpose()
y_train = np.apply_along_axis(xor, 1, x_train)
y_test  = np.apply_along_axis(xor, 1, x_test)
with open('data/xor.tuple', 'wb') as xtuple:
    pickle.dump((x_train, y_train, x_test, y_test), xtuple)
Explanation: XOR
End of explanation
!wget -P data/ https://archive.ics.uci.edu/ml/machine-learning-databases/housing/housing.data
housing = pd.read_csv('data/housing.data', delim_whitespace=True, 
                   names=['CRIM', 
                          'ZM', 
                          'INDUS', 
                          'CHAS', 
                          'NOX', 
                          'RM', 
                          'AGE', 
                          'DIS', 
                          'RAD',
                          'TAX',
                          'PTRATIO',
                          'B',
                          'LSTAT',
                          'MEDV'])
housing.head()
with open('data/housing.dframe', 'wb') as dhousing:
    pickle.dump(housing, dhousing)
Explanation: Multivariante Regression - Housing Data Set
https://archive.ics.uci.edu/ml/datasets/Housing
1. CRIM: per capita crime rate by town 
2. ZN: proportion of residential land zoned for lots over 25,000 sq.ft. 
3. INDUS: proportion of non-retail business acres per town 
4. CHAS: Charles River dummy variable (= 1 if tract bounds river; 0 otherwise) 
5. NOX: nitric oxides concentration (parts per 10 million) 
6. RM: average number of rooms per dwelling 
7. AGE: proportion of owner-occupied units built prior to 1940 
8. DIS: weighted distances to five Boston employment centres 
9. RAD: index of accessibility to radial highways 
10. TAX: full-value property-tax rate per \$10,000 
11. PTRATIO: pupil-teacher ratio by town 
12. B: 1000(Bk - 0.63)^2 where Bk is the proportion of blacks by town 
13. LSTAT: \% lower status of the population 
14. MEDV: Median value of owner-occupied homes in $1000's
End of explanation
!wget -P data/ https://archive.ics.uci.edu/ml/machine-learning-databases/pima-indians-diabetes/pima-indians-diabetes.data
data = pd.read_csv('data/pima-indians-diabetes.data',
                   names=['n_pregnant', 
                          'glucose', 
                          'mmHg', 
                          'triceps', 
                          'insulin', 
                          'BMI', 
                          'pedigree', 
                          'age', 
                          'class'])
data.head()
x = np.array(data)[:,:-1]
y = np.array(data)[:,-1]
n_train = int(len(x) * 0.70)
x_train = x[:n_train]
x_test  = x[n_train:]
y_train = y[:n_train]
y_test  = y[n_train:]
with open('data/pima-indians-diabetes.tuple', 'wb') as xtuple:
    pickle.dump((x_train, y_train, x_test, y_test), xtuple)
Explanation: Binary Classification - Pima Indians Diabetes Data Set
https://archive.ics.uci.edu/ml/datasets/Pima+Indians+Diabetes
1. Number of times pregnant 
2. Plasma glucose concentration a 2 hours in an oral glucose tolerance test 
3. Diastolic blood pressure (mm Hg) 
4. Triceps skin fold thickness (mm) 
5. 2-Hour serum insulin (mu U/ml) 
6. Body mass index (weight in kg/(height in m)^2) 
7. Diabetes pedigree function 
8. Age (years) 
9. Class variable (0 or 1)
End of explanation
!wget -P data/ http://deeplearning.net/data/mnist/mnist.pkl.gz
import cPickle, gzip, numpy
# Load the dataset
f = gzip.open('data/mnist.pkl.gz', 'rb')
train_set, valid_set, test_set = cPickle.load(f)
f.close()
plt.imshow(train_set[0][0].reshape((28,28)),cmap='gray', interpolation=None)
!wget -P data/ http://data.dmlc.ml/mxnet/data/mnist.zip
!unzip -d data/ -u data/mnist.zip
Explanation: Image Classification - MNIST dataset
http://deeplearning.net/data/mnist/mnist.pkl.gz
End of explanation
!wget -P data/ https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz
!tar -xzf data/cifar-10-python.tar.gz -C data/
with open('data/cifar-10-batches-py/data_batch_1', 'rb') as batch:
    cifar1 = cPickle.load(batch)
cifar1.keys()
img = np.stack([cifar1['data'][0].reshape((3,32,32))[0,:,:],
                cifar1['data'][0].reshape((3,32,32))[1,:,:],
                cifar1['data'][0].reshape((3,32,32))[2,:,:]],axis=2)
plt.imshow(img, cmap='gray')
Explanation: Image Classification - CIFAR-10 dataset
https://www.cs.toronto.edu/~kriz/cifar.html
End of explanation
<END_TASK>