コード例 #1
0
    def predict(self):
        """
        trains the scikit-learn  python machine learning algorithm library function
        https://scikit-learn.org

        then passes the trained algorithm the features set and returns the
        predicted y test values form, the function

        then compares the y_test values from scikit-learn predicted to
        y_test values passed in

        then returns the accuracy
        """

        algorithm = MLPClassifier(
            solver=get_ohe_config().mlp_solver,
            alpha=get_ohe_config().MLP_alpha,
            max_iter=400,
            hidden_layer_sizes=(get_ohe_config().MLP_layers,
                                get_ohe_config().MLP_neurons),
            random_state=get_ohe_config().MLP_random_state)
        algorithm.fit(self.X_train, self.y_train)
        y_pred = list(algorithm.predict(self.X_test))
        self.acc = OneHotPredictor.get_accuracy(y_pred, self.y_test)
        return self.acc
コード例 #2
0
    def predict(self):
        """
         trains the scikit-learn  python machine learning algorithm library function
         https://scikit-learn.org

         then passes the trained algorithm the features set and returns the
         predicted y test values form, the function

         then compares the y_test values from scikit-learn predicted to
         y_test values passed in

         then returns the accuracy
         """
        algorithm = linear_model.LinearRegression()
        #print("self.y_train " + str(type(self.y_train)))

        algorithm.fit(self.X_train, self.y_train)

        y_pred_sk = algorithm.predict(self.X_test)
        #print("y_pred_sk " + str(type(y_pred_sk)))

        y_pred = list(algorithm.predict(self.X_test))

        # print(type(y_pred))

        self.acc = OneHotPredictor.get_accuracy(y_pred, self.y_test)
        return self.acc
コード例 #3
0
    def predict(self):
        """
Random forest

like its name implies, consists of a large number of individual decision trees
that operate as an ensemble. Each individual tree in the random forest spits out a
class prediction and the class with the most votes becomes our model’s prediction
A large number of relatively uncorrelated models (trees) operating as a
committee will outperform any of the individual constituent models.

The low correlation between models is the key. Just like how investments with low correlations
(like stocks and bonds) come together to form a portfolio that is greater than the sum of its parts,
uncorrelated models can produce ensemble predictions that are more accurate than any of the
individual predictions. The reason for this wonderful effect is that the trees protect each other
from their individual errors (as long as they don’t constantly all err in the same direction).
While some trees may be wrong, many other trees will be right, so as a group the trees are able to
move in the correct direction. So the prerequisites for random forest to perform well are:

There needs to be some actual signal in our features so that models built using those features do better than random guessing.
The predictions (and therefore the errors) made by the individual trees need to have low correlations with each other.


 Parameters
----------
X_test: array
    testing features

X_train: array
    training features

y_test: array
    testing label

y_train: array
    testing label

Returns:
----------
    target: array - label to be predicted or classified


        trains the scikit-learn  python machine learning algorithm library function
        https://scikit-learn.org

        then passes the trained algorithm the features set and returns the
        predicted y test values form, the function

        then compares the y_test values from scikit-learn predicted to
        y_test values passed in

        then returns the accuracy
        """
        algorithm = RandomForestClassifier(
            n_estimators=get_ohe_config().rf_estimators,
            max_depth=get_ohe_config().rf_max_depth)
        algorithm.fit(self.X_train, self.y_train)
        y_pred = list(algorithm.predict(self.X_test))
        self.acc = OneHotPredictor.get_accuracy(y_pred, self.y_test)
        return self.acc
コード例 #4
0
ファイル: mlp_regression_10.py プロジェクト: tmlrnc/axn_ml_2
 def predict(self):
     algorithm = MLPRegressor(hidden_layer_sizes=(10, 10),
                              learning_rate_init=0.01,
                              early_stopping=True)
     algorithm.fit(self.X_train, self.y_train)
     y_pred = list(algorithm.predict(self.X_test))
     self.acc = OneHotPredictor.get_accuracy(y_pred, self.y_test)
     return self.acc
コード例 #5
0
 def predict(self):
     algorithm = MLPClassifier(
         solver=get_ohe_config().mlp_solver,
         alpha=get_ohe_config().mlp_alpha,
         hidden_layer_sizes=(get_ohe_config().mlp_layers,
                             get_ohe_config().mlp_neurons),
         random_state=get_ohe_config().mlp_random_state)
     algorithm.fit(self.X_train, self.y_train)
     y_pred = list(algorithm.predict(self.X_test))
     self.acc = OneHotPredictor.get_accuracy(y_pred, self.y_test)
     return self.acc
