Changeset 11559:05d6847d3185 in orange
 Timestamp:
 05/29/13 16:19:55 (11 months ago)
 Branch:
 default
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

Orange/classification/neural.py
r10984 r11559 127 127 class NeuralNetworkLearner(Orange.classification.Learner): 128 128 """ 129 NeuralNetworkLearner uses jzbontar's implementation of neural networks and wraps it in 130 an Orange compatible learner. 131 132 NeuralNetworkLearner supports all types of data and returns a classifier, regression is currently not supported. 133 134 More information about neural networks can be found at http://en.wikipedia.org/wiki/Artificial_neural_network. 129 NeuralNetworkLearner implements a multilayer perceptron. Learning is performed by minimizing an L2regularized 130 cost function with scipy's implementation of LBFGS. The current implementations is limited to a single 131 hidden layer. 132 133 Regression is currently not supported. 135 134 136 135 :param name: learner name. … … 138 137 139 138 :param n_mid: Number of nodes in the hidden layer 140 :type n_mid: int eger139 :type n_mid: int 141 140 142 141 :param reg_fact: Regularization factor. … … 144 143 145 144 :param max_iter: Maximum number of iterations. 146 :type max_iter: integer 145 :type max_iter: int 146 147 :param normalize: Normalize the data prior to learning (subtract each column by the mean and divide by the standard deviation) 148 :type normalize: bool 147 149 148 150 :rtype: :class:`Orange.multitarget.neural.neuralNetworkLearner` or … … 159 161 return self(data,weight) 160 162 161 def __init__(self, name="NeuralNetwork", n_mid=10, reg_fact=1, max_iter= 1000, rand=None):163 def __init__(self, name="NeuralNetwork", n_mid=10, reg_fact=1, max_iter=300, normalize=True, rand=None): 162 164 """ 163 165 Current default values are the same as in the original implementation (neural_networks.py) 164 166 """ 165 166 167 self.name = name 167 168 self.n_mid = n_mid … … 169 170 self.max_iter = max_iter 170 171 self.rand = rand 172 self.normalize = normalize 171 173 172 174 if not self.rand: … … 193 195 X = data.to_numpy()[0] 194 196 197 mean = X.mean(axis=0) 198 std = X.std(axis=0) 199 if self.normalize: 200 X = (X  mean) / std 201 195 202 #converts multitarget or singletarget classes to numpy 196 197 198 203 if data.domain.class_vars: 199 204 for cv in data.domain.class_vars: … … 228 233 self.nn.fit(X,Y) 229 234 230 return NeuralNetworkClassifier(classifier=self.nn.predict, domain = data.domain) 235 return NeuralNetworkClassifier(classifier=self.nn.predict, 236 domain=data.domain, normalize=self.normalize, mean=mean, std=std) 231 237 232 238 class NeuralNetworkClassifier(): … … 258 264 input = np.array([[float(e) for e in example]]) 259 265 266 if self.normalize: 267 input = (input  self.mean) / self.std 268 260 269 # transform results from numpy 261 270 results = self.classifier(input).tolist()[0] 271 if len(results) == 1: 272 prob_positive = results[0] 273 results = [1  prob_positive, prob_positive] 262 274 mt_prob = [] 263 275 mt_value = [] … … 295 307 global_timer = time.time() 296 308 297 data = Orange.data.Table('iris') 298 l1 = NeuralNetworkLearner(n_mid=10, reg_fact=1, max_iter=1000) 299 res = Orange.evaluation.testing.cross_validation([l1],data, 3) 309 data = Orange.data.Table('wine') 310 l1 = NeuralNetworkLearner(n_mid=40, reg_fact=1, max_iter=200) 311 312 # c1 = l1(data) 313 # print c1(data[0], 3), data[0] 314 315 l2 = Orange.classification.bayes.NaiveLearner() 316 res = Orange.evaluation.testing.cross_validation([l1, l2],data, 5) 300 317 scores = Orange.evaluation.scoring.CA(res) 301 302 318 for i in range(len(scores)): 303 319 print res.classifierNames[i], scores[i]
Note: See TracChangeset
for help on using the changeset viewer.