#! /usr/bin/env python3 # def forge_classify_svm ( ): #*****************************************************************************80 # ## forge_classify_svm() uses the support vector classifier on forge data. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 04 July 2023 # # Author: # # Andreas Mueller, Sarah Guido. # Modifications by John Burkardt. # # Reference: # # Andreas Mueller, Sarah Guido, # Introduction to Machine Learning with Python, # OReilly, 2017, # ISBN: 978-1-449-36941-5 # from sklearn.svm import LinearSVC import matplotlib.pyplot as plt import mglearn import numpy as np import pandas as pd import platform import sklearn print ( '' ) print ( 'forge_classify_svm():' ) print ( ' Python version: ' + platform.python_version ( ) ) print ( ' scikit-learn version: '+ sklearn.__version__ ) print ( ' Classify the data from the forge dataset.' ) print ( ' Use the support vector classifier.' ) print ( ' Vary the C parameter.' ) print ( '' ) # # Generate the dataset. # print ( ' Generate the forge dataset, (X, y).' ) X, y = mglearn.datasets.make_forge ( ) print ( " X.shape:", X.shape ) for c_value in [ 0.01, 10.0, 1000.0 ]: clf = LinearSVC ( C = c_value ).fit ( X, y ) mglearn.plots.plot_2d_separator ( clf, X, fill = False, eps = 0.5, alpha = 0.7 ) mglearn.discrete_scatter ( X[:,0], X[:,1], y ) plt.title ( 'C = ' + str ( c_value ) ) plt.xlabel ( 'Feature 0' ) plt.ylabel ( 'Feature 1' ) plt.legend() filename = "forge_classify_" + str ( c_value ) + ".png" plt.savefig ( filename ) print ( " Graphics saved as '" + filename + "'" ) plt.close ( ) # # Terminate. # print ( '' ) print ( 'forge_classify_svm():' ) print ( ' Normal end of execution.' ) return def timestamp ( ): #*****************************************************************************80 # ## timestamp() prints the date as a timestamp. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 21 August 2019 # # Author: # # John Burkardt # import time t = time.time ( ) print ( time.ctime ( t ) ) return if ( __name__ == '__main__' ): timestamp ( ) forge_classify_svm ( ) timestamp ( )