-
Notifications
You must be signed in to change notification settings - Fork 8
/
svr.py
53 lines (35 loc) · 1.13 KB
/
svr.py
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
#importing the libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#importing the dataset
dataset = pd.read_csv("Dataset.csv")
from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
dataset['Date']= le.fit_transform(dataset['Date'])
X = dataset.iloc[:, 1:6].values
y = dataset.iloc[:, 6:7].values
#splitting into Train and Test data
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0)
#Featuring Scaling
from sklearn.preprocessing import StandardScaler
sc_X = StandardScaler()
X_train = sc_X.fit_transform(X_train)
X_test = sc_X.fit_transform(X_test)
#fitting SVR to the dataset
from sklearn.svm import SVR
regressor = SVR(kernel = 'rbf')
regressor.fit(X_train,y_train)
#Predicting the Test Set Results
y_pred = regressor.predict(X_test)
if(y_pred.all()<2.5):
y_pred=np.round(y_pred-0.5)
else:
y_pred=np.round(y_pred+0.5)
#Calculationg the error and accuracy
df1=(y_pred-y_test)/y_test
df1=round(df1.mean()*100,2)
print("Error = ",df1,"%")
a=100-df1
print("Accuracy= ",a,"%")