コード例 #6
0
ファイル: ball_tree.py プロジェクト: tmlrnc/axn_ml_2
    def predict(self):
        """
        trains the scikit-learn  python machine learning algorithm library function
        https://scikit-learn.org

        then passes the trained algorithm the features set and returns the
        predicted y test values form, the function

        then compares the y_test values from scikit-learn predicted to
        y_test values passed in

        then returns the accuracy
        """
        algorithm = KNeighborsClassifier(algorithm='ball_tree')
        algorithm.fit(self.X_train.toarray(), self.y_train)
        y_pred = list(algorithm.predict(self.X_test.toarray()))
        self.acc = OneHotPredictor.get_accuracy(y_pred, self.y_test)
        return self.acc
コード例 #7
0
    def predict(self):
        """
        trains the scikit-learn  python machine learning algorithm library function
        https://scikit-learn.org

        then passes the trained algorithm the features set and returns the
        predicted y test values form, the function

        then compares the y_test values from scikit-learn predicted to
        y_test values passed in

        then returns the accuracy
        """
        algorithm = ExtraTreesClassifier(n_estimators=100, random_state=0)
        algorithm.fit(self.X_train, self.y_train)
        y_pred = list(algorithm.predict(self.X_test))
        self.acc = OneHotPredictor.get_accuracy(y_pred, self.y_test)
        return self.acc
コード例 #8
0
    def predict(self):
        """
         trains the scikit-learn  python machine learning algorithm library function
         https://scikit-learn.org

         then passes the trained algorithm the features set and returns the
         predicted y test values form, the function

         then compares the y_test values from scikit-learn predicted to
         y_test values passed in

         then returns the accuracy
         """
        algorithm = linear_model.BayesianRidge()
        algorithm.fit(self.X_train, self.y_train)
        y_pred = list(algorithm.predict(self.X_test))
        self.acc = OneHotPredictor.get_accuracy(y_pred, self.y_test)
        return self.acc
コード例 #9
0
ファイル: brute_force_radius.py プロジェクト: tmlrnc/axn_ml_2
    def predict(self):
        """
         trains the scikit-learn  python machine learning algorithm library function
         https://scikit-learn.org

         then passes the trained algorithm the features set and returns the
         predicted y test values form, the function

         then compares the y_test values from scikit-learn predicted to
         y_test values passed in

         then returns the accuracy
         """
        algorithm = RadiusNeighborsRegressor(
            radius=get_ohe_config().rnr_radius)
        algorithm.fit(self.X_train, self.y_train)
        y_pred = list(algorithm.predict(self.X_test))
        self.acc = OneHotPredictor.get_accuracy(y_pred, self.y_test)
        return self.acc
コード例 #10
0
    def predict(self):
        """
        trains the scikit-learn python machine learning algorithm library function
        https://scikit-learn.org

        then passes the trained algorithm the features set and returns the
        predicted y test values form, the function

        then compares the y_test values from scikit-learn predicted to
        y_test values passed in

        then returns the accuracy
        """
        algorithm = LogisticRegression(
            solver='newton-cg', random_state=get_ohe_config().lr_random_state)
        algorithm.fit(self.X_train, self.y_train)
        y_pred = list(algorithm.predict(self.X_test))
        self.acc = OneHotPredictor.get_accuracy(y_pred, self.y_test)
        return self.acc
コード例 #11
0
    def predict(self):
        """
        trains the scikit-learn  python machine learning algorithm library function
        https://scikit-learn.org

        then passes the trained algorithm the features set and returns the
        predicted y test values form, the function

        then compares the y_test values from scikit-learn predicted to
        y_test values passed in

        then returns the accuracy
        """
        kernel = 1.0 * RBF(1.0)
        algorithm = GaussianProcessClassifier(kernel=kernel, random_state=0)
        algorithm.fit(self.X_train.toarray(), self.y_train)
        y_pred = list(algorithm.predict(self.X_test.toarray()))
        self.acc = OneHotPredictor.get_accuracy(y_pred, self.y_test)
        return self.acc
コード例 #12
0
ファイル: pac_class_weights.py プロジェクト: tmlrnc/axn_ml_2
    def predict(self):
        """
         trains the scikit-learn  python machine learning algorithm library function
         https://scikit-learn.org

         then passes the trained algorithm the features set and returns the
         predicted y test values form, the function

         then compares the y_test values from scikit-learn predicted to
         y_test values passed in

         then returns the accuracy
         """
        algorithm = PassiveAggressiveClassifier(
            max_iter=1000, random_state=0, tol=1e-3, class_weight='balanced')
        algorithm.fit(self.X_train, self.y_train)
        y_pred = list(algorithm.predict(self.X_test))
        self.acc = OneHotPredictor.get_accuracy(y_pred, self.y_test)
        return self.acc
