zoukankan      html  css  js  c++  java
  • 莫烦python教程学习笔记——数据预处理之normalization

    # View more python learning tutorial on my Youtube and Youku channel!!!
    
    # Youtube video tutorial: https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg
    # Youku video tutorial: http://i.youku.com/pythontutorial
    
    """
    Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
    """
    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))
    
    #对sklearn自动生成的数据集对其进行归一化,绘制散点图 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 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))
  • 相关阅读:
    常用的一些js方法
    git常用命令
    thread join和detach的区别
    C和C++的区别和联系
    C++面试集锦( 面试被问到的问题 )
    C/C++面试题:编写类String的构造函数、析构函数和赋值函数。
    C++ 多态的实现及原理
    获取当前操作系统的ip
    CString的头文件
    C++ 多用户模式下同一个exe只能运行一次
  • 原文地址:https://www.cnblogs.com/simpleDi/p/9964127.html
Copyright © 2011-2022 走看看