forked from zhengyuv/MyPyMLRoad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4-purchase.py
47 lines (23 loc) · 853 Bytes
/
4-purchase.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
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 6 18:39:01 2018
@author: zhengyuv
"""
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
#import matplotlib.pyplot as plt
from sklearn.metrics import accuracy_score
dataset = pd.read_csv('Social_Network_Ads.csv')
X = dataset.iloc[ : ,2:4].values
Y = dataset.iloc[ : ,4].values
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size = 0.2)
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test )
classifier = LogisticRegression()
classifier.fit(X_train, Y_train)
y_pred = classifier.predict(X_test)
acc = accuracy_score(Y_test, y_pred)
print("准确率为:", acc)