Python - Classification - Support Vector Machine (SVM)
Data:
Questionnaire data from mall visitors contains sex, age, salary & shopping score (200 rows).
Mission:
How to predict the probability of shopping score from given age & salary
Library used:
- Pandas
- Matplotlib
- Scikit
Code:
import pandas as pd
import matplotlib.pyplot as plt
from sklearn import svm
url = 'https://raw.githubusercontent.com/kokocamp/vlog101/master/vlog101.csv'
vlog126 = pd.read_csv(url)
vlog126.head()
X = vlog126[['Usia','Gaji (juta)']]
y = vlog126['Skor Belanja (1-100)']
svmpred = svm.SVC(kernel='linear')
svmpred.fit(X,y)
usia = input("Usia (thn): ")
usia = int(usia)
gaji = input("Gaji (juta): ")
gaji = int(gaji)
data = [usia,gaji]
print("Prediksi Skor Belanja (1-100): ", svmpred.predict([data]))
plt.scatter(vlog126[['Gaji (juta)']],y, color='green')
plt.scatter(gaji,svmpred.predict([data]), color='red')
I wrapped the scenario in a Youtube video below.
Click this link (http://paparadit.blogspot.com/2020/11/the-algorithms-of-machine-learning.html), if you want to check out for other algorithms. Thank you for for visiting this blog & subs my channel.
Labels: Programming, Python
PS: If you've benefit from this blog, you can support it by making a small contribution. |
Post a Comment
Leave comments here...