Exemple #1
0
 def fit(self, X, y=None):
     self._sklearn_model = SKLModel(**self._hyperparams)
     if (y is not None):
         self._sklearn_model.fit(X, y)
     else:
         self._sklearn_model.fit(X)
     return self
Exemple #2
0
class LabelPropagationImpl():
    def __init__(self,
                 kernel='rbf',
                 gamma=20,
                 n_neighbors=7,
                 alpha=None,
                 max_iter=1000,
                 tol=0.001,
                 n_jobs=None):
        self._hyperparams = {
            'kernel': kernel,
            'gamma': gamma,
            'n_neighbors': n_neighbors,
            'alpha': alpha,
            'max_iter': max_iter,
            'tol': tol,
            'n_jobs': n_jobs
        }
        self._wrapped_model = Op(**self._hyperparams)

    def fit(self, X, y=None):
        if (y is not None):
            self._wrapped_model.fit(X, y)
        else:
            self._wrapped_model.fit(X)
        return self

    def predict(self, X):
        return self._wrapped_model.predict(X)

    def predict_proba(self, X):
        return self._wrapped_model.predict_proba(X)
Exemple #3
0
 def __init__(self,
              kernel='rbf',
              gamma=20,
              n_neighbors=7,
              alpha=None,
              max_iter=1000,
              tol=0.001,
              n_jobs=None):
     self._hyperparams = {
         'kernel': kernel,
         'gamma': gamma,
         'n_neighbors': n_neighbors,
         'alpha': alpha,
         'max_iter': max_iter,
         'tol': tol,
         'n_jobs': n_jobs
     }
     self._wrapped_model = Op(**self._hyperparams)
warnings.filterwarnings('ignore')

classifiers = [
    AdaBoostClassifier(),
    BaggingClassifier(),
    BernoulliNB(),
    CalibratedClassifierCV(),
    DecisionTreeClassifier(),
    ExtraTreeClassifier(),
    ExtraTreesClassifier(),
    GaussianNB(),
    GaussianProcessClassifier(),
    GradientBoostingClassifier(),
    KNeighborsClassifier(),
    LabelPropagation(),
    LabelSpreading(),
    LinearDiscriminantAnalysis(),
    LogisticRegression(),
    LogisticRegressionCV(),
    MLPClassifier(),
    NuSVC(probability=True),
    QuadraticDiscriminantAnalysis(),
    RandomForestClassifier(),
    SGDClassifier(loss='log'),
    SVC(probability=True),
    XGBClassifier()
]

names = [
    'AdaBoostClassifier', 'BaggingClassifier', 'BernoulliNB',
Exemple #5
0
			'GraphLasso':GraphLasso(),
			'GraphLassoCV':GraphLassoCV(),
			'HuberRegressor':HuberRegressor(),
			'Imputer':Imputer(),
			'IncrementalPCA':IncrementalPCA(),
			'IsolationForest':IsolationForest(),
			'Isomap':Isomap(),
			'KMeans':KMeans(),
			'KNeighborsClassifier':KNeighborsClassifier(),
			'KNeighborsRegressor':KNeighborsRegressor(),
			'KernelCenterer':KernelCenterer(),
			'KernelDensity':KernelDensity(),
			'KernelPCA':KernelPCA(),
			'KernelRidge':KernelRidge(),
			'LSHForest':LSHForest(),
			'LabelPropagation':LabelPropagation(),
			'LabelSpreading':LabelSpreading(),
			'Lars':Lars(),
			'LarsCV':LarsCV(),
			'Lasso':Lasso(),
			'LassoCV':LassoCV(),
			'LassoLars':LassoLars(),
			'LassoLarsCV':LassoLarsCV(),
			'LassoLarsIC':LassoLarsIC(),
			'LatentDirichletAllocation':LatentDirichletAllocation(),
			'LedoitWolf':LedoitWolf(),
			'LinearDiscriminantAnalysis':LinearDiscriminantAnalysis(),
			'LinearRegression':LinearRegression(),
			'LinearSVC':LinearSVC(),
			'LinearSVR':LinearSVR(),
			'LocallyLinearEmbedding':LocallyLinearEmbedding(),
Exemple #6
0
def compare(X, Y, n, index, kernel='rbf', tol=0.01, max_iter=100, gamma=20):
    """
    Compare Propagation between our method and random method

    Parameters
    ----------
    X : 2D array
        The dataset
    Y : 1d array
        True label of every points in X
    n : int
        number of point to label first
    index :1d array of int
        array of index of the point to label
    kernel : str
        rbf
    tol : float
        tol for labelpropagation
    max_iter : int
        max_iter for labelpropagation
    gamma : int
        gamma for labelpropagation
    """
    plt.figure(figsize=(17, 8))
    # start with randomness
    ok = False
    c = 0
    # make sure we have a point of each class (at least)
    while not ok:
        label = np.random.randint(Y.shape[0], size=n)
        c += 1
        if len(np.unique(Y[label])) == len(np.unique(Y)):
            ok = True
    Y_unlabel = -np.ones(Y.shape[0])
    Y_unlabel[label] = Y[label]

    label_spread = LabelPropagation(kernel=kernel,
                                    tol=tol,
                                    max_iter=max_iter,
                                    n_jobs=-1,
                                    gamma=gamma)
    label_spread.fit(X, Y_unlabel)
    Y_predict = label_spread.transduction_
    iter_random = label_spread.n_iter_

    plt.subplot(1, 2, 1)
    oui = np.where(Y_predict == 0)[0]
    non = np.where(Y_predict == 1)[0]
    plt.scatter(X[oui, 0], X[oui, 1], color='b', marker='s', lw=0, s=10)
    plt.scatter(X[non, 0], X[non, 1], color='g', marker='s', lw=0, s=10)
    plot_interesting_points(X, label, 1, 0)

    # now active part
    label = index[:n]
    if len(np.unique(Y[label])) < len(np.unique(Y)):
        raise Exception("we have less points than classes")
    Y_unlabel = -np.ones(Y.shape[0])
    Y_unlabel[label] = Y[label]

    label_spread = LabelPropagation(kernel=kernel,
                                    tol=tol,
                                    max_iter=max_iter,
                                    n_jobs=-1,
                                    gamma=gamma)
    label_spread.fit(X, Y_unlabel)
    Y_predict = label_spread.transduction_
    iter_active = label_spread.n_iter_
    # plotting
    plt.subplot(1, 2, 2)
    oui = np.where(Y_predict == 0)[0]
    non = np.where(Y_predict == 1)[0]
    plt.scatter(X[oui, 0], X[oui, 1], color='b', marker='s', lw=0, s=10)
    plt.scatter(X[non, 0], X[non, 1], color='g', marker='s', lw=0, s=10)
    plot_interesting_points(X, label, 0.5, 0)
    return (iter_random, iter_active)