コード例 #13
0
ファイル: omp_cv.py プロジェクト: tmlrnc/axn_ml_2
    def predict(self):
        """
         trains the scikit-learn  python machine learning algorithm library function
         https://scikit-learn.org

         then passes the trained algorithm the features set and returns the
         predicted y test values form, the function

         then compares the y_test values from scikit-learn predicted to
         y_test values passed in

         then returns the accuracy
         """

        n_nonzero_coefs = 17
        algorithm = OrthogonalMatchingPursuitCV()
        algorithm.fit(self.X_train, self.y_train)
        y_pred = list(algorithm.predict(self.X_test))
        self.acc = OneHotPredictor.get_accuracy(y_pred, self.y_test)
        return self.acc
コード例 #14
0
    def predict(self):
        """
        trains the scikit-learn  python machine learning algorithm library function
        https://scikit-learn.org

        then passes the trained algorithm the features set and returns the
        predicted y test values form, the function

        then compares the y_test values from scikit-learn predicted to
        y_test values passed in

        then returns the accuracy
        """
        algorithm = KNeighborsClassifier(
            n_neighbors=get_ohe_config().kneighbors_classifiernn,
            metric='minkowski')
        algorithm.fit(self.X_train, self.y_train)
        y_pred = list(algorithm.predict(self.X_test))
        self.acc = OneHotPredictor.get_accuracy(y_pred, self.y_test)
        return self.acc
コード例 #15
0
    def predict(self):
        """
        trains the scikit-learn  python machine learning algorithm library function
        https://scikit-learn.org

        then passes the trained algorithm the features set and returns the
        predicted y test values form, the function

        then compares the y_test values from scikit-learn predicted to
        y_test values passed in

        then returns the accuracy
        """
        algorithm = DecisionTreeClassifier(criterion='entropy')
        algorithm.fit(self.X_train, self.y_train)
        y_pred = list(algorithm.predict(self.X_test))

        self.acc = OneHotPredictor.get_accuracy(y_pred, self.y_test)

        return self.acc
コード例 #16
0
ファイル: svm.py プロジェクト: tmlrnc/axn_ml_2
    def predict(self):
        """
         trains the scikit-learn  python machine learning algorithm library function
         https://scikit-learn.org

         then passes the trained algorithm the features set and returns the
         predicted y test values form, the function

         then compares the y_test values from scikit-learn predicted to
         y_test values passed in

         then returns the accuracy
         """
        algorithm = LinearSVC(random_state=get_ohe_config().lr_random_state,
                              max_iter=-1,
                              multi_class=get_ohe_config().s_multi_class)
        algorithm.fit(self.X_train, self.y_train)
        y_pred = list(algorithm.predict(self.X_test))
        self.acc = OneHotPredictor.get_accuracy(y_pred, self.y_test)
        return self.acc
コード例 #17
0
    def predict(self):
        """
        trains the scikit-learn  python machine learning algorithm library function
        https://scikit-learn.org

        then passes the trained algorithm the features set and returns the
        predicted y test values form, the function

        then compares the y_test values from scikit-learn predicted to
        y_test values passed in

        then returns the accuracy
        """
        algorithm = KMeans(
            n_clusters=get_ohe_config().kmeans_bins,
            random_state=0)
        algorithm.fit(self.X_train, self.y_train)
        y_pred = list(algorithm.predict(self.X_test))
        self.acc = OneHotPredictor.get_accuracy(y_pred, self.y_test)
        return self.acc
コード例 #18
0
    def predict(self):
        """
        trains the scikit-learn  python machine learning algorithm library function
        https://scikit-learn.org

        then passes the trained algorithm the features set and returns the
        predicted y test values form, the function

        then compares the y_test values from scikit-learn predicted to
        y_test values passed in

        then returns the accuracy
        """
        algorithm = RandomForestRegressor(
            n_estimators=get_ohe_config().r_n_estimators,
            max_depth=get_ohe_config().r_max_depth,
            max_features='sqrt')
        algorithm.fit(self.X_train, self.y_train)
        y_pred = list(algorithm.predict(self.X_test))
        self.acc = OneHotPredictor.get_accuracy(y_pred, self.y_test)
        return self.acc
コード例 #19
0
    def predict(self):
        """
         trains the scikit-learn  python machine learning algorithm library function
         https://scikit-learn.org

         then passes the trained algorithm the features set and returns the
         predicted y test values form, the function

         then compares the y_test values from scikit-learn predicted to
         y_test values passed in

         then returns the accuracy
         """
        algorithm = Perceptron(tol=1e-3,
                               random_state=0,
                               class_weight="balanced",
                               penalty="l1")
        algorithm.fit(self.X_train, self.y_train)
        y_pred = list(algorithm.predict(self.X_test))
        self.acc = OneHotPredictor.get_accuracy(y_pred, self.y_test)
        return self.acc