當前位置: 首頁>>代碼示例>>Python>>正文


Python sklearn.preprocessing方法代碼示例

本文整理匯總了Python中sklearn.preprocessing方法的典型用法代碼示例。如果您正苦於以下問題:Python sklearn.preprocessing方法的具體用法?Python sklearn.preprocessing怎麽用?Python sklearn.preprocessing使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sklearn的用法示例。


在下文中一共展示了sklearn.preprocessing方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: encoded_1d

# 需要導入模塊: import sklearn [as 別名]
# 或者: from sklearn import preprocessing [as 別名]
def encoded_1d(samples):
        """ Returns a unique label for each combination of samples """
        # from sklearn.preprocessing import MultiLabelBinarizer
        encoded_2d = samples.encoded_2d()
        class_space = [v.n_classes for k, v in samples.items()]
        offsets = np.array([1] + np.cumprod(class_space).tolist()[:-1])[None, :]
        encoded_1d = (offsets * encoded_2d).sum(axis=1)
        # e = MultiLabelBinarizer()
        # bin_coeff = e.fit_transform(encoded_2d)
        # bin_basis = (2 ** np.arange(bin_coeff.shape[1]))[None, :]
        # # encoded_1d = (bin_coeff * bin_basis).sum(axis=1)
        # encoded_1d = (bin_coeff * bin_basis[::-1]).sum(axis=1)
        # # vt.unique_rows(sklearn.preprocessing.MultiLabelBinarizer().fit_transform(encoded_2d))
        # [v.encoded_df.values for k, v in samples.items()]
        # encoded_df_1d = pd.concat([v.encoded_df for k, v in samples.items()], axis=1)
        return encoded_1d 
開發者ID:Erotemic,項目名稱:ibeis,代碼行數:18,代碼來源:clf_helpers.py

示例2: __init__

# 需要導入模塊: import sklearn [as 別名]
# 或者: from sklearn import preprocessing [as 別名]
def __init__(self,
                 component_config: Dict[Text, Any] = None,
                 clf: 'sklearn.model_selection.GridSearchCV' = None,
                 le: Optional['sklearn.preprocessing.LabelEncoder'] = None
                 ) -> None:
        """Construct a new intent classifier using the sklearn framework."""
        from sklearn.preprocessing import LabelEncoder

        super(SklearnIntentClassifier, self).__init__(component_config)

        if le is not None:
            self.le = le
        else:
            self.le = LabelEncoder()
        self.clf = clf

        _sklearn_numpy_warning_fix() 
開發者ID:weizhenzhao,項目名稱:rasa_nlu,代碼行數:19,代碼來源:sklearn_intent_classifier.py

示例3: get_scaler

# 需要導入模塊: import sklearn [as 別名]
# 或者: from sklearn import preprocessing [as 別名]
def get_scaler(df, missing="zeros", scaler="standard", **kwargs):
        """
        Fit a sklearn scaler on a Data Frame and return the scaler.
        Valid options for the scaler are: standard, minmax, maxabs, robust, quantile
        Missing values must be dealt with before the scaling is applied. 
        Valid options specified through the missing parameter are: zeros, mean, median, mode
        """

        scalers = {'standard':'StandardScaler', 'minmax':'MinMaxScaler', 'maxabs':'MaxAbsScaler',\
                   'robust':'RobustScaler', 'quantile':'QuantileTransformer'}

        s = getattr(preprocessing, scalers[scaler])
        s = s(**kwargs)

        df = Preprocessor.fillna(df, missing=missing)
        
        return s.fit(df) 
開發者ID:nabeel-oz,項目名稱:qlik-py-tools,代碼行數:19,代碼來源:preprocessor.py

示例4: scale

# 需要導入模塊: import sklearn [as 別名]
# 或者: from sklearn import preprocessing [as 別名]
def scale(df, missing="zeros", scaler="robust", **kwargs):
    """
    Scale values in a Data Frame using the relevant sklearn preprocessing method.
    Valid options for the scaler are: standard, minmax, maxabs, robust, quantile
    Missing values must be dealt with before the scaling is applied. 
    Valid options specified through the missing parameter are: zeros, mean, median, mode
    """
    
    scalers = {'standard':'StandardScaler', 'minmax':'MinMaxScaler', 'maxabs':'MaxAbsScaler',\
               'robust':'RobustScaler', 'quantile':'QuantileTransformer'}
    
    s = getattr(preprocessing, scalers[scaler])
    s = s(**kwargs)
    
    df = fillna(df, method=missing)
    df = pd.DataFrame(s.fit_transform(df), index=df.index, columns=df.columns)
    
    return df 
