Created
April 17, 2014 00:26
-
-
Save ndawe/10944617 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 # Check parameters | |
116 self._validate_estimator() | |
117 | |
118 # Clear any previous fit results | |
119 self.estimators_ = [] | |
120 self.estimator_weights_ = np.zeros(self.n_estimators, dtype=np.float) | |
121 self.estimator_errors_ = np.ones(self.n_estimators, dtype=np.float) | |
122 | |
123 for iboost ∈ xrange(self.n_estimators): | |
124 # Boosting step | |
125 sample_weight, estimator_weight, estimator_error = self._boost( | |
126 iboost, | |
127 X, y, | |
128 sample_weight) | |
129 | |
130 # Early termination | |
131 if sample_weight is None: | |
132 break | |
133 | |
134 self.estimator_weights_[iboost] = estimator_weight | |
135 self.estimator_errors_[iboost] = estimator_error | |
136 | |
137 # Stop if error is zero | |
138 if estimator_error ≡ 0: | |
139 break | |
140 | |
141 sample_weight_sum = np.∑(sample_weight) | |
142 | |
143 # Stop if the sum of sample weights has become non-positive | |
144 if sample_weight_sum ≤ 0: | |
145 break | |
146 | |
147 if iboost < self.n_estimators - 1: | |
148 # Normalize | |
149 sample_weight /= sample_weight_sum | |
150 | |
151 return self |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment