-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSupport_vector_machin.py
More file actions
71 lines (58 loc) · 1.85 KB
/
Support_vector_machin.py
File metadata and controls
71 lines (58 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import numpy as np
import pandas as pd
import matplotlib.pylab as plt
import seaborn as sns
import sklearn
df = pd.read_csv('/home/m-fayzi/Desktop/machin_learning/Datasets/mobile_price_range_data.csv')
# print(df.head())
# print(df.info())
# print(df['price_range'].value_counts())
corr = df.corr()
# plt.figure(figsize=(23,18))
# sns.heatmap(corr, annot=True, cmap='coolwarm')
# plt.show()
sort = corr.sort_values(by='price_range', ascending=False).iloc[0].sort_values(ascending=False)
# print(sort)
X = df.iloc[:, :-1].values
y = df.iloc[:, -1].values
# print(df.isnull().sum())
from sklearn.preprocessing import StandardScaler
standard = StandardScaler()
X = standard.fit_transform(X)
# print(X)
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state= 5)
# print(X_train.shape)
# print(X_test.shape)
from sklearn.svm import SVC
classifier = SVC(kernel='linear')
classifier.fit(X_train, y_train)
y_pred = classifier.predict(X_test)
# print(y_pred)
# print(y_test)
# print(pd.crosstab(y_test, y_pred))
from sklearn.metrics import accuracy_score,classification_report, confusion_matrix
# print(confusion_matrix(y_test, y_pred))
# print('Accuracy Score:',accuracy_score(y_test, y_pred) * 100)
# print(classification_report(y_test, y_pred))
#SVR Model
data = pd.read_csv('/home/m-fayzi/Desktop/machin_learning/Datasets/Position_Salaries.csv')
# print(data)
X = data.iloc[:, 1:2].values
y = data.iloc[:, 2:3].values
# print(X)
# print(y)
# Feature Scaling
from sklearn.preprocessing import StandardScaler
scale_X = StandardScaler()
scale_y = StandardScaler()
X = scale_X.fit_transform(X)
y = scale_y.fit_transform(y)
print(X)
from sklearn.svm import SVR
model = SVR(kernel='rbf')
model.fit(X,y)
y_pred = model.predict(X)
plt.scatter(X, y, color='magenta')
plt.plot(X, y_pred, color = 'green')
plt.show()