当前位置: 首页>>代码示例>>Python>>正文


Python validation.NotFittedError方法代码示例

本文整理汇总了Python中sklearn.utils.validation.NotFittedError方法的典型用法代码示例。如果您正苦于以下问题:Python validation.NotFittedError方法的具体用法?Python validation.NotFittedError怎么用?Python validation.NotFittedError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sklearn.utils.validation的用法示例。


在下文中一共展示了validation.NotFittedError方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: predict

# 需要导入模块: from sklearn.utils import validation [as 别名]
# 或者: from sklearn.utils.validation import NotFittedError [as 别名]
def predict(self, X):
        """Perform classification on samples in X.
        
        Parameters
        ----------
        X : array-like, shape = [n_samples, n_features]
            Matrix containing new samples
        
        Returns
        -------
        y_pred : array, shape = [n_samples]
            The value of prediction for each sample
        """
        
        if self.is_fitted == False:
            raise NotFittedError("This KOMD instance is not fitted yet. Call 'fit' with appropriate arguments before using this method.")
        X = check_array(X, accept_sparse='csr', dtype=np.float64, order="C")
        if self.multiclass_ == True:
            return self.cls.predict(X)
        
        return np.array([self.classes_[1] if p >=0 else self.classes_[0] for p in self.decision_function(X)]) 
开发者ID:IvanoLauriola,项目名称:MKLpy,代码行数:23,代码来源:komd.py

示例2: decision_function

# 需要导入模块: from sklearn.utils import validation [as 别名]
# 或者: from sklearn.utils.validation import NotFittedError [as 别名]
def decision_function(self, X):
        """Distance of the samples in X to the separating hyperplane.
        
        Parameters
        ----------
        X : array-like, shape = [n_samples, n_features]
        
        Returns
        -------
        Z : array-like, shape = [n_samples, 1]
            Returns the decision function of the samples.
        """
        
        if self.is_fitted == False:
            raise NotFittedError("This KOMD instance is not fitted yet. Call 'fit' with appropriate arguments before using this method.")
        X = check_array(X, accept_sparse='csr', dtype=np.float64, order="C")
        
        if self.multiclass_ == True:
            return self.cls.decision_function(X)
        
        Kf = self.__kernel_definition__()
        YY = matrix(np.diag(list(matrix(self.Y))))
        ker_matrix = matrix(Kf(X,self.X).astype(np.double))
        z = ker_matrix*YY*self.gamma
        z = z-self.bias
        return np.array(list(z)) 
开发者ID:IvanoLauriola,项目名称:MKLpy,代码行数:28,代码来源:komd.py

示例3: transform

# 需要导入模块: from sklearn.utils import validation [as 别名]
# 或者: from sklearn.utils.validation import NotFittedError [as 别名]
def transform(self, X, y=None):
        """Use the model to transform matrix to Shared Response space

        Parameters
        ----------
        X : list of 2D arrays, element i has shape=[voxels_i, samples_i]
            Each element in the list contains the fMRI data of one subject
            note that number of voxels and samples can vary across subjects
        y : not used (as it is unsupervised learning)


        Returns
        -------
        s : list of 2D arrays, element i has shape=[features_i, samples_i]
            Shared responses from input data (X)
        """

        # Check if the model exist
        if hasattr(self, 'w_') is False:
            raise NotFittedError("The model fit has not been run yet.")

        # Check the number of subjects
        if len(X) != len(self.w_):
            raise ValueError("The number of subjects does not match the one"
                             " in the model.")

        s = [None] * len(X)
        for subject in range(len(X)):
            s[subject] = self.w_[subject].T.dot(X[subject])

        return s 
开发者ID:ContextLab,项目名称:hypertools,代码行数:33,代码来源:srm.py

示例4: transform

# 需要导入模块: from sklearn.utils import validation [as 别名]
# 或者: from sklearn.utils.validation import NotFittedError [as 别名]
def transform(self, X):
        """Use the model to transform new data to Shared Response space

        Parameters
        ----------

        X : list of 2D arrays, element i has shape=[voxels_i, timepoints_i]
            Each element in the list contains the fMRI data of one subject.

        Returns
        -------

        r : list of 2D arrays, element i has shape=[features_i, timepoints_i]
            Shared responses from input data (X)

        s : list of 2D arrays, element i has shape=[voxels_i, timepoints_i]
            Individual data obtained from fitting model to input data (X)
        """
        # Check if the model exist
        if hasattr(self, 'w_') is False:
            raise NotFittedError("The model fit has not been run yet.")

        # Check the number of subjects
        if len(X) != len(self.w_):
            raise ValueError("The number of subjects does not match the one"
                             " in the model.")

        r = [None] * len(X)
        s = [None] * len(X)
        for subject in range(len(X)):
            if X[subject] is not None:
                r[subject], s[subject] = self._transform_new_data(X[subject],
                                                                  subject)

        return r, s 
