深入浅出python机器学习_7.1_支持向量机

系统 574 0
            
              
                %
              
              matplotlib inline


              
                # 支持向量机SVM的核函数
              
              
                import
              
               numpy 
              
                as
              
               np


              
                import
              
               matplotlib
              
                .
              
              pyplot 
              
                as
              
               plt


              
                from
              
               sklearn 
              
                import
              
               svm


              
                from
              
               sklearn
              
                .
              
              datasets 
              
                import
              
               make_blobs

X
              
                ,
              
              y
              
                =
              
              make_blobs
              
                (
              
              n_samples
              
                =
              
              
                50
              
              
                ,
              
              centers
              
                =
              
              
                2
              
              
                ,
              
              random_state
              
                =
              
              
                6
              
              
                )
              
              
                print
              
              
                (
              
              
                'X:\n'
              
              
                ,
              
              X
              
                ,
              
              
                '\n'
              
              
                )
              
              
                print
              
              
                (
              
              
                'y:\n'
              
              
                ,
              
              y
              
                ,
              
              
                '\n'
              
              
                )
              
            
          
            
              X:
 [[  6.45519089  -9.46356669]
 [  8.49142837  -2.54974889]
 [  6.87151089 -10.18071547]
 [  9.49649411  -3.7902975 ]
 [  7.67619643  -2.82620437]
 [  6.3883927   -9.25691447]
 [  9.24223825  -3.88003098]
 [  5.95313618  -6.82945967]
 [  6.86866543 -10.02289012]
 [  7.52132141  -2.12266605]
 [  7.29573215  -4.39392379]
 [  6.85086785  -9.92422452]
 [  4.29225906  -8.99220442]
 [  8.21597398  -2.28672255]
 [  7.9683312   -3.23125265]
 [  8.68185687  -4.53683537]
 [  6.77811308  -9.80940478]
 [  7.93333064  -3.51553205]
 [  7.73046665  -4.72901672]
 [  7.37578372  -8.7241701 ]
 [  6.95292352  -8.22624269]
 [  8.07502382  -4.25949569]
 [  7.39169472  -3.1266933 ]
 [  6.59823581 -10.20150177]
 [  7.27059007  -4.84225716]
 [  8.71445065  -2.41730491]
 [  5.73005848  -4.19481136]
 [  9.42169269  -2.6476988 ]
 [  6.26221548  -8.43925752]
 [  7.89359985  -7.41655113]
 [  8.98426675  -4.87449712]
 [ 10.48848359  -2.75858164]
 [  5.45644482  -8.99900075]
 [  6.50072722  -3.82403586]
 [  7.07705089  -2.4047943 ]
 [  9.07568367  -4.21790533]
 [  7.92736799  -9.7615272 ]
 [  7.29885085  -9.90563956]
 [  6.6008728   -8.07144707]
 [  5.94709536  -9.05353781]
 [  5.88397542  -8.37284513]
 [  5.37042238  -2.44715237]
 [  8.21201164  -1.54781358]
 [  6.40500112  -7.50322463]
 [  6.94752781  -9.75794397]
 [  6.04907774  -8.76969991]
 [  8.32932478  -8.47191434]
 [  6.37734541 -10.61510727]
 [  4.29810787  -8.41461865]
 [  7.97164446  -3.38236058]] 

y:
 [1 0 1 0 0 1 0 1 1 0 0 1 1 0 0 0 1 0 0 1 1 0 0 1 0 0 0 0 1 1 0 0 1 0 0 0 1
 1 1 1 1 0 0 1 1 1 1 1 1 0] 

            
          
            
              clf
              
                =
              
              svm
              
                .
              
              SVC
              
                (
              
              kernel
              
                =
              
              
                'linear'
              
              
                ,
              
              C
              
                =
              
              
                1000
              
              
                )
              
              

clf
              
                .
              
              fit
              
                (
              
              X
              
                ,
              
              y
              
                )
              
              

plt
              
                .
              
              scatter
              
                (
              
              X
              
                [
              
              
                :
              
              
                ,
              
              
                0
              
              
                ]
              
              
                ,
              
              X
              
                [
              
              
                :
              
              
                ,
              
              
                1
              
              
                ]
              
              
                ,
              
              c
              
                =
              
              y
              
                ,
              
              s
              
                =
              
              
                30
              
              
                ,
              
              cmap
              
                =
              
              plt
              
                .
              
              cm
              
                .
              
              Paired
              
                )
              
            
          
            
              
              
            
          

深入浅出python机器学习_7.1_支持向量机_第1张图片

            
              ax
              
                =
              
              plt
              
                .
              
              gca
              
                (
              
              
                )
              
              
                print
              
              
                (
              
              
                '打印ax:\n'
              
              
                ,
              
              ax
              
                ,
              
              
                '\n'
              
              
                )
              
              
                print
              
              
                (
              
              
                'ax的类型:\n'
              
              
                ,
              
              
                type
              
              
                (
              
              ax
              
                )
              
              
                ,
              
              
                '\n'
              
              
                )
              
              

xlim
              
                =
              
              ax
              
                .
              
              get_xlim
              
                (
              
              
                )
              
              
                print
              
              
                (
              
              
                'xlim:\n'
              
              
                ,
              
              xlim
              
                ,
              
              
                '\n'
              
              
                )
              
              
                print
              
              
                (
              
              
                'xlim的类型:\n'
              
              
                ,
              
              
                type
              
              
                (
              
              xlim
              
                )
              
              
                ,
              
              
                '\n'
              
              
                )
              
              

ylim
              
                =
              
              ax
              
                .
              
              get_ylim
              
                (
              
              
                )
              
              
                print
              
              
                (
              
              
                'ylim:\n'
              
              
                ,
              
              ylim
              
                ,
              
              
                '\n'
              
              
                )
              
            
          
            
              打印ax:
 AxesSubplot(0.125,0.125;0.775x0.755) 

ax的类型:
 
              
                 

xlim:
 (0.0, 1.0) 

xlim的类型:
 
                
                   

ylim:
 (0.0, 1.0) 

                
              
            
          

深入浅出python机器学习_7.1_支持向量机_第2张图片

            
              xx
              
                =
              
              np
              
                .
              
              linspace
              
                (
              
              xlim
              
                [
              
              
                0
              
              
                ]
              
              
                ,
              
              xlim
              
                [
              
              
                1
              
              
                ]
              
              
                ,
              
              
                30
              
              
                )
              
              

yy
              
                =
              
              np
              
                .
              
              linspace
              
                (
              
              ylim
              
                [
              
              
                0
              
              
                ]
              
              
                ,
              
              ylim
              
                [
              
              
                1
              
              
                ]
              
              
                ,
              
              
                30
              
              
                )
              
              
                print
              
              
                (
              
              
                '打印xx:\n'
              
              
                ,
              
              xx
              
                ,
              
              
                '\n'
              
              
                )
              
              
                print
              
              
                (
              
              
                'xx的类型:\n'
              
              
                ,
              
              
                type
              
              
                (
              
              xx
              
                )
              
              
                ,
              
              
                '\n'
              
              
                )
              
              

xx_
              
                =
              
              np
              
                .
              
              arange
              
                (
              
              xlim
              
                [
              
              
                0
              
              
                ]
              
              
                ,
              
              xlim
              
                [
              
              
                1
              
              
                ]
              
              
                ,
              
              
                0.1
              
              
                )
              
              
                print
              
              
                (
              
              
                '打印xx_:\n'
              
              
                ,
              
              xx_
              
                ,
              
              
                '\n'
              
              
                )
              
              
                print
              
              
                (
              
              
                '打印xx.shape'
              
              
                ,
              
              xx
              
                .
              
              shape
              
                ,
              
              
                '\n'
              
              
                )
              
              
                print
              
              
                (
              
              
                'xx_的类型:\n'
              
              
                ,
              
              
                type
              
              
                (
              
              xx_
              
                )
              
              
                ,
              
              
                '\n'
              
              
                )
              
              