開發者ID:nabeel-oz,項目名稱:qlik-py-tools,代碼行數:20,代碼來源:_utils.py

示例5: __init__

# 需要導入模塊: import sklearn [as 別名]
# 或者: from sklearn import preprocessing [as 別名]
def __init__(
        self,
        component_config: Optional[Dict[Text, Any]] = None,
        clf: "sklearn.model_selection.GridSearchCV" = None,
        le: Optional["sklearn.preprocessing.LabelEncoder"] = None,
    ) -> None:
        """Construct a new intent classifier using the sklearn framework."""
        from sklearn.preprocessing import LabelEncoder

        super().__init__(component_config)

        if le is not None:
            self.le = le
        else:
            self.le = LabelEncoder()
        self.clf = clf 
開發者ID:botfront,項目名稱:rasa-for-botfront,代碼行數:18,代碼來源:sklearn_intent_classifier.py

示例6: load

# 需要導入模塊: import sklearn [as 別名]
# 或者: from sklearn import preprocessing [as 別名]
def load(
        cls,
        meta: Dict[Text, Any],
        model_dir: Optional[Text] = None,
        model_metadata: Optional[Metadata] = None,
        cached_component: Optional["SklearnIntentClassifier"] = None,
        **kwargs: Any,
    ) -> "SklearnIntentClassifier":
        from sklearn.preprocessing import LabelEncoder

        classifier_file = os.path.join(model_dir, meta.get("classifier"))
        encoder_file = os.path.join(model_dir, meta.get("encoder"))

        if os.path.exists(classifier_file):
            classifier = io_utils.json_unpickle(classifier_file)
            classes = io_utils.json_unpickle(encoder_file)
            encoder = LabelEncoder()
            encoder.classes_ = classes
            return cls(meta, classifier, encoder)
        else:
            return cls(meta) 
開發者ID:botfront,項目名稱:rasa-for-botfront,代碼行數:23,代碼來源:sklearn_intent_classifier.py

示例7: __init__

# 需要導入模塊: import sklearn [as 別名]
# 或者: from sklearn import preprocessing [as 別名]
def __init__(self,
                 component_config=None,  # type: Dict[Text, Any]
                 clf=None,  # type: sklearn.model_selection.GridSearchCV
                 le=None  # type: sklearn.preprocessing.LabelEncoder
                 ):
        # type: (...) -> None
        """Construct a new intent classifier using the sklearn framework."""
        from sklearn.preprocessing import LabelEncoder

        super(SklearnIntentClassifier, self).__init__(component_config)

        if le is not None:
            self.le = le
        else:
            self.le = LabelEncoder()
        self.clf = clf

        _sklearn_numpy_warning_fix() 
開發者ID:crownpku,項目名稱:Rasa_NLU_Chi,代碼行數:20,代碼來源:sklearn_intent_classifier.py

示例8: convert_inst_scores_to_cls_scores

# 需要導入模塊: import sklearn [as 別名]
# 或者: from sklearn import preprocessing [as 別名]
def convert_inst_scores_to_cls_scores(similarity, testset0, testset1, num_identity, lbl_map):
    cls_scores1 = []
    for i in range(len(similarity)):
        cls_score = np.zeros(num_identity)
        for j in range(len(similarity[i])):
            id = lbl_map[testset1[j].identity_id]
            cls_score[id] = max(cls_score[id], similarity[i][j])
        cls_scores1.append(cls_score)
    cls_scores1 = np.array(cls_scores1)
    cls_scores1 = sklearn.preprocessing.normalize(cls_scores1)

    similarity = np.transpose(similarity)
    cls_scores2 = []
    for i in range(len(similarity)):
        cls_score = np.zeros(num_identity)
        for j in range(len(similarity[i])):
            id = lbl_map[testset0[j].identity_id]
            cls_score[id] = max(cls_score[id], similarity[i][j])
        cls_scores2.append(cls_score)
    cls_scores2 = np.array(cls_scores2)
    cls_scores2 = sklearn.preprocessing.normalize(cls_scores2)

    return cls_scores1, cls_scores2 
開發者ID:ymao1993,項目名稱:HumanRecognition,代碼行數:25,代碼來源:performance_test.py

示例9: squiggle_search2_old

