-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMachineLearning1.py
More file actions
82 lines (52 loc) · 1.88 KB
/
MachineLearning1.py
File metadata and controls
82 lines (52 loc) · 1.88 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
72
73
74
75
76
77
78
79
80
81
82
# -*- coding: utf-8 -*-
"""
Created on Fri Dec 5 23:11:43 2025
@author: medak
"""
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# Veri Yükleme
veriler = pd.read_csv('eksikveriler.csv')
# Eksik Veriler
from sklearn.impute import SimpleImputer
imputer = SimpleImputer(missing_values=np.nan, strategy='mean')
Yas = veriler.iloc[:, 1:4].values
print(Yas)
imputer = imputer.fit(Yas[:, 1:4])
Yas[:, 1:4] = imputer.transform(Yas[:, 1:4])
print(Yas)
# Kategorik Veriler
ulke = veriler.iloc[:, 0:1].values
print(ulke)
from sklearn import preprocessing
le = preprocessing.LabelEncoder()
ulke[:,0] = le.fit_transform(veriler.iloc[:, 0])
print(ulke)
ohe = preprocessing.OneHotEncoder()
ulke = ohe.fit_transform(ulke).toarray()
print(ulke)
# Verilerin Birleştirilmesi
print(list(range(22)))
sonuc = pd.DataFrame(data=ulke, index=range(22), columns=['fr','tr','us'])
print(sonuc)
sonuc2 = pd.DataFrame(data=Yas, index=range(22), columns=['boy','kilo','yas'])
print(sonuc2)
cinsiyet = veriler.iloc[:, -1].values
print(cinsiyet)
sonuc3 = pd.DataFrame(data=cinsiyet, index=range(22), columns=['cinsiyet'])
print(sonuc3)
s = pd.concat([sonuc,sonuc2], axis=1)
print(s)
s2 = pd.concat([s,sonuc3], axis=1)
print(s2)
# Veri Setini Test ve Train olarak Bölmek
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(s, sonuc3, test_size=0.33, random_state=0)
# Veri setinin %33’ü test, %67’si eğitim olarak kullanılacak demektir.
# Öznitelik Ölçekleme
# Veri setindeki bazı özellikler çok büyük, bazıları çok küçük olabilir. Tüm sütunları benzer aralığa getirmek gerekir.
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(x_train)
X_test = sc.fit_transform(x_test)