YY
              
                ,
              
              XX
              
                =
              
              np
              
                .
              
              meshgrid
              
                (
              
              yy
              
                ,
              
              xx
              
                )
              
              
                print
              
              
                (
              
              
                '打印XX:\n'
              
              
                ,
              
              XX
              
                ,
              
              
                '\n'
              
              
                )
              
              

xy
              
                =
              
              np
              
                .
              
              vstack
              
                (
              
              
                [
              
              XX
              
                .
              
              ravel
              
                (
              
              
                )
              
              
                ,
              
              YY
              
                .
              
              ravel
              
                (
              
              
                )
              
              
                ]
              
              
                )
              
              
                .
              
              T


              
                print
              
              
                (
              
              
                '打印XX.ravel():\n'
              
              
                ,
              
              XX
              
                .
              
              ravel
              
                (
              
              
                )
              
              
                ,
              
              
                '\n'
              
              
                )
              
              
                print
              
              
                (
              
              
                '打印np.vstack([XX.ravel(),YY.ravel()])\n'
              
              
                ,
              
              np
              
                .
              
              vstack
              
                (
              
              
                [
              
              XX
              
                .
              
              ravel
              
                (
              
              
                )
              
              
                ,
              
              YY
              
                .
              
              ravel
              
                (
              
              
                )
              
              
                ]
              
              
                )
              
              
                ,
              
              
                '\n'
              
              
                )
              
              
                print
              
              
                (
              
              
                '打印xy:\n'
              
              
                ,
              
              xy
              
                ,
              
              
                '\n'
              
              
                )
              
              

Z
              
                =
              
              clf
              
                .
              
              decision_function
              
                (
              
              xy
              
                )
              
              
                .
              
              reshape
              
                (
              
              XX
              
                .
              
              shape
              
                )
              
            
          
            
              打印xx:
 [0.         0.03448276 0.06896552 0.10344828 0.13793103 0.17241379
 0.20689655 0.24137931 0.27586207 0.31034483 0.34482759 0.37931034
 0.4137931  0.44827586 0.48275862 0.51724138 0.55172414 0.5862069
 0.62068966 0.65517241 0.68965517 0.72413793 0.75862069 0.79310345
 0.82758621 0.86206897 0.89655172 0.93103448 0.96551724 1.        ] 

xx的类型:
 
              
                 

打印xx_:
 [0.  0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9] 

打印xx.shape (30,) 

xx_的类型:
 
                
                   

打印XX:
 [[0.         0.         0.         0.         0.         0.
  0.         0.         0.         0.         0.         0.
  0.         0.         0.         0.         0.         0.
  0.         0.         0.         0.         0.         0.
  0.         0.         0.         0.         0.         0.        ]
 [0.03448276 0.03448276 0.03448276 0.03448276 0.03448276 0.03448276
  0.03448276 0.03448276 0.03448276 0.03448276 0.03448276 0.03448276
  0.03448276 0.03448276 0.03448276 0.03448276 0.03448276 0.03448276
  0.03448276 0.03448276 0.03448276 0.03448276 0.03448276 0.03448276
  0.03448276 0.03448276 0.03448276 0.03448276 0.03448276 0.03448276]
 [0.06896552 0.06896552 0.06896552 0.06896552 0.06896552 0.06896552
  0.06896552 0.06896552 0.06896552 0.06896552 0.06896552 0.06896552
  0.06896552 0.06896552 0.06896552 0.06896552 0.06896552 0.06896552
  0.06896552 0.06896552 0.06896552 0.06896552 0.06896552 0.06896552
  0.06896552 0.06896552 0.06896552 0.06896552 0.06896552 0.06896552]
 [0.10344828 0.10344828 0.10344828 0.10344828 0.10344828 0.10344828
  0.10344828 0.10344828 0.10344828 0.10344828 0.10344828 0.10344828
  0.10344828 0.10344828 0.10344828 0.10344828 0.10344828 0.10344828
  0.10344828 0.10344828 0.10344828 0.10344828 0.10344828 0.10344828
  0.10344828 0.10344828 0.10344828 0.10344828 0.10344828 0.10344828]
 [0.13793103 0.13793103 0.13793103 0.13793103 0.13793103 0.13793103
  0.13793103 0.13793103 0.13793103 0.13793103 0.13793103 0.13793103
  0.13793103 0.13793103 0.13793103 0.13793103 0.13793103 0.13793103
  0.13793103 0.13793103 0.13793103 0.13793103 0.13793103 0.13793103
  0.13793103 0.13793103 0.13793103 0.13793103 0.13793103 0.13793103]
 [0.17241379 0.17241379 0.17241379 0.17241379 0.17241379 0.17241379
  0.17241379 0.17241379 0.17241379 0.17241379 0.17241379 0.17241379
  0.17241379 0.17241379 0.17241379 0.17241379 0.17241379 0.17241379
  0.17241379 0.17241379 0.17241379 0.17241379 0.17241379 0.17241379
  0.17241379 0.17241379 0.17241379 0.17241379 0.17241379 0.17241379]
 [0.20689655 0.20689655 0.20689655 0.20689655 0.20689655 0.20689655
  0.20689655 0.20689655 0.20689655 0.20689655 0.20689655 0.20689655
  0.20689655 0.20689655 0.20689655 0.20689655 0.20689655 0.20689655
  0.20689655 0.20689655 0.20689655 0.20689655 0.20689655 0.20689655
  0.20689655 0.20689655 0.20689655 0.20689655 0.20689655 0.20689655]
 [0.24137931 0.24137931 0.24137931 0.24137931 0.24137931 0.24137931
  0.24137931 0.24137931 0.24137931 0.24137931 0.24137931 0.24137931
  0.24137931 0.24137931 0.24137931 0.24137931 0.24137931 0.24137931
  0.24137931 0.24137931 0.24137931 0.24137931 0.24137931 0.24137931
  0.24137931 0.24137931 0.24137931 0.24137931 0.24137931 0.24137931]
 [0.27586207 0.27586207 0.27586207 0.27586207 0.27586207 0.27586207
  0.27586207 0.27586207 0.27586207 0.27586207 0.27586207 0.27586207
  0.27586207 0.27586207 0.27586207 0.27586207 0.27586207 0.27586207
  0.27586207 0.27586207 0.27586207 0.27586207 0.27586207 0.27586207
  0.27586207 0.27586207 0.27586207 0.27586207 0.27586207 0.27586207]
 [0.31034483 0.31034483 0.31034483 0.31034483 0.31034483 0.31034483
  0.31034483 0.31034483 0.31034483 0.31034483 0.31034483 0.31034483
  0.31034483 0.31034483 0.31034483 0.31034483 0.31034483 0.31034483
  0.31034483 0.31034483 0.31034483 0.31034483 0.31034483 0.31034483
  0.31034483 0.31034483 0.31034483 0.31034483 0.31034483 0.31034483]
 [0.34482759 0.34482759 0.34482759 0.34482759 0.34482759 0.34482759
  0.34482759 0.34482759 0.34482759 0.34482759 0.34482759 0.34482759
  0.34482759 0.34482759 0.34482759 0.34482759 0.34482759 0.34482759
  0.34482759 0.34482759 0.34482759 0.34482759 0.34482759 0.34482759
  0.34482759 0.34482759 0.34482759 0.34482759 0.34482759 0.34482759]
 [0.37931034 0.37931034 0.37931034 0.37931034 0.37931034 0.37931034
  0.37931034 0.37931034 0.37931034 0.37931034 0.37931034 0.37931034
  0.37931034 0.37931034 0.37931034 0.37931034 0.37931034 0.37931034
  0.37931034 0.37931034 0.37931034 0.37931034 0.37931034 0.37931034
  0.37931034 0.37931034 0.37931034 0.37931034 0.37931034 0.37931034]
 [0.4137931  0.4137931  0.4137931  0.4137931  0.4137931  0.4137931
  0.4137931  0.4137931  0.4137931  0.4137931  0.4137931  0.4137931
  0.4137931  0.4137931  0.4137931  0.4137931  0.4137931  0.4137931
  0.4137931  0.4137931  0.4137931  0.4137931  0.4137931  0.4137931
  0.4137931  0.4137931  0.4137931  0.4137931  0.4137931  0.4137931 ]
 [0.44827586 0.44827586 0.44827586 0.44827586 0.44827586 0.44827586
  0.44827586 0.44827586 0.44827586 0.44827586 0.44827586 0.44827586
  0.44827586 0.44827586 0.44827586 0.44827586 0.44827586 0.44827586
  0.44827586 0.44827586 0.44827586 0.44827586 0.44827586 0.44827586
  0.44827586 0.44827586 0.44827586 0.44827586 0.44827586 0.44827586]
 [0.48275862 0.48275862 0.48275862 0.48275862 0.48275862 0.48275862
  0.48275862 0.48275862 0.48275862 0.48275862 0.48275862 0.48275862
  0.48275862 0.48275862 0.48275862 0.48275862 0.48275862 0.48275862
  0.48275862 0.48275862 0.48275862 0.48275862 0.48275862 0.48275862
  0.48275862 0.48275862 0.48275862 0.48275862 0.48275862 0.48275862]
 [0.51724138 0.51724138 0.51724138 0.51724138 0.51724138 0.51724138
  0.51724138 0.51724138 0.51724138 0.51724138 0.51724138 0.51724138
  0.51724138 0.51724138 0.51724138 0.51724138 0.51724138 0.51724138
  0.51724138 0.51724138 0.51724138 0.51724138 0.51724138 0.51724138
  0.51724138 0.51724138 0.51724138 0.51724138 0.51724138 0.51724138]
 [0.55172414 0.55172414 0.55172414 0.55172414 0.55172414 0.55172414
  0.55172414 0.55172414 0.55172414 0.55172414 0.55172414 0.55172414
  0.55172414 0.55172414 0.55172414 0.55172414 0.55172414 0.55172414
  0.55172414 0.55172414 0.55172414 0.55172414 0.55172414 0.55172414
  0.55172414 0.55172414 0.55172414 0.55172414 0.55172414 0.55172414]
 [0.5862069  0.5862069  0.5862069  0.5862069  0.5862069  0.5862069
  0.5862069  0.5862069  0.5862069  0.5862069  0.5862069  0.5862069
  0.5862069  0.5862069  0.5862069  0.5862069  0.5862069  0.5862069
  0.5862069  0.5862069  0.5862069  0.5862069  0.5862069  0.5862069
  0.5862069  0.5862069  0.5862069  0.5862069  0.5862069  0.5862069 ]
 [0.62068966 0.62068966 0.62068966 0.62068966 0.62068966 0.62068966
  0.62068966 0.62068966 0.62068966 0.62068966 0.62068966 0.62068966
  0.62068966 0.62068966 0.62068966 0.62068966 0.62068966 0.62068966
  0.62068966 0.62068966 0.62068966 0.62068966 0.62068966 0.62068966
  0.62068966 0.62068966 0.62068966 0.62068966 0.62068966 0.62068966]
 [0.65517241 0.65517241 0.65517241 0.65517241 0.65517241 0.65517241
  0.65517241 0.65517241 0.65517241 0.65517241 0.65517241 0.65517241
  0.65517241 0.65517241 0.65517241 0.65517241 0.65517241 0.65517241
  0.65517241 0.65517241 0.65517241 0.65517241 0.65517241 0.65517241
  0.65517241 0.65517241 0.65517241 0.65517241 0.65517241 0.65517241]
 [0.68965517 0.68965517 0.68965517 0.68965517 0.68965517 0.68965517
  0.68965517 0.68965517 0.68965517 0.68965517 0.68965517 0.68965517
  0.68965517 0.68965517 0.68965517 0.68965517 0.68965517 0.68965517
  0.68965517 0.68965517 0.68965517 0.68965517 0.68965517 0.68965517
  0.68965517 0.68965517 0.68965517 0.68965517 0.68965517 0.68965517]
 [0.72413793 0.72413793 0.72413793 0.72413793 0.72413793 0.72413793
  0.72413793 0.72413793 0.72413793 0.72413793 0.72413793 0.72413793
  0.72413793 0.72413793 0.72413793 0.72413793 0.72413793 0.72413793
  0.72413793 0.72413793 0.72413793 0.72413793 0.72413793 0.72413793
  0.72413793 0.72413793 0.72413793 0.72413793 0.72413793 0.72413793]
 [0.75862069 0.75862069 0.75862069 0.75862069 0.75862069 0.75862069
  0.75862069 0.75862069 0.75862069 0.75862069 0.75862069 0.75862069
  0.75862069 0.75862069 0.75862069 0.75862069 0.75862069 0.75862069
  0.75862069 0.75862069 0.75862069 0.75862069 0.75862069 0.75862069
  0.75862069 0.75862069 0.75862069 0.75862069 0.75862069 0.75862069]
 [0.79310345 0.79310345 0.79310345 0.79310345 0.79310345 0.79310345
  0.79310345 0.79310345 0.79310345 0.79310345 0.79310345 0.79310345
  0.79310345 0.79310345 0.79310345 0.79310345 0.79310345 0.79310345
  0.79310345 0.79310345 0.79310345 0.79310345 0.79310345 0.79310345
  0.79310345 0.79310345 0.79310345 0.79310345 0.79310345 0.79310345]
 [0.82758621 0.82758621 0.82758621 0.82758621 0.82758621 0.82758621
  0.82758621 0.82758621 0.82758621 0.82758621 0.82758621 0.82758621
  0.82758621 0.82758621 0.82758621 0.82758621 0.82758621 0.82758621
  0.82758621 0.82758621 0.82758621 0.82758621 0.82758621 0.82758621
  0.82758621 0.82758621 0.82758621 0.82758621 0.82758621 0.82758621]
 [0.86206897 0.86206897 0.86206897 0.86206897 0.86206897 0.86206897
  0.86206897 0.86206897 0.86206897 0.86206897 0.86206897 0.86206897
  0.86206897 0.86206897 0.86206897 0.86206897 0.86206897 0.86206897
  0.86206897 0.86206897 0.86206897 0.86206897 0.86206897 0.86206897
  0.86206897 0.86206897 0.86206897 0.86206897 0.86206897 0.86206897]
 [0.89655172 0.89655172 0.89655172 0.89655172 0.89655172 0.89655172
  0.89655172 0.89655172 0.89655172 0.89655172 0.89655172 0.89655172
  0.89655172 0.89655172 0.89655172 0.89655172 0.89655172 0.89655172
  0.89655172 0.89655172 0.89655172 0.89655172 0.89655172 0.89655172
  0.89655172 0.89655172 0.89655172 0.89655172 0.89655172 0.89655172]
 [0.93103448 0.93103448 0.93103448 0.93103448 0.93103448 0.93103448
  0.93103448 0.93103448 0.93103448 0.93103448 0.93103448 0.93103448
  0.93103448 0.93103448 0.93103448 0.93103448 0.93103448 0.93103448
  0.93103448 0.93103448 0.93103448 0.93103448 0.93103448 0.93103448
  0.93103448 0.93103448 0.93103448 0.93103448 0.93103448 0.93103448]
 [0.96551724 0.96551724 0.96551724 0.96551724 0.96551724 0.96551724
  0.96551724 0.96551724 0.96551724 0.96551724 0.96551724 0.96551724
  0.96551724 0.96551724 0.96551724 0.96551724 0.96551724 0.96551724
  0.96551724 0.96551724 0.96551724 0.96551724 0.96551724 0.96551724
  0.96551724 0.96551724 0.96551724 0.96551724 0.96551724 0.96551724]
 [1.         1.         1.         1.         1.         1.
  1.         1.         1.         1.         1.         1.
  1.         1.         1.         1.         1.         1.
  1.         1.         1.         1.         1.         1.
  1.         1.         1.         1.         1.         1.        ]] 

