-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathb-25-k_fold_model_secimi.py
63 lines (43 loc) · 1.39 KB
/
b-25-k_fold_model_secimi.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
53
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Jul 8 10:03:40 2018
@author: regkr
"""
#1. kutuphaneler
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# veri kümesi
dataset = pd.read_csv('Social_Network_Ads.csv')
X = dataset.iloc[:, [2, 3]].values
y = dataset.iloc[:, 4].values
# eğitim ve test kümelerinin bölünmesi
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)
# Ölçekleme
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
# SVM
from sklearn.svm import SVC
classifier = SVC(kernel = 'rbf', random_state = 0)
classifier.fit(X_train, y_train)
# Tahminler
y_pred = classifier.predict(X_test)
# Confusion Matrix
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)
print(cm)
#k-katlamali capraz dogrulama
from sklearn.model_selection import cross_val_score
'''
1. estimator : classifier (bizim durum) çünkü svc objesine classifier ismini verdik.
2. X
3. Y
4. cv : kaç katlamalı
'''
basari = cross_val_score(estimator = classifier, X=X_train, y=y_train , cv = 4)
print(basari.mean()) #mean yüntemi başarıların ortalamasını verir.
print(basari.std()) # std ise başarılar arasındaki standart sapmayı verir. (düşük olmalı)