# 需要導入模塊: import sklearn [as 別名]
# 或者: from sklearn import preprocessing [as 別名]
def squiggle_search2_old(squiggle,kmerhash,seqlen):
    result=[]

    for ref in kmerhash:
        #print "ss2",ref
        queryarray = sklearn.preprocessing.scale(np.array(squiggle),axis=0,with_mean=True,with_std=True,copy=True)

        dist, cost, path = mlpy.dtw_subsequence(queryarray,kmerhash[ref]['Fprime'])
        result.append((dist,ref,"F",path[1][0],ref,path[1][-1]))
        dist, cost, path = mlpy.dtw_subsequence(queryarray,kmerhash[ref]['Rprime'])
        result.append((dist,ref,"R",path[1][0],ref,path[1][-1]))

    #('J02459', 41.017514495176989, 'F', 10003, 'J02459', 10198)
    #distanceR,seqmatchnameR,frR,rsR,reR,qsR,qeR=sorted(result,key=lambda result: result[0])[0]
    #return seqmatchnameR,distanceR,frR,rsR,reR,qsR,qeR
    return sorted(result,key=lambda result: result[0])[0][1],sorted(result,key=lambda result: result[0])[0][0],sorted(result,key=lambda result: result[0])[0][2],sorted(result,key=lambda result: result[0])[0][3],sorted(result,key=lambda result: result[0])[0][4],sorted(result,key=lambda result: result[0])[0][5]

######################################################################

###################################################################### 
開發者ID:mattloose,項目名稱:RUscripts,代碼行數:22,代碼來源:test_gReadUntil.py

示例10: get_feature

# 需要導入模塊: import sklearn [as 別名]
# 或者: from sklearn import preprocessing [as 別名]
def get_feature(imgs, nets):
  count = len(imgs)
  data = mx.nd.zeros(shape = (count*2, 3, imgs[0].shape[0], imgs[0].shape[1]))
  for idx, img in enumerate(imgs):
    img = img[:,:,::-1] #to rgb
    img = np.transpose( img, (2,0,1) )
    for flipid in [0,1]:
      _img = np.copy(img)
      if flipid==1:
        _img = _img[:,:,::-1]
      _img = nd.array(_img)
      data[count*flipid+idx] = _img

  F = []
  for net in nets:
    db = mx.io.DataBatch(data=(data,))
    net.model.forward(db, is_train=False)
    x = net.model.get_outputs()[0].asnumpy()
    embedding = x[0:count,:] + x[count:,:]
    embedding = sklearn.preprocessing.normalize(embedding)
    #print('emb', embedding.shape)
    F.append(embedding)
  F = np.concatenate(F, axis=1)
  F = sklearn.preprocessing.normalize(F)
  #print('F', F.shape)
  return F 
開發者ID:deepinsight,項目名稱:insightface,代碼行數:28,代碼來源:gen_megaface.py

示例11: get_feature

# 需要導入模塊: import sklearn [as 別名]
# 或者: from sklearn import preprocessing [as 別名]
def get_feature(buffer):
  global emb_size
  if use_flip:
    input_blob = np.zeros( (len(buffer)*2, 3, image_shape[1], image_shape[2] ) )
  else:
    input_blob = np.zeros( (len(buffer), 3, image_shape[1], image_shape[2] ) )
  idx = 0
  for item in buffer:
    img = face_preprocess.read_image(item[0], mode='rgb')
    img = face_preprocess.preprocess(img, bbox=None, landmark=item[1], image_size='%d,%d'%(image_shape[1], image_shape[2]))
    img = np.transpose( img, (2,0,1) )
    attempts = [0,1] if use_flip else [0]
    for flipid in attempts:
      _img = np.copy(img)
      if flipid==1:
        do_flip(_img)
      input_blob[idx] = _img
      idx+=1
  data = mx.nd.array(input_blob)
  db = mx.io.DataBatch(data=(data,))
  net.model.forward(db, is_train=False)
  _embedding = net.model.get_outputs()[0].asnumpy()
  if emb_size==0:
    emb_size = _embedding.shape[1]
    print('set emb_size to ', emb_size)
  embedding = np.zeros( (len(buffer), emb_size), dtype=np.float32 )
  if use_flip:
    embedding1 = _embedding[0::2]
    embedding2 = _embedding[1::2]
    embedding = embedding1+embedding2
  else:
    embedding = _embedding
  embedding = sklearn.preprocessing.normalize(embedding)
  return embedding 
開發者ID:deepinsight,項目名稱:insightface,代碼行數:36,代碼來源:gen_glint.py