打印XX.ravel():
 [0.         0.         0.         0.         0.         0.
 0.         0.         0.         0.         0.         0.
 0.         0.         0.         0.         0.         0.
 0.         0.         0.         0.         0.         0.
 0.         0.         0.         0.         0.         0.
 0.03448276 0.03448276 0.03448276 0.03448276 0.03448276 0.03448276
 0.03448276 0.03448276 0.03448276 0.03448276 0.03448276 0.03448276
 0.03448276 0.03448276 0.03448276 0.03448276 0.03448276 0.03448276
 0.03448276 0.03448276 0.03448276 0.03448276 0.03448276 0.03448276
 0.03448276 0.03448276 0.03448276 0.03448276 0.03448276 0.03448276
 0.06896552 0.06896552 0.06896552 0.06896552 0.06896552 0.06896552
 0.06896552 0.06896552 0.06896552 0.06896552 0.06896552 0.06896552
 0.06896552 0.06896552 0.06896552 0.06896552 0.06896552 0.06896552
 0.06896552 0.06896552 0.06896552 0.06896552 0.06896552 0.06896552
 0.06896552 0.06896552 0.06896552 0.06896552 0.06896552 0.06896552
 0.10344828 0.10344828 0.10344828 0.10344828 0.10344828 0.10344828
 0.10344828 0.10344828 0.10344828 0.10344828 0.10344828 0.10344828
 0.10344828 0.10344828 0.10344828 0.10344828 0.10344828 0.10344828
 0.10344828 0.10344828 0.10344828 0.10344828 0.10344828 0.10344828
 0.10344828 0.10344828 0.10344828 0.10344828 0.10344828 0.10344828
 0.13793103 0.13793103 0.13793103 0.13793103 0.13793103 0.13793103
 0.13793103 0.13793103 0.13793103 0.13793103 0.13793103 0.13793103
 0.13793103 0.13793103 0.13793103 0.13793103 0.13793103 0.13793103
 0.13793103 0.13793103 0.13793103 0.13793103 0.13793103 0.13793103
 0.13793103 0.13793103 0.13793103 0.13793103 0.13793103 0.13793103
 0.17241379 0.17241379 0.17241379 0.17241379 0.17241379 0.17241379
 0.17241379 0.17241379 0.17241379 0.17241379 0.17241379 0.17241379
 0.17241379 0.17241379 0.17241379 0.17241379 0.17241379 0.17241379
 0.17241379 0.17241379 0.17241379 0.17241379 0.17241379 0.17241379
 0.17241379 0.17241379 0.17241379 0.17241379 0.17241379 0.17241379
 0.20689655 0.20689655 0.20689655 0.20689655 0.20689655 0.20689655
 0.20689655 0.20689655 0.20689655 0.20689655 0.20689655 0.20689655
 0.20689655 0.20689655 0.20689655 0.20689655 0.20689655 0.20689655
 0.20689655 0.20689655 0.20689655 0.20689655 0.20689655 0.20689655
 0.20689655 0.20689655 0.20689655 0.20689655 0.20689655 0.20689655
 0.24137931 0.24137931 0.24137931 0.24137931 0.24137931 0.24137931
 0.24137931 0.24137931 0.24137931 0.24137931 0.24137931 0.24137931
 0.24137931 0.24137931 0.24137931 0.24137931 0.24137931 0.24137931
 0.24137931 0.24137931 0.24137931 0.24137931 0.24137931 0.24137931
 0.24137931 0.24137931 0.24137931 0.24137931 0.24137931 0.24137931
 0.27586207 0.27586207 0.27586207 0.27586207 0.27586207 0.27586207
 0.27586207 0.27586207 0.27586207 0.27586207 0.27586207 0.27586207
 0.27586207 0.27586207 0.27586207 0.27586207 0.27586207 0.27586207
 0.27586207 0.27586207 0.27586207 0.27586207 0.27586207 0.27586207
 0.27586207 0.27586207 0.27586207 0.27586207 0.27586207 0.27586207
 0.31034483 0.31034483 0.31034483 0.31034483 0.31034483 0.31034483
 0.31034483 0.31034483 0.31034483 0.31034483 0.31034483 0.31034483
 0.31034483 0.31034483 0.31034483 0.31034483 0.31034483 0.31034483
 0.31034483 0.31034483 0.31034483 0.31034483 0.31034483 0.31034483
 0.31034483 0.31034483 0.31034483 0.31034483 0.31034483 0.31034483
 0.34482759 0.34482759 0.34482759 0.34482759 0.34482759 0.34482759
 0.34482759 0.34482759 0.34482759 0.34482759 0.34482759 0.34482759
 0.34482759 0.34482759 0.34482759 0.34482759 0.34482759 0.34482759
 0.34482759 0.34482759 0.34482759 0.34482759 0.34482759 0.34482759
 0.34482759 0.34482759 0.34482759 0.34482759 0.34482759 0.34482759
 0.37931034 0.37931034 0.37931034 0.37931034 0.37931034 0.37931034
 0.37931034 0.37931034 0.37931034 0.37931034 0.37931034 0.37931034
 0.37931034 0.37931034 0.37931034 0.37931034 0.37931034 0.37931034
 0.37931034 0.37931034 0.37931034 0.37931034 0.37931034 0.37931034
 0.37931034 0.37931034 0.37931034 0.37931034 0.37931034 0.37931034
 0.4137931  0.4137931  0.4137931  0.4137931  0.4137931  0.4137931
 0.4137931  0.4137931  0.4137931  0.4137931  0.4137931  0.4137931
 0.4137931  0.4137931  0.4137931  0.4137931  0.4137931  0.4137931
 0.4137931  0.4137931  0.4137931  0.4137931  0.4137931  0.4137931
 0.4137931  0.4137931  0.4137931  0.4137931  0.4137931  0.4137931
 0.44827586 0.44827586 0.44827586 0.44827586 0.44827586 0.44827586
 0.44827586 0.44827586 0.44827586 0.44827586 0.44827586 0.44827586
 0.44827586 0.44827586 0.44827586 0.44827586 0.44827586 0.44827586
 0.44827586 0.44827586 0.44827586 0.44827586 0.44827586 0.44827586
 0.44827586 0.44827586 0.44827586 0.44827586 0.44827586 0.44827586
 0.48275862 0.48275862 0.48275862 0.48275862 0.48275862 0.48275862
 0.48275862 0.48275862 0.48275862 0.48275862 0.48275862 0.48275862
 0.48275862 0.48275862 0.48275862 0.48275862 0.48275862 0.48275862
 0.48275862 0.48275862 0.48275862 0.48275862 0.48275862 0.48275862
 0.48275862 0.48275862 0.48275862 0.48275862 0.48275862 0.48275862
 0.51724138 0.51724138 0.51724138 0.51724138 0.51724138 0.51724138
 0.51724138 0.51724138 0.51724138 0.51724138 0.51724138 0.51724138
 0.51724138 0.51724138 0.51724138 0.51724138 0.51724138 0.51724138
 0.51724138 0.51724138 0.51724138 0.51724138 0.51724138 0.51724138
 0.51724138 0.51724138 0.51724138 0.51724138 0.51724138 0.51724138
 0.55172414 0.55172414 0.55172414 0.55172414 0.55172414 0.55172414
 0.55172414 0.55172414 0.55172414 0.55172414 0.55172414 0.55172414
 0.55172414 0.55172414 0.55172414 0.55172414 0.55172414 0.55172414
 0.55172414 0.55172414 0.55172414 0.55172414 0.55172414 0.55172414
 0.55172414 0.55172414 0.55172414 0.55172414 0.55172414 0.55172414
 0.5862069  0.5862069  0.5862069  0.5862069  0.5862069  0.5862069
 0.5862069  0.5862069  0.5862069  0.5862069  0.5862069  0.5862069
 0.5862069  0.5862069  0.5862069  0.5862069  0.5862069  0.5862069
 0.5862069  0.5862069  0.5862069  0.5862069  0.5862069  0.5862069
 0.5862069  0.5862069  0.5862069  0.5862069  0.5862069  0.5862069
 0.62068966 0.62068966 0.62068966 0.62068966 0.62068966 0.62068966
 0.62068966 0.62068966 0.62068966 0.62068966 0.62068966 0.62068966
 0.62068966 0.62068966 0.62068966 0.62068966 0.62068966 0.62068966
 0.62068966 0.62068966 0.62068966 0.62068966 0.62068966 0.62068966
 0.62068966 0.62068966 0.62068966 0.62068966 0.62068966 0.62068966
 0.65517241 0.65517241 0.65517241 0.65517241 0.65517241 0.65517241
 0.65517241 0.65517241 0.65517241 0.65517241 0.65517241 0.65517241
 0.65517241 0.65517241 0.65517241 0.65517241 0.65517241 0.65517241
 0.65517241 0.65517241 0.65517241 0.65517241 0.65517241 0.65517241
 0.65517241 0.65517241 0.65517241 0.65517241 0.65517241 0.65517241
 0.68965517 0.68965517 0.68965517 0.68965517 0.68965517 0.68965517
 0.68965517 0.68965517 0.68965517 0.68965517 0.68965517 0.68965517
 0.68965517 0.68965517 0.68965517 0.68965517 0.68965517 0.68965517
 0.68965517 0.68965517 0.68965517 0.68965517 0.68965517 0.68965517
 0.68965517 0.68965517 0.68965517 0.68965517 0.68965517 0.68965517
 0.72413793 0.72413793 0.72413793 0.72413793 0.72413793 0.72413793
 0.72413793 0.72413793 0.72413793 0.72413793 0.72413793 0.72413793
 0.72413793 0.72413793 0.72413793 0.72413793 0.72413793 0.72413793
 0.72413793 0.72413793 0.72413793 0.72413793 0.72413793 0.72413793
 0.72413793 0.72413793 0.72413793 0.72413793 0.72413793 0.72413793
 0.75862069 0.75862069 0.75862069 0.75862069 0.75862069 0.75862069
 0.75862069 0.75862069 0.75862069 0.75862069 0.75862069 0.75862069
 0.75862069 0.75862069 0.75862069 0.75862069 0.75862069 0.75862069
 0.75862069 0.75862069 0.75862069 0.75862069 0.75862069 0.75862069
 0.75862069 0.75862069 0.75862069 0.75862069 0.75862069 0.75862069
 0.79310345 0.79310345 0.79310345 0.79310345 0.79310345 0.79310345
 0.79310345 0.79310345 0.79310345 0.79310345 0.79310345 0.79310345
 0.79310345 0.79310345 0.79310345 0.79310345 0.79310345 0.79310345
 0.79310345 0.79310345 0.79310345 0.79310345 0.79310345 0.79310345
 0.79310345 0.79310345 0.79310345 0.79310345 0.79310345 0.79310345
 0.82758621 0.82758621 0.82758621 0.82758621 0.82758621 0.82758621
 0.82758621 0.82758621 0.82758621 0.82758621 0.82758621 0.82758621
 0.82758621 0.82758621 0.82758621 0.82758621 0.82758621 0.82758621
 0.82758621 0.82758621 0.82758621 0.82758621 0.82758621 0.82758621
 0.82758621 0.82758621 0.82758621 0.82758621 0.82758621 0.82758621
 0.86206897 0.86206897 0.86206897 0.86206897 0.86206897 0.86206897
 0.86206897 0.86206897 0.86206897 0.86206897 0.86206897 0.86206897
 0.86206897 0.86206897 0.86206897 0.86206897 0.86206897 0.86206897
 0.86206897 0.86206897 0.86206897 0.86206897 0.86206897 0.86206897
 0.86206897 0.86206897 0.86206897 0.86206897 0.86206897 0.86206897
 0.89655172 0.89655172 0.89655172 0.89655172 0.89655172 0.89655172
 0.89655172 0.89655172 0.89655172 0.89655172 0.89655172 0.89655172
 0.89655172 0.89655172 0.89655172 0.89655172 0.89655172 0.89655172
 0.89655172 0.89655172 0.89655172 0.89655172 0.89655172 0.89655172
 0.89655172 0.89655172 0.89655172 0.89655172 0.89655172 0.89655172
 0.93103448 0.93103448 0.93103448 0.93103448 0.93103448 0.93103448
 0.93103448 0.93103448 0.93103448 0.93103448 0.93103448 0.93103448
 0.93103448 0.93103448 0.93103448 0.93103448 0.93103448 0.93103448
 0.93103448 0.93103448 0.93103448 0.93103448 0.93103448 0.93103448
 0.93103448 0.93103448 0.93103448 0.93103448 0.93103448 0.93103448
 0.96551724 0.96551724 0.96551724 0.96551724 0.96551724 0.96551724
 0.96551724 0.96551724 0.96551724 0.96551724 0.96551724 0.96551724
 0.96551724 0.96551724 0.96551724 0.96551724 0.96551724 0.96551724
 0.96551724 0.96551724 0.96551724 0.96551724 0.96551724 0.96551724
 0.96551724 0.96551724 0.96551724 0.96551724 0.96551724 0.96551724
 1.         1.         1.         1.         1.         1.
 1.         1.         1.         1.         1.         1.
 1.         1.         1.         1.         1.         1.
 1.         1.         1.         1.         1.         1.
 1.         1.         1.         1.         1.         1.        ] 

