Skip to content

Commit b69f136

Browse files
committed
pre
1 parent 892d510 commit b69f136

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

Diff for: Unsup_learn/Preprocessing.py

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Sun Aug 12 14:28:52 2018
4+
5+
@author: Administrator
6+
"""
7+
8+
import mglearn
9+
from sklearn.model_selection import train_test_split
10+
from sklearn.preprocessing import MinMaxScaler
11+
from sklearn.svm import LinearSVC, SVC
12+
from sklearn.datasets import load_breast_cancer
13+
14+
mglearn.plots.plot_scaling()
15+
16+
def test_prep():
17+
cancer = load_breast_cancer()
18+
19+
X_train, X_test, y_train, y_test = train_test_split(
20+
cancer.data, cancer.target, stratify=cancer.target
21+
, random_state=1)
22+
23+
scale = MinMaxScaler()
24+
scale.fit(X_train)
25+
26+
X_scaled = scale.transform(X_train)
27+
print(X_scaled)
28+
29+
def test_SVC():
30+
31+
cancer = load_breast_cancer()
32+
33+
X_train, X_test, y_train, y_test = train_test_split(
34+
cancer.data, cancer.target, stratify=cancer.target
35+
, random_state=42)
36+
37+
svc = SVC(C=100)
38+
svc.fit(X_train,y_train)
39+
40+
print(svc.score(X_train,y_train))
41+
print("the test score is {:.2f}".format(svc.score(X_test
42+
,y_test)))
43+
scale = MinMaxScaler()
44+
scale.fit(X_train)
45+
X_test_scaled = scale.transform(X_test)
46+
X_scaled = scale.transform(X_train)
47+
48+
svc.fit(X_scaled, y_train)
49+
print("the test score scaled is {:.2f}".format(svc.score(X_test_scaled
50+
,y_test)))
51+
52+

0 commit comments

Comments
 (0)