zoukankan      html  css  js  c++  java
  • sklearn 标准化数据的方法

    Sklearn

    标准化数据

    from __future__ import print_function
    from sklearn import preprocessing
    import numpy as np
    from sklearn.model_selection import train_test_split
    from sklearn.datasets.samples_generator import make_classification
    from sklearn.svm import SVC
    import matplotlib.pyplot as plt
    #每一列是一个属性
    a = np.array([[10, 2.7, 3.6],
                         [-100, 5, -2],
                         [120, 20, 40]], dtype=np.float64)
            
    print(a)
    #归一化
    print(preprocessing.scale(a))
    # 生成一堆数据 有两个属性 有两个相关属性
    X, y = make_classification(n_samples=300, n_features=2 , n_redundant=0, n_informative=2,
                               random_state=22, n_clusters_per_class=1, scale=100)
    plt.scatter(X[:, 0], X[:, 1], c=y)
    plt.show()
    X = preprocessing.scale(X)    # normalization step
    #minmax_scale(X,feature_range=(-1,1))
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.3)
    clf = SVC()
    clf.fit(X_train, y_train)
    print(clf.score(X_test, y_test))
    
  • 相关阅读:
    装饰者模式
    使用dom4j工具:读取xml(一)
    关于设计模式
    简单工厂模式
    Html 笔记
    数据库SQL归纳(三)
    windows上同时安装两个版本的mysql数据库
    MySQL的使用
    数据库SQL归纳(二)
    数据库SQL归纳(一)
  • 原文地址:https://www.cnblogs.com/Tony100K/p/10058366.html
Copyright © 2011-2022 走看看