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


Python MultiLabelBinarizer.transpose方法代码示例

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


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

示例1: __kfold_prob_tp_fp

# 需要导入模块: from sklearn.preprocessing import MultiLabelBinarizer [as 别名]
# 或者: from sklearn.preprocessing.MultiLabelBinarizer import transpose [as 别名]
    def __kfold_prob_tp_fp(self, X, y, n_folds=2):
        # if isinstance(X, csr_matrix) and isinstance(y, np.ndarray):
        #     X=X.toarray()
        # elif isinstance(X, np.ndarray) and isinstance(y, np.ndarray):
        #     if len(y.shape)==1:
        #         y=MultiLabelBinarizer(classes=self.classes).fit_transform([[y_p] for y_p in y])
        #     elif len(y.shape)==2:
        #         pass
        if isinstance(y, list):
            y = np.asarray(y)

        try:
            with open(self.prefix + self.dir_name + "/" + str(n_folds) + "FCV_prob.pickle", "rb") as f:
                [tp_av, fp_av] = pickle.load(f)
        except:
            kf = KFold(y.shape[0], n_folds=n_folds)
            TP_avr = []
            FP_avr = []
            for train_index, test_index in kf:
                X_train, X_test = X[train_index], X[test_index]
                y_train, y_test = y[train_index], y[test_index]
                model = self.model
                model = model.fit(X_train, y_train)
                y_predict = model.predict(X_test)
                y_prob_predict = model.predict_proba(X_test)
                TP = []
                FP = []
                if len(y.shape) == 1:
                    y_predict = MultiLabelBinarizer(classes=self.classes).fit_transform([[y_p] for y_p in y_predict])
                elif len(y.shape) == 2:
                    pass
                for class_ind, class_prob in zip(y_predict.transpose(), y_prob_predict.transpose()):
                    TP_class = []
                    FP_class = []
                    for ind, prob in zip(class_ind, class_prob):
                        if ind == 1:
                            TP_class.append(prob)
                        elif ind == 0:
                            FP_class.append(prob)
                    TP.append(np.sum(TP_class) / len(class_ind))
                    FP.append(np.sum(FP_class) / len(class_ind))
                TP_avr.append(TP)
                FP_avr.append(FP)
            tp_av, fp_av = np.average(TP_avr, axis=0), np.average(FP_avr, axis=0)
            with open(self.prefix + self.dir_name + "/" + str(n_folds) + "FCV_prob.pickle", "wb") as f:
                pickle.dump([tp_av, fp_av], f)
                f.close()
            # print('tp, fp by prob', tp_av, fp_av)
        return [tp_av, fp_av]
开发者ID:Arctickirillas,项目名称:Rubrication,代码行数:51,代码来源:quantification.py


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