示例12: get_feature

# 需要導入模塊: import sklearn [as 別名]
# 或者: from sklearn import preprocessing [as 別名]
def get_feature(buffer):
  global emb_size
  if use_flip:
    input_blob = np.zeros( (len(buffer)*2, 3, image_shape[1], image_shape[2] ) )
  else:
    input_blob = np.zeros( (len(buffer), 3, image_shape[1], image_shape[2] ) )
  idx = 0
  for item in buffer:
    img = cv2.imread(item)[:,:,::-1] #to rgb
    img = np.transpose( img, (2,0,1) )
    attempts = [0,1] if use_flip else [0]
    for flipid in attempts:
      _img = np.copy(img)
      if flipid==1:
        do_flip(_img)
      input_blob[idx] = _img
      idx+=1
  data = mx.nd.array(input_blob)
  db = mx.io.DataBatch(data=(data,))
  net.model.forward(db, is_train=False)
  _embedding = net.model.get_outputs()[0].asnumpy()
  if emb_size==0:
    emb_size = _embedding.shape[1]
    print('set emb_size to ', emb_size)
  embedding = np.zeros( (len(buffer), emb_size), dtype=np.float32 )
  if use_flip:
    embedding1 = _embedding[0::2]
    embedding2 = _embedding[1::2]
    embedding = embedding1+embedding2
  else:
    embedding = _embedding
  embedding = sklearn.preprocessing.normalize(embedding)
  return embedding 
開發者ID:deepinsight,項目名稱:insightface,代碼行數:35,代碼來源:gen_image_feature.py

示例13: get_feature

# 需要導入模塊: import sklearn [as 別名]
# 或者: from sklearn import preprocessing [as 別名]
def get_feature(buffer):
  global emb_size
  input_count = len(buffer)
  if use_flip:
    input_count *= 2
  network_count = input_count
  if input_count%ctx_num!=0:
    network_count = (input_count//ctx_num+1)*ctx_num

  input_blob = np.zeros( (network_count, 3, image_shape[1], image_shape[2]), dtype=np.float32)
  idx = 0
  for item in buffer:
    img = cv2.imread(item)[:,:,::-1] #to rgb
    img = np.transpose( img, (2,0,1) )
    attempts = [0,1] if use_flip else [0]
    for flipid in attempts:
      _img = np.copy(img)
      if flipid==1:
        do_flip(_img)
      input_blob[idx] = _img
      idx+=1
  data = mx.nd.array(input_blob)
  db = mx.io.DataBatch(data=(data,))
  net.model.forward(db, is_train=False)
  _embedding = net.model.get_outputs()[0].asnumpy()
  _embedding = _embedding[0:input_count]
  if emb_size==0:
    emb_size = _embedding.shape[1]
    print('set emb_size to ', emb_size)
  embedding = np.zeros( (len(buffer), emb_size), dtype=np.float32 )
  if use_flip:
    embedding1 = _embedding[0::2]
    embedding2 = _embedding[1::2]
    embedding = embedding1+embedding2
  else:
    embedding = _embedding
  embedding = sklearn.preprocessing.normalize(embedding)
  return embedding 
開發者ID:deepinsight,項目名稱:insightface,代碼行數:40,代碼來源:gen_video_feature.py

示例14: predict_proba

# 需要導入模塊: import sklearn [as 別名]
# 或者: from sklearn import preprocessing [as 別名]
def predict_proba(self, X):
        predictions = self.predict(X)
        predictions = sklearn.preprocessing.scale(predictions)
        predictions = 1.0 / (1.0 + np.exp(-0.5 * predictions))
        return np.vstack((1.0 - predictions, predictions)).T 
開發者ID:MichaelHills,項目名稱:seizure-prediction,代碼行數:7,代碼來源:classifiers.py

示例15: svc_example

# 需要導入模塊: import sklearn [as 別名]
# 或者: from sklearn import preprocessing [as 別名]
def svc_example(n_samples = 10000, n_features = 4):
	from sklearn.svm import LinearSVC
	from sklearn.preprocessing import PolynomialFeatures
	from sklearn.datasets import make_classification
	
	X,Y = make_classification(n_samples, n_features)
	#pp = PolynomialFeatures(degree=3)
	
	#X = pp.fit_transform(X)
	m = LinearSVC()
	m.fit(X,Y) 
開發者ID:sfalkner,項目名稱:pynisher,代碼行數:13,代碼來源:unit_tests.py


注:本文中的sklearn.preprocessing方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。