打印np.vstack([XX.ravel(),YY.ravel()])
 [[0.         0.         0.         ... 1.         1.         1.        ]
 [0.         0.03448276 0.06896552 ... 0.93103448 0.96551724 1.        ]] 

打印xy:
 [[0.         0.        ]
 [0.         0.03448276]
 [0.         0.06896552]
 ...
 [1.         0.93103448]
 [1.         0.96551724]
 [1.         1.        ]] 

                
              
            
          
            
              ax
              
                .
              
              contour
              
                (
              
              XX
              
                ,
              
              YY
              
                ,
              
              Z
              
                ,
              
              colors
              
                =
              
              
                'k'
              
              
                ,
              
              levels
              
                =
              
              
                [
              
              
                -
              
              
                1
              
              
                ,
              
              
                0
              
              
                ,
              
              
                1
              
              
                ]
              
              
                ,
              
              alpha
              
                =
              
              
                0.5
              
              
                ,
              
              
          linestyles
              
                =
              
              
                [
              
              
                '--'
              
              
                ,
              
              
                '-'
              
              
                ,
              
              
                '--'
              
              
                ]
              
              
                )
              
              

ax
              
                .
              
              scatter
              
                (
              
              clf
              
                .
              
              support_vectors_
              
                [
              
              
                :
              
              
                ,
              
              
                0
              
              
                ]
              
              
                ,
              
              clf
              
                .
              
              support_vectors_
              
                [
              
              
                :
              
              
                ,
              
              
                1
              
              
                ]
              
              
                ,
              
              s
              
                =
              
              
                100
              
              
                ,
              
              
          linewidths
              
                =
              
              
                1
              
              
                ,
              
              facecolors
              
                =
              
              
                'none'
              
              
                )
              
              

