Machine Learning using Python: how do I use matplotlib to plot the SVM? -


i'm new machine learning (using python). referred few books, not able figure out how plot svm using matplotlib.

please me plot following:

from sklearn.svm import svc features_train=[[0,0],[1,1],[2,2]] label_train=[1,2,3] features_test=[[1,2],[2,1]] clf=svc() clf.fit(x,y) pred=clf.predict(features_test) print(pred) 

try code below , read comments. tyro. more detail may catch link mlextend in getting better insight of svm having matplotlib under it's hood.

import numpy np import pandas pd # more detail catch link below sklearn import svm mlxtend.plotting import plot_decision_regions import matplotlib.pyplot plt   # create arbitrary dataset example df = pd.dataframe({'planned_end': np.random.uniform(low=-5, high=5, size=50),                'actual_end':  np.random.uniform(low=-1, high=1, size=50),                'late':        np.random.random_integers(low=0,  high=2, size=50)} )  # fit support vector machine classifier x = df[['planned_end', 'actual_end']] y = df['late']  clf = svm.svc(decision_function_shape='ovo') clf.fit(x.values, y.values)   # plot decision region using mlxtend's awesome plotting function plot_decision_regions(x=x.values,                    y=y.values,                   clf=clf,                    legend=2)  # update plot object x/y axis labels , figure title plt.xlabel(x.columns[0], size=14) plt.ylabel(x.columns[1], size=14) plt.title('svm decision region boundary', size=16) 

however, if unaware of pandas follow link: http://pandas.pydata.org/ docs. hope works


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -