Ejemplo n.º 1
0
 def test_validate_weights(self):
     X = np.random.random(size=(50,10))
     w = np.random.random(size=(10,))
     y = np.dot(X, w)
     enet = ElasticNet(alpha=.5)
     # Invalid use
     #    Passing in a sample weight vector that is too short.
     with self.assertRaises(ValueError):
         sw = np.ones(shape=(49,))
         enet._validate_weights(X, y, weights=sw)
     # Invalid use:
     #    Passing in a weight vector that matches the wrong dimenstion of X.
     with self.assertRaises(ValueError):
         sw = np.ones(shape=(10,))
         enet._validate_weights(X, y, weights=sw)
     # Invalid use:
     #    Passing in a weight vector containing a negative entry. 
     with self.assertRaises(ValueError):
         sw = np.ones(shape=(50,))
         sw[25] = -1
         enet._validate_weights(X, y, weights=sw)
     # Valid Use:
     #    Weight vector of the correct dimension with all non-negative 
     #    entries.
     sw = np.ones(shape=(50,))
     enet._validate_weights(X, y, weights=sw)
Ejemplo n.º 2
0
 def test_validate_weights(self):
     X = np.random.random(size=(50, 10))
     w = np.random.random(size=(10, ))
     y = np.dot(X, w)
     enet = ElasticNet(alpha=.5)
     # Invalid use
     #    Passing in a sample weight vector that is too short.
     with self.assertRaises(ValueError):
         sw = np.ones(shape=(49, ))
         enet._validate_weights(X, y, weights=sw)
     # Invalid use:
     #    Passing in a weight vector that matches the wrong dimenstion of X.
     with self.assertRaises(ValueError):
         sw = np.ones(shape=(10, ))
         enet._validate_weights(X, y, weights=sw)
     # Invalid use:
     #    Passing in a weight vector containing a negative entry.
     with self.assertRaises(ValueError):
         sw = np.ones(shape=(50, ))
         sw[25] = -1
         enet._validate_weights(X, y, weights=sw)
     # Valid Use:
     #    Weight vector of the correct dimension with all non-negative
     #    entries.
     sw = np.ones(shape=(50, ))
     enet._validate_weights(X, y, weights=sw)