plt
              
                .
              
              show
              
                (
              
              
                )
              
            
          
            
              c:\users\huawei\appdata\local\programs\python\python36\lib\site-packages\ipykernel_launcher.py:2: UserWarning: No contour levels were found within the data range.

            
          
            
              
                print
              
              
                (
              
              
                'xx.shape:'
              
              
                ,
              
              xx
              
                .
              
              shape
              
                ,
              
              
                '\n'
              
              
                )
              
              
                print
              
              
                (
              
              
                'yy.shape:'
              
              
                ,
              
              yy
              
                .
              
              shape
              
                ,
              
              
                '\n'
              
              
                )
              
              
                print
              
              
                (
              
              
                'XX.shape:'
              
              
                ,
              
              XX
              
                .
              
              shape
              
                ,
              
              
                '\n'
              
              
                )
              
              
                print
              
              
                (
              
              
                'YY.shape:'
              
              
                ,
              
              YY
              
                .
              
              shape
              
                ,
              
              
                '\n'
              
              
                )
              
              
                print
              
              
                (
              
              
                'XX.ravel().shape:'
              
              
                ,
              
              XX
              
                .
              
              ravel
              
                (
              
              
                )
              
              
                .
              
              shape
              
                ,
              
              
                '\n'
              
              
                )
              
              
                print
              
              
                (
              
              
                'np.vstack([XX.ravel(),YY.ravel()]).shape:'
              
              
                ,
              
              np
              
                .
              
              vstack
              
                (
              
              
                [
              
              XX
              
                .
              
              ravel
              
                (
              
              
                )
              
              
                ,
              
              YY
              
                .
              
              ravel
              
                (
              
              
                )
              
              
                ]
              
              
                )
              
              
                .
              
              shape
              
                ,
              
              
                '\n'
              
              
                )
              
              
                print
              
              
                (
              
              
                'np.vstack([XX.ravel(),YY.ravel()]).T.shape:'
              
              
                ,
              
              np
              
                .
              
              vstack
              
                (
              
              
                [
              
              XX
              
                .
              
              ravel
              
                (
              
              
                )
              
              
                ,
              
              YY
              
                .
              
              ravel
              
                (
              
              
                )
              
              
                ]
              
              
                )
              
              
                .
              
              T
              
                .
              
              shape
              
                ,
              
              
                '\n'
              
              
                )
              
              
                print
              
              
                (
              
              
                'clf.decision_function(xy).shape:'
              
              
                ,
              
              clf
              
                .
              
              decision_function
              
                (
              
              xy
              
                )
              
              
                .
              
              shape
              
                ,
              
              
                '\n'
              
              
                )
              
            
          
            
              xx.shape: (30,) 

yy.shape: (30,) 

XX.shape: (30, 30) 

YY.shape: (30, 30) 

XX.ravel().shape: (900,) 

np.vstack([XX.ravel(),YY.ravel()]).shape: (2, 900) 

np.vstack([XX.ravel(),YY.ravel()]).T.shape: (900, 2) 

