Python sklearn.metrics.regression.mean_squared_error() Examples

The following are 5 code examples of sklearn.metrics.regression.mean_squared_error(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sklearn.metrics.regression , or try the search function .
Example #1
Source File: models.py    From fireTS with MIT License 6 votes vote down vote up
def score(self, X, y, step=1, method="r2"):
        """
        Produce multi-step prediction of y, and compute the metrics against y.
        Nan is ignored when computing the metrics.

        :param array-like X: exogenous input time series, shape = (n_samples,
                             n_exog_inputs)
        :param array-like y: target time series to predict, shape = (n_samples)
        :param int step: prediction step.
        :param string method: could be "r2" (R Square) or "mse" (Mean Square
                              Error).

        :return: prediction metric. Nan is ignored when computing the metrics.
        """
        ypred = self.predict(X, y, step=step)
        mask = np.isnan(y) | np.isnan(ypred)
        if method == "r2":
            return r2_score(y[~mask], ypred[~mask])
        elif method == "mse":
            return mean_squared_error(y[~mask], ypred[~mask]) 
Example #2
Source File: models.py    From fireTS with MIT License 6 votes vote down vote up
def score(self, X, y, method="r2", verbose=False):
        """
        Produce multi-step prediction of y, and compute the metrics against y.
        Nan is ignored when computing the metrics.

        :param array-like X: exogenous input time series, shape = (n_samples,
                             n_exog_inputs)
        :param array-like y: target time series to predict, shape = (n_samples)
        :param string method: could be "r2" (R Square) or "mse" (Mean Square
                              Error).

        :return: prediction metric. Nan is ignored when computing the metrics.
        """
        ypred = self.predict(X, y)
        mask = np.isnan(y) | np.isnan(ypred)
        if verbose:
            print('Evaluating {} score, {} of {} data points are evaluated.'.
                  format(method, np.sum(~mask), y.shape[0]))
        if method == "r2":
            return r2_score(y[~mask], ypred[~mask])
        elif method == "mse":
            return mean_squared_error(y[~mask], ypred[~mask])
        else:
            raise ValueError('{} method is not supported. Please choose from \"r2\" or \"mse\".') 
Example #3
Source File: mse_predictions_by_dimension.py    From multi-categorical-gans with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def plot_predictions_by_dimension(data_x, data_y, data_test):
    score_y_by_dimension = predictions_by_dimension(data_y, data_test)
    score_x_by_dimension = predictions_by_dimension(data_x, data_test)
    mse = mean_squared_error(score_x_by_dimension, score_y_by_dimension)
    return score_x_by_dimension, score_y_by_dimension, mse 
Example #4
Source File: mse_predictions_by_categorical.py    From multi-categorical-gans with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def plot_predictions_by_categorical(data_x, data_y, data_test, variable_sizes):
    score_y_by_categorical = predictions_by_categorical(data_y, data_test, variable_sizes)
    score_x_by_categorical = predictions_by_categorical(data_x, data_test, variable_sizes)
    mse = mean_squared_error(score_x_by_categorical, score_y_by_categorical)
    return score_x_by_categorical, score_y_by_categorical, mse 
Example #5
Source File: mse_probabilities_by_dimension.py    From multi-categorical-gans with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def mse_probabilities_by_dimension(data_x, data_y):
    p_x_by_dimension = probabilities_by_dimension(data_x)
    p_y_by_dimension = probabilities_by_dimension(data_y)
    mse = mean_squared_error(p_x_by_dimension, p_y_by_dimension)
    return p_x_by_dimension, p_y_by_dimension, mse