import numpy as np
import matplotlib.pyplot as plt
from sklearn import svm
%matplotlib inline

"""
Explanation: Let us first explore an example that falls under novelty detection.  Here, we train a model on data with some distribution and no outliers.  The test data, has some "novel" subset of data that does not follow that distribution.
End of explanation
"""


model = svm.OneClassSVM()

"""
Explanation: Use the np.random module to generate a normal distribution of 1,000 data points in two dimensions (e.g. x, y) - choose whatever mean and sigma^2 you like.  Generate another 1,000 data points with a normal distribution in two dimensions that are well separated from the first set.  You now have two "clusters".  Concatenate them so you have 2,000 data points in two dimensions.  Plot the points. This will be the training set.
Plot the points.
Generate 100 data points with the same distribution as your first random normal 2-d set, and 100 data points with the same distribution as your second random normal 2-d set.  This will be the test set labeled X_test_normal.
Generate 100 data points with a random uniform distribution.  This will be the test set labeled X_test_uniform.
Define a model classifier with the svm.OneClassSVM
End of explanation
"""


from sklearn.covariance import EllipticEnvelope

"""
Explanation: Fit the model to the training data.
Use the trained model to predict whether X_test_normal data point are in the same distributions.  Calculate the fraction of "false" predictions.
Use the trained model to predict whether X_test_uniform is in the same distribution. Calculate the fraction of "false" predictions.
Use the trained model to see how well it recovers the training data.  (Predict on the training data, and calculate the fraction of "false" predictions.)
Create another instance of the model classifier, but change the kwarg value for nu.  Hint: Use help to figure out what the kwargs are.
Redo the prediction on the training set, prediction on X_test_random, and prediction on X_test.
Plot in scatter points the X_train in blue, X_test_normal in red, and X_test_uniform in black.  Overplot the trained model decision function boundary for the first instance of the model classifier.
Do the same for the second instance of the model classifier.
End of explanation
"""