clf.decision_function(xy).shape: (900,) 

            
          
            
              
                print
              
              
                (
              
              
                'Z:\n'
              
              
                ,
              
              Z
              
                ,
              
              
                '\n'
              
              
                )
              
            
          
            
              Z:
 [[-3.2115599  -3.24045912 -3.26935835 -3.29825757 -3.3271568  -3.35605602
  -3.38495524 -3.41385447 -3.44275369 -3.47165292 -3.50055214 -3.52945137
  -3.55835059 -3.58724982 -3.61614904 -3.64504827 -3.67394749 -3.70284672
  -3.73174594 -3.76064516 -3.78954439 -3.81844361 -3.84734284 -3.87624206
  -3.90514129 -3.93404051 -3.96293974 -3.99183896 -4.02073819 -4.04963741]
 [-3.22031683 -3.24921606 -3.27811528 -3.30701451 -3.33591373 -3.36481296
  -3.39371218 -3.4226114  -3.45151063 -3.48040985 -3.50930908 -3.5382083
  -3.56710753 -3.59600675 -3.62490598 -3.6538052  -3.68270443 -3.71160365
  -3.74050288 -3.7694021  -3.79830132 -3.82720055 -3.85609977 -3.884999
  -3.91389822 -3.94279745 -3.97169667 -4.0005959  -4.02949512 -4.05839435]
 [-3.22907377 -3.25797299 -3.28687222 -3.31577144 -3.34467067 -3.37356989
  -3.40246912 -3.43136834 -3.46026756 -3.48916679 -3.51806601 -3.54696524
  -3.57586446 -3.60476369 -3.63366291 -3.66256214 -3.69146136 -3.72036059
  -3.74925981 -3.77815904 -3.80705826 -3.83595748 -3.86485671 -3.89375593
  -3.92265516 -3.95155438 -3.98045361 -4.00935283 -4.03825206 -4.06715128]
 [-3.2378307  -3.26672993 -3.29562915 -3.32452838 -3.3534276  -3.38232683
  -3.41122605 -3.44012528 -3.4690245  -3.49792372 -3.52682295 -3.55572217
  -3.5846214  -3.61352062 -3.64241985 -3.67131907 -3.7002183  -3.72911752
  -3.75801675 -3.78691597 -3.8158152  -3.84471442 -3.87361364 -3.90251287
  -3.93141209 -3.96031132 -3.98921054 -4.01810977 -4.04700899 -4.07590822]
 [-3.24658764 -3.27548686 -3.30438609 -3.33328531 -3.36218454 -3.39108376
  -3.41998299 -3.44888221 -3.47778144 -3.50668066 -3.53557988 -3.56447911
  -3.59337833 -3.62227756 -3.65117678 -3.68007601 -3.70897523 -3.73787446
  -3.76677368 -3.79567291 -3.82457213 -3.85347136 -3.88237058 -3.9112698
  -3.94016903 -3.96906825 -3.99796748 -4.0268667  -4.05576593 -4.08466515]
 [-3.25534457 -3.2842438  -3.31314302 -3.34204225 -3.37094147 -3.3998407
  -3.42873992 -3.45763915 -3.48653837 -3.5154376  -3.54433682 -3.57323604
  -3.60213527 -3.63103449 -3.65993372 -3.68883294 -3.71773217 -3.74663139
  -3.77553062 -3.80442984 -3.83332907 -3.86222829 -3.89112752 -3.92002674
  -3.94892596 -3.97782519 -4.00672441 -4.03562364 -4.06452286 -4.09342209]
 [-3.26410151 -3.29300073 -3.32189996 -3.35079918 -3.37969841 -3.40859763
  -3.43749686 -3.46639608 -3.49529531 -3.52419453 -3.55309376 -3.58199298
  -3.6108922  -3.63979143 -3.66869065 -3.69758988 -3.7264891  -3.75538833
  -3.78428755 -3.81318678 -3.842086   -3.87098523 -3.89988445 -3.92878368
  -3.9576829  -3.98658212 -4.01548135 -4.04438057 -4.0732798  -4.10217902]
 [-3.27285845 -3.30175767 -3.33065689 -3.35955612 -3.38845534 -3.41735457
  -3.44625379 -3.47515302 -3.50405224 -3.53295147 -3.56185069 -3.59074992
  -3.61964914 -3.64854836 -3.67744759 -3.70634681 -3.73524604 -3.76414526
  -3.79304449 -3.82194371 -3.85084294 -3.87974216 -3.90864139 -3.93754061
  -3.96643984 -3.99533906 -4.02423828 -4.05313751 -4.08203673 -4.11093596]
 [-3.28161538 -3.31051461 -3.33941383 -3.36831305 -3.39721228 -3.4261115
  -3.45501073 -3.48390995 -3.51280918 -3.5417084  -3.57060763 -3.59950685
  -3.62840608 -3.6573053  -3.68620452 -3.71510375 -3.74400297 -3.7729022
  -3.80180142 -3.83070065 -3.85959987 -3.8884991  -3.91739832 -3.94629755
  -3.97519677 -4.004096   -4.03299522 -4.06189444 -4.09079367 -4.11969289]
 [-3.29037232 -3.31927154 -3.34817077 -3.37706999 -3.40596921 -3.43486844
  -3.46376766 -3.49266689 -3.52156611 -3.55046534 -3.57936456 -3.60826379
  -3.63716301 -3.66606224 -3.69496146 -3.72386068 -3.75275991 -3.78165913
  -3.81055836 -3.83945758 -3.86835681 -3.89725603 -3.92615526 -3.95505448
  -3.98395371 -4.01285293 -4.04175216 -4.07065138 -4.0995506  -4.12844983]
 [-3.29912925 -3.32802848 -3.3569277  -3.38582693 -3.41472615 -3.44362537
  -3.4725246  -3.50142382 -3.53032305 -3.55922227 -3.5881215  -3.61702072
  -3.64591995 -3.67481917 -3.7037184  -3.73261762 -3.76151684 -3.79041607
  -3.81931529 -3.84821452 -3.87711374 -3.90601297 -3.93491219 -3.96381142
  -3.99271064 -4.02160987 -4.05050909 -4.07940832 -4.10830754 -4.13720676]
 [-3.30788619 -3.33678541 -3.36568464 -3.39458386 -3.42348309 -3.45238231
  -3.48128153 -3.51018076 -3.53907998 -3.56797921 -3.59687843 -3.62577766
  -3.65467688 -3.68357611 -3.71247533 -3.74137456 -3.77027378 -3.799173
  -3.82807223 -3.85697145 -3.88587068 -3.9147699  -3.94366913 -3.97256835
  -4.00146758 -4.0303668  -4.05926603 -4.08816525 -4.11706448 -4.1459637 ]
 [-3.31664312 -3.34554235 -3.37444157 -3.4033408  -3.43224002 -3.46113925
  -3.49003847 -3.51893769 -3.54783692 -3.57673614 -3.60563537 -3.63453459
  -3.66343382 -3.69233304 -3.72123227 -3.75013149 -3.77903072 -3.80792994
  -3.83682916 -3.86572839 -3.89462761 -3.92352684 -3.95242606 -3.98132529
  -4.01022451 -4.03912374 -4.06802296 -4.09692219 -4.12582141 -4.15472064]
 [-3.32540006 -3.35429928 -3.38319851 -3.41209773 -3.44099696 -3.46989618
  -3.49879541 -3.52769463 -3.55659385 -3.58549308 -3.6143923  -3.64329153
  -3.67219075 -3.70108998 -3.7299892  -3.75888843 -3.78778765 -3.81668688
  -3.8455861  -3.87448532 -3.90338455 -3.93228377 -3.961183   -3.99008222
  -4.01898145 -4.04788067 -4.0767799  -4.10567912 -4.13457835 -4.16347757]
 [-3.33415699 -3.36305622 -3.39195544 -3.42085467 -3.44975389 -3.47865312
  -3.50755234 -3.53645157 -3.56535079 -3.59425001 -3.62314924 -3.65204846
  -3.68094769 -3.70984691 -3.73874614 -3.76764536 -3.79654459 -3.82544381
  -3.85434304 -3.88324226 -3.91214148 -3.94104071 -3.96993993 -3.99883916
  -4.02773838 -4.05663761 -4.08553683 -4.11443606 -4.14333528 -4.17223451]
 [-3.34291393 -3.37181315 -3.40071238 -3.4296116  -3.45851083 -3.48741005
  -3.51630928 -3.5452085  -3.57410773 -3.60300695 -3.63190617 -3.6608054
  -3.68970462 -3.71860385 -3.74750307 -3.7764023  -3.80530152 -3.83420075
  -3.86309997 -3.8919992  -3.92089842 -3.94979764 -3.97869687 -4.00759609
  -4.03649532 -4.06539454 -4.09429377 -4.12319299 -4.15209222 -4.18099144]
 [-3.35167086 -3.38057009 -3.40946931 -3.43836854 -3.46726776 -3.49616699
  -3.52506621 -3.55396544 -3.58286466 -3.61176389 -3.64066311 -3.66956233
  -3.69846156 -3.72736078 -3.75626001 -3.78515923 -3.81405846 -3.84295768
  -3.87185691 -3.90075613 -3.92965536 -3.95855458 -3.9874538  -4.01635303
  -4.04525225 -4.07415148 -4.1030507  -4.13194993 -4.16084915 -4.18974838]
 [-3.3604278  -3.38932702 -3.41822625 -3.44712547 -3.4760247  -3.50492392
  -3.53382315 -3.56272237 -3.5916216  -3.62052082 -3.64942005 -3.67831927
  -3.70721849 -3.73611772 -3.76501694 -3.79391617 -3.82281539 -3.85171462
  -3.88061384 -3.90951307 -3.93841229 -3.96731152 -3.99621074 -4.02510996
  -4.05400919 -4.08290841 -4.11180764 -4.14070686 -4.16960609 -4.19850531]
 [-3.36918473 -3.39808396 -3.42698318 -3.45588241 -3.48478163 -3.51368086
  -3.54258008 -3.57147931 -3.60037853 -3.62927776 -3.65817698 -3.68707621
  -3.71597543 -3.74487465 -3.77377388 -3.8026731  -3.83157233 -3.86047155
  -3.88937078 -3.91827    -3.94716923 -3.97606845 -4.00496768 -4.0338669
  -4.06276612 -4.09166535 -4.12056457 -4.1494638  -4.17836302 -4.20726225]
 [-3.37794167 -3.40684089 -3.43574012 -3.46463934 -3.49353857 -3.52243779
  -3.55133702 -3.58023624 -3.60913547 -3.63803469 -3.66693392 -3.69583314
  -3.72473237 -3.75363159 -3.78253081 -3.81143004 -3.84032926 -3.86922849
  -3.89812771 -3.92702694 -3.95592616 -3.98482539 -4.01372461 -4.04262384
  -4.07152306 -4.10042228 -4.12932151 -4.15822073 -4.18711996 -4.21601918]
 [-3.38669861 -3.41559783 -3.44449705 -3.47339628 -3.5022955  -3.53119473
  -3.56009395 -3.58899318 -3.6178924  -3.64679163 -3.67569085 -3.70459008
  -3.7334893  -3.76238853 -3.79128775 -3.82018697 -3.8490862  -3.87798542
  -3.90688465 -3.93578387 -3.9646831  -3.99358232 -4.02248155 -4.05138077
  -4.08028    -4.10917922 -4.13807844 -4.16697767 -4.19587689 -4.22477612]
 [-3.39545554 -3.42435477 -3.45325399 -3.48215321 -3.51105244 -3.53995166
  -3.56885089 -3.59775011 -3.62664934 -3.65554856 -3.68444779 -3.71334701
  -3.74224624 -3.77114546 -3.80004469 -3.82894391 -3.85784313 -3.88674236
  -3.91564158 -3.94454081 -3.97344003 -4.00233926 -4.03123848 -4.06013771
  -4.08903693 -4.11793616 -4.14683538 -4.1757346  -4.20463383 -4.23353305]
 [-3.40421248 -3.4331117  -3.46201093 -3.49091015 -3.51980937 -3.5487086
  -3.57760782 -3.60650705 -3.63540627 -3.6643055  -3.69320472 -3.72210395
  -3.75100317 -3.7799024  -3.80880162 -3.83770085 -3.86660007 -3.89549929
  -3.92439852 -3.95329774 -3.98219697 -4.01109619 -4.03999542 -4.06889464
  -4.09779387 -4.12669309 -4.15559232 -4.18449154 -4.21339076 -4.24228999]
 [-3.41296941 -3.44186864 -3.47076786 -3.49966709 -3.52856631 -3.55746553
  -3.58636476 -3.61526398 -3.64416321 -3.67306243 -3.70196166 -3.73086088
  -3.75976011 -3.78865933 -3.81755856 -3.84645778 -3.87535701 -3.90425623
  -3.93315545 -3.96205468 -3.9909539  -4.01985313 -4.04875235 -4.07765158
  -4.1065508  -4.13545003 -4.16434925 -4.19324848 -4.2221477  -4.25104692]
 [-3.42172635 -3.45062557 -3.4795248  -3.50842402 -3.53732325 -3.56622247
  -3.59512169 -3.62402092 -3.65292014 -3.68181937 -3.71071859 -3.73961782
  -3.76851704 -3.79741627 -3.82631549 -3.85521472 -3.88411394 -3.91301317
  -3.94191239 -3.97081161 -3.99971084 -4.02861006 -4.05750929 -4.08640851
  -4.11530774 -4.14420696 -4.17310619 -4.20200541 -4.23090464 -4.25980386]
 [-3.43048328 -3.45938251 -3.48828173 -3.51718096 -3.54608018 -3.57497941
  -3.60387863 -3.63277785 -3.66167708 -3.6905763  -3.71947553 -3.74837475
  -3.77727398 -3.8061732  -3.83507243 -3.86397165 -3.89287088 -3.9217701
  -3.95066933 -3.97956855 -4.00846777 -4.037367   -4.06626622 -4.09516545
  -4.12406467 -4.1529639  -4.18186312 -4.21076235 -4.23966157 -4.2685608 ]
 [-3.43924022 -3.46813944 -3.49703867 -3.52593789 -3.55483712 -3.58373634
  -3.61263557 -3.64153479 -3.67043401 -3.69933324 -3.72823246 -3.75713169
  -3.78603091 -3.81493014 -3.84382936 -3.87272859 -3.90162781 -3.93052704
  -3.95942626 -3.98832549 -4.01722471 -4.04612393 -4.07502316 -4.10392238
  -4.13282161 -4.16172083 -4.19062006 -4.21951928 -4.24841851 -4.27731773]
 [-3.44799715 -3.47689638 -3.5057956  -3.53469483 -3.56359405 -3.59249328
  -3.6213925  -3.65029173 -3.67919095 -3.70809017 -3.7369894  -3.76588862
  -3.79478785 -3.82368707 -3.8525863  -3.88148552 -3.91038475 -3.93928397
  -3.9681832  -3.99708242 -4.02598165 -4.05488087 -4.08378009 -4.11267932
  -4.14157854 -4.17047777 -4.19937699 -4.22827622 -4.25717544 -4.28607467]
 [-3.45675409 -3.48565331 -3.51455254 -3.54345176 -3.57235099 -3.60125021
  -3.63014944 -3.65904866 -3.68794789 -3.71684711 -3.74574633 -3.77464556
  -3.80354478 -3.83244401 -3.86134323 -3.89024246 -3.91914168 -3.94804091
  -3.97694013 -4.00583936 -4.03473858 -4.06363781 -4.09253703 -4.12143625
  -4.15033548 -4.1792347  -4.20813393 -4.23703315 -4.26593238 -4.2948316 ]
 [-3.46551102 -3.49441025 -3.52330947 -3.5522087  -3.58110792 -3.61000715
  -3.63890637 -3.6678056  -3.69670482 -3.72560405 -3.75450327 -3.78340249
  -3.81230172 -3.84120094 -3.87010017 -3.89899939 -3.92789862 -3.95679784
  -3.98569707 -4.01459629 -4.04349552 -4.07239474 -4.10129397 -4.13019319
  -4.15909241 -4.18799164 -4.21689086 -4.24579009 -4.27468931 -4.30358854]] 

            
          
            
              plt
              
                .
              
              scatter
              
                (
              
              XX
              
                ,
              
              YY
              
                ,
              
              c
              
                =
              
              Z
              
                ,
              
              s
              
                =
              
              
                30
              
              
                ,
              
              cmap
              
                =
              
              plt
              
                .
              
              cm
              
                .
              
              Paired
              
                )
              
              

