classification.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:Default-Credit-Card-Prediction 作者: AlexPnt 项目源码 文件源码
def predict(self, X):
        """
        Classify the input data assigning the label of the nearest prototype

        Keyword arguments:
        X -- The feature vectors
        """
        classification=np.zeros(len(X))

        if self.distance_metric=="euclidean":
            distances=pairwise_distances(X, self.M_,self.distance_metric)                                   #compute distances to the prototypes (template matching)
        if self.distance_metric=="minkowski":
            distances=pairwise_distances(X, self.M_,self.distance_metric)   
        elif self.distance_metric=="manhattan":
            distances=pairwise_distances(X, self.M_,self.distance_metric)
        elif self.distance_metric=="mahalanobis":
            distances=pairwise_distances(X, self.M_,self.distance_metric)
        else:
            distances=pairwise_distances(X, self.M_,"euclidean")

        for i in xrange(len(X)):
            classification[i]=self.outcomes[distances[i].tolist().index(min(distances[i]))]                 #choose the class belonging to nearest prototype distance

        return classification
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号