• 12.scikit-learn中的Scaler


    import numpy as np
    from sklearn import datasets
    
    iris = datasets.load_iris()
    
    X = iris.data
    y = iris.target
    
    X[:10,:]
    array([[5.1, 3.5, 1.4, 0.2],
           [4.9, 3. , 1.4, 0.2],
           [4.7, 3.2, 1.3, 0.2],
           [4.6, 3.1, 1.5, 0.2],
           [5. , 3.6, 1.4, 0.2],
           [5.4, 3.9, 1.7, 0.4],
           [4.6, 3.4, 1.4, 0.3],
           [5. , 3.4, 1.5, 0.2],
           [4.4, 2.9, 1.4, 0.2],
           [4.9, 3.1, 1.5, 0.1]])
    from sklearn.model_selection import train_test_split
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=666)
    from sklearn.preprocessing import StandardScaler
    standardscaler = StandardScaler()
    standardscaler.fit(X_train)
    StandardScaler(copy=True, with_mean=True, with_std=True)
    standardscaler.mean_
    array([5.83416667, 3.08666667, 3.70833333, 1.17      ])
    standardscaler.scale_
    array([0.81019502, 0.44327067, 1.76401924, 0.75317107])
    X_train = standardscaler.transform(X_train)
    X_test_standard  = standardscaler.transform(X_test)
    
    from sklearn.neighbors import KNeighborsClassifier
    knn_clf = KNeighborsClassifier(n_neighbors=3)
    knn_clf.fit(X_train, y_train)
    
    knn_clf.score(X_test_standard, y_test)
  • 相关阅读:
    阿里代码检查工具
    SpringCloud 服务通信方法
    Apache ab简单使用
    H5 webSocket使用
    Java list去重 取重
    解决 spring boot Failed to decode downloaded font
    Pycharm设置快捷方式
    环境变量与文件的查找
    Linux基础
    VIM中文乱码解决
  • 原文地址:https://www.cnblogs.com/waterr/p/14039303.html
Copyright © 2020-2023  润新知