-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipeline_classification.py
More file actions
37 lines (28 loc) · 879 Bytes
/
Copy pathpipeline_classification.py
File metadata and controls
37 lines (28 loc) · 879 Bytes
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
import pandas as pd
import numpy as np
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import Pipeline
from sklearn.svm import SVC
from sklearn.model_selection import train_test_split
from sklearn.model_selection import GridSearchCV
df = pd.read_csv('Social_Network_Ads.csv')
df.info()
X = df[['Age','EstimatedSalary']]
y = df[['Purchased']]
steps = [
('scaler',StandardScaler()),
('classifier',SVC())
]
param = {
'classifier__C':[1,10,100],
'classifier__gamma':[0.1,0.01]
}
pipeline = Pipeline(steps)
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.25,random_state=0)
grcv = GridSearchCV(pipeline,param,cv=5)
grcv.fit(X_train,y_train)
y_pred = grcv.predict(X_test)
clf = SVC()
clf.fit(X_train,y_train)
print(f'score is {grcv.score(X_test,y_test)}')
print(f'score of orginal data {clf.score(X_test,y_test)}')