开发者ID:brainiak,项目名称:brainiak,代码行数:37,代码来源:rsrm.py

示例5: transform_subject

# 需要导入模块: from sklearn.utils import validation [as 别名]
# 或者: from sklearn.utils.validation import NotFittedError [as 别名]
def transform_subject(self, X):
        """Transform a new subject using the existing model

        Parameters
        ----------

        X : 2D array, shape=[voxels, timepoints]
            The fMRI data of the new subject.

        Returns
        -------

        w : 2D array, shape=[voxels, features]
            Orthogonal mapping `W_{new}` for new subject

        s : 2D array, shape=[voxels, timepoints]
            Individual term `S_{new}` for new subject
        """
        # Check if the model exist
        if hasattr(self, 'w_') is False:
            raise NotFittedError("The model fit has not been run yet.")

        # Check the number of TRs in the subject
        if X.shape[1] != self.r_.shape[1]:
            raise ValueError("The number of timepoints(TRs) does not match the"
                             "one in the model.")

        s = np.zeros_like(X)
        for i in range(self.n_iter):
            w = self._update_transform_subject(X, s, self.r_)
            s = self._shrink(X - w.dot(self.r_), self.lam)

        return w, s 
开发者ID:brainiak,项目名称:brainiak,代码行数:35,代码来源:rsrm.py

示例6: transform

# 需要导入模块: from sklearn.utils import validation [as 别名]
# 或者: from sklearn.utils.validation import NotFittedError [as 别名]
def transform(self, X, y=None):
        """Use the model to transform matrix to Shared Response space

        Parameters
        ----------

        X : list of 2D arrays, element i has shape=[voxels_i, samples_i]
            Each element in the list contains the fMRI data of one subject
            note that number of voxels and samples can vary across subjects.

        y : not used as it only applies the mappings


        Returns
        -------

        s : list of 2D arrays, element i has shape=[features_i, samples_i]
            Shared responses from input data (X)
        """

        # Check if the model exist
        if hasattr(self, 'w_') is False:
            raise NotFittedError("The model fit has not been run yet.")

        # Check the number of subjects
        if len(X) != len(self.w_):
            raise ValueError("The number of subjects does not match the one"
                             " in the model.")

        s = [None] * len(X)
        for subject in range(len(X)):
            s[subject] = self.w_[subject].T.dot(X[subject])

        return s 
开发者ID:brainiak,项目名称:brainiak,代码行数:36,代码来源:sssrm.py

示例7: predict

# 需要导入模块: from sklearn.utils import validation [as 别名]
# 或者: from sklearn.utils.validation import NotFittedError [as 别名]
def predict(self, X):
        """Classify the output for given data

        Parameters
        ----------

        X : list of 2D arrays, element i has shape=[voxels_i, samples_i]
            Each element in the list contains the fMRI data of one subject
            The number of voxels should be according to each subject at
            the moment of training the model.

        Returns
        -------
        p: list of arrays, element i has shape=[samples_i]
            Predictions for each data sample.
        """
        # Check if the model exist
        if hasattr(self, 'w_') is False:
            raise NotFittedError("The model fit has not been run yet.")

        # Check the number of subjects
        if len(X) != len(self.w_):
            raise ValueError("The number of subjects does not match the one"
                             " in the model.")

        X_shared = self.transform(X)
        p = [None] * len(X_shared)
        for subject in range(len(X_shared)):
            sumexp, _, exponents = utils.sumexp_stable(
                self.theta_.T.dot(X_shared[subject]) + self.bias_)
            p[subject] = self.classes_[
                (exponents / sumexp[np.newaxis, :]).argmax(axis=0)]

        return p 
开发者ID:brainiak,项目名称:brainiak,代码行数:36,代码来源:sssrm.py

示例8: check_is_fitted

# 需要导入模块: from sklearn.utils import validation [as 别名]
# 或者: from sklearn.utils.validation import NotFittedError [as 别名]
def check_is_fitted(estimator, attribute):
    if not hasattr(estimator, attribute):
        raise NotFittedError(
            "This %s instance is not fitted yet. Call 'fit' with "
            "appropriate arguments before using this method."
            % type(estimator).__name__) 
开发者ID:hmmlearn,项目名称:hmmlearn,代码行数:8,代码来源:_utils.py


注:本文中的sklearn.utils.validation.NotFittedError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。