plt
              
                .
              
              show
              
                (
              
              
                )
              
            
          

深入浅出python机器学习_7.1_支持向量机_第3张图片

            
              
                # 测试
              
              

pp
              
                =
              
              np
              
                .
              
              linspace
              
                (
              
              
                0
              
              
                ,
              
              
                10
              
              
                ,
              
              
                900
              
              
                )
              
              

tt
              
                =
              
              np
              
                .
              
              linspace
              
                (
              
              
                0
              
              
                ,
              
              
                10
              
              
                ,
              
              
                900
              
              
                )
              
              

uu
              
                =
              
              np
              
                .
              
              vstack
              
                (
              
              
                [
              
              pp
              
                ,
              
              tt
              
                ]
              
              
                )
              
              
                .
              
              T

Z_
              
                =
              
              clf
              
                .
              
              decision_function
              
                (
              
              uu
              
                )
              
              
                .
              
              reshape
              
                (
              
              XX
              
                .
              
              shape
              
                )
              
              

plt
              
                .
              
              scatter
              
                (
              
              XX
              
                ,
              
              YY
              
                ,
              
              c
              
                =
              
              Z_
              
                ,
              
              s
              
                =
              
              
                30
              
              
                ,
              
              cmap
              
                =
              
              plt
              
                .
              
              cm
              
                .
              
              Paired
              
                )
              
              

plt
              
                .
              
              show
              
                (
              
              
                )
              
            
          

深入浅出python机器学习_7.1_支持向量机_第4张图片


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请请扫描上面二维码支持博主1元、2元、5元等您想捐的金额吧,狠狠点击下面给点支持吧

发表我的评论
最新评论 总共0条评论