def test_clone_2(): """Tests that clone doesn't copy everything. We first create an estimator, give it an own attribute, and make a copy of its original state. Then we check that the copy doesn't have the specific attribute we manually added to the initial estimator. """ from scikits.learn.feature_selection import SelectFpr, f_classif selector = SelectFpr(f_classif, alpha=0.1) selector.own_attribute = "test" new_selector = clone(selector) assert_false(hasattr(new_selector, "own_attribute"))
def test_clone(): """Tests that clone creates a correct deep copy. We create an estimator, make a copy of its original state (which, in this case, is the current state of the setimator), and check that the obtained copy is a correct deep copy. """ from scikits.learn.feature_selection import SelectFpr, f_classif selector = SelectFpr(f_classif, alpha=0.1) new_selector = clone(selector) assert_true(selector is not new_selector) assert_equal(selector._get_params(), new_selector._get_params())
y = iris.target ################################################################################ pl.figure(1) pl.clf() x_indices = np.arange(x.shape[-1]) ################################################################################ # Univariate feature selection from scikits.learn.feature_selection import SelectFpr, f_classif # As a scoring function, we use a F test for classification # We use the default selection function: the 10% most significant # features selector = SelectFpr(f_classif, alpha=0.1) selector.fit(x, y) scores = -np.log10(selector._pvalues) scores /= scores.max() pl.bar(x_indices-.45, scores, width=.3, label=r'Univariate score ($-Log(p_{value})$)', color='g') ################################################################################ # Compare to the weights of an SVM clf = svm.SVC(kernel='linear') clf.fit(x, y) svm_weights = (clf.coef_**2).sum(axis=0) svm_weights /= svm_weights.max() pl.bar(x_indices-.15, svm_weights, width=.3, label='SVM weight',
x_indices = np.arange(x.shape[-1]) ################################################################################ # Univariate feature selection from scikits.learn.feature_selection import SelectFpr, f_classif # As a scoring function, we use a F test for classification # We use the default selection function: the 10% most significant # features <<<<<<< HEAD selector = us.SelectFpr(us.f_classif, alpha=0.1) selector.fit(x, y) scores = -np.log(selector._scores) ======= selector = SelectFpr(f_classif, alpha=0.1) selector.fit(x, y) scores = -np.log10(selector._pvalues) >>>>>>> remote scores /= scores.max() pl.bar(x_indices-.45, scores, width=.3, label=r'Univariate score ($-Log(p_{value})$)', color='g') ################################################################################ # Compare to the weights of an SVM clf = svm.SVC(kernel='linear') clf.fit(x, y) svm_weights = (clf.coef_**2).sum(axis=0) svm_weights /